Changeset 236

Show
Ignore:
Timestamp:
03/02/07 23:55:40 (1 year ago)
Author:
ug
Message:

Fixed some issues with creating the frequency db.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/libkombilo-branches/hash_center_makedb/analyze.py

    r235 r236  
    33db = dbapi2.connect('t1.db2') 
    44c = db.cursor() 
    5 c.execute('select card from algo_hash_19_CENTER;') 
     5c.execute('select freq from algo_hash_19_CENTER;') 
    66a = c.fetchall() 
    77 
  • 06/libkombilo-branches/hash_center_makedb/makedb.py

    r235 r236  
    33db = dbapi2.connect('t1.db2') 
    44c = db.cursor() 
    5 c.execute('select hash,card from algo_hash_19_CENTER where card > 40 and card < 5000;') 
     5c.execute('select hash,freq from algo_hash_19_CENTER where freq > 40 and freq < 5000;') 
    66a = c.fetchall() 
    77print 'retrieved data', len(a) 
  • 06/libkombilo-branches/hash_center_makedb/process.py

    r233 r236  
    4747# filelist = glob.glob('./*.sgf') 
    4848# 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') 
    5050# filelist = glob.glob('/home/ug/go/KGS2005/*.sgf') 
    5151 
    52 filelist.sort() 
    53 process(filelist) 
     52for path in ['/home/ug/go/gogod06/*/*.sgf', '/home/ug/go/KGS/*/*.sgf']: 
     53    filelist = glob.glob(path) 
     54    filelist.sort() 
     55    process(filelist) 
    5456 
    5557gl = GameList("t1.db", "id", "[[filename.]], ") 
    5658 
    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() 
    5961 
    60 gl.reset() 
    61 gl.search(p, so) 
     62# gl.reset() 
     63# gl.search(p, so) 
    6264 
    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) 
    6567 
    6668 
  • 06/libkombilo-branches/hash_center_makedb/search.cpp

    r233 r236  
    238238} 
    239239 
    240 Pattern::Pattern(int type, int BOARDSIZE, int sX, int sY, 
    241                  char* iPos, vector<MoveNC> CONTLIST, char* CONTLABELS) { 
     240Pattern::Pattern(int type, int BOARDSIZE, int sX, int sY, char* iPos, vector<MoveNC> CONTLIST, char* CONTLABELS) { 
    242241  flip = 0; 
    243242  colorSwitch = 0; 
     
    293292} 
    294293 
    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) { 
     294Pattern::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) { 
    297295  // check whether anchor rectangle is valid 
    298296  if (le < 0 || ri+sX > BOARDSIZE || to < 0 || bo+sY > BOARDSIZE || ri < le || bo < to) throw PatternError(); 
     
    27202718Algo_hash_center::Algo_hash_center(int bsize) : Algo_hash(bsize, "CENTER", 16) { 
    27212719  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++) 
    27242722      hi->push_back(new HashInstanceCTR(i, j, 4, 4, boardsize)); 
     2723} 
     2724 
     2725void 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(); 
    27252734} 
    27262735         
     
    27302739      (*it)->changed = false; 
    27312740      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 
     2747void 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
    27382761 
    27392762pair<hashtype,int> Algo_hash_center::compute_hashkey(PatternList& pl, int CS) {