Changeset 236
- Timestamp:
- 03/02/07 23:55:40 (1 year ago)
- Files:
-
- 06/libkombilo-branches/hash_center_makedb/analyze.py (modified) (1 diff)
- 06/libkombilo-branches/hash_center_makedb/makedb.py (modified) (1 diff)
- 06/libkombilo-branches/hash_center_makedb/process.py (modified) (1 diff)
- 06/libkombilo-branches/hash_center_makedb/search.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
06/libkombilo-branches/hash_center_makedb/analyze.py
r235 r236 3 3 db = dbapi2.connect('t1.db2') 4 4 c = db.cursor() 5 c.execute('select cardfrom algo_hash_19_CENTER;')5 c.execute('select freq from algo_hash_19_CENTER;') 6 6 a = c.fetchall() 7 7 06/libkombilo-branches/hash_center_makedb/makedb.py
r235 r236 3 3 db = dbapi2.connect('t1.db2') 4 4 c = db.cursor() 5 c.execute('select hash, card from algo_hash_19_CENTER where card > 40 and card< 5000;')5 c.execute('select hash,freq from algo_hash_19_CENTER where freq > 40 and freq < 5000;') 6 6 a = c.fetchall() 7 7 print 'retrieved data', len(a) 06/libkombilo-branches/hash_center_makedb/process.py
r233 r236 47 47 # filelist = glob.glob('./*.sgf') 48 48 # filelist = glob.glob('/home/ug/go/gogod06/*/*.sgf') 49 filelist = glob.glob('/home/ug/go/KGS/*/*.sgf')49 # filelist = glob.glob('/home/ug/go/KGS/*/*.sgf') 50 50 # filelist = glob.glob('/home/ug/go/KGS2005/*.sgf') 51 51 52 filelist.sort() 53 process(filelist) 52 for path in ['/home/ug/go/gogod06/*/*.sgf', '/home/ug/go/KGS/*/*.sgf']: 53 filelist = glob.glob(path) 54 filelist.sort() 55 process(filelist) 54 56 55 57 gl = GameList("t1.db", "id", "[[filename.]], ") 56 58 57 p = Pattern(CENTER_PATTERN, 19, 3, 5, ".X..OX.OX.OXOXO")58 so = SearchOptions()59 # p = Pattern(CENTER_PATTERN, 19, 3, 5, ".X..OX.OX.OXOXO") 60 # so = SearchOptions() 59 61 60 gl.reset()61 gl.search(p, so)62 # gl.reset() 63 # gl.search(p, so) 62 64 63 for i in range(gl.size())[-10:]:64 print gl.currentEntryAsString(i)65 # for i in range(gl.size())[-10:]: 66 # print gl.currentEntryAsString(i) 65 67 66 68 06/libkombilo-branches/hash_center_makedb/search.cpp
r233 r236 238 238 } 239 239 240 Pattern::Pattern(int type, int BOARDSIZE, int sX, int sY, 241 char* iPos, vector<MoveNC> CONTLIST, char* CONTLABELS) { 240 Pattern::Pattern(int type, int BOARDSIZE, int sX, int sY, char* iPos, vector<MoveNC> CONTLIST, char* CONTLABELS) { 242 241 flip = 0; 243 242 colorSwitch = 0; … … 293 292 } 294 293 295 Pattern::Pattern(int le, int ri, int to, int bo, int BOARDSIZE, int sX, int sY, 296 char* iPos, const vector<MoveNC>& CONTLIST, char* CONTLABELS) throw(PatternError) { 294 Pattern::Pattern(int le, int ri, int to, int bo, int BOARDSIZE, int sX, int sY, char* iPos, const vector<MoveNC>& CONTLIST, char* CONTLABELS) throw(PatternError) { 297 295 // check whether anchor rectangle is valid 298 296 if (le < 0 || ri+sX > BOARDSIZE || to < 0 || bo+sY > BOARDSIZE || ri < le || bo < to) throw PatternError(); … … 2720 2718 Algo_hash_center::Algo_hash_center(int bsize) : Algo_hash(bsize, "CENTER", 16) { 2721 2719 hi = new vector<HashInstance* >; 2722 for(int i= 1; i<bsize-4; i++)2723 for(int j= 1; j<bsize-4; j++)2720 for(int i=0; i<bsize-3; i++) 2721 for(int j=0; j<bsize-3; j++) 2724 2722 hi->push_back(new HashInstanceCTR(i, j, 4, 4, boardsize)); 2723 } 2724 2725 void Algo_hash_center::initialize_process(sqlite3* DB) throw(DBError) { 2726 db = DB; 2727 char buf[200]; 2728 sprintf(buf, "create table if not exists algo_hash_%d_%s ( hash integer, freq integer);", boardsize, dbnameext.c_str()); 2729 int rc = sqlite3_exec(db, buf, 0, 0, 0); 2730 if (rc != SQLITE_OK) throw DBError(); 2731 sprintf(buf, "create index if not exists hash_idx_%d_%s on algo_hash_%d_%s(hash);", boardsize, dbnameext.c_str(), boardsize, dbnameext.c_str()); 2732 rc = sqlite3_exec(db, buf, 0, 0, 0); 2733 if (rc != SQLITE_OK) throw DBError(); 2725 2734 } 2726 2735 … … 2730 2739 (*it)->changed = false; 2731 2740 pair<hashtype,int> phi = (*it)->cHC(); 2732 if (phi.first in table of relevant hash codes) 2733 if (insert_hash(phi.first, phi.second) != 0) throw DBError(); 2734 } 2735 } 2736 } 2737 2741 if (data.find(phi.first) != data.end()) data[phi.first]++; 2742 else data[phi.first] = 1; 2743 } 2744 } 2745 } 2746 2747 void Algo_hash_center::finalize_process() { 2748 // write data map to db 2749 char sql[200]; 2750 sprintf(sql, "insert into algo_hash_%d_%s (hash, freq) values (?,?);", boardsize, dbnameext.c_str()); 2751 sqlite3_stmt *ppStmt=0; 2752 int rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 2753 for(map<hashtype, int>::iterator it = data.begin(); it != data.end(); it++) { 2754 rc = sqlite3_bind_int64(ppStmt, 1, it->first); 2755 rc = sqlite3_bind_int(ppStmt, 2, it->second); 2756 rc = sqlite3_step(ppStmt); 2757 rc = sqlite3_reset(ppStmt); 2758 } 2759 rc = sqlite3_finalize(ppStmt); 2760 } 2738 2761 2739 2762 pair<hashtype,int> Algo_hash_center::compute_hashkey(PatternList& pl, int CS) {
