root/06/libkombilo/process.py

Revision 239, 1.7 kB (checked in by ug, 1 year ago)

Handling of duplicates within GameList, also during process.
Better access to processing results.

  • Property svn:executable set to
Line 
1 #! /usr/bin/env python2.4
2
3 # from pysqlite2 import dbapi2
4 import os
5 import os.path
6 import sys
7 import glob
8 import time
9 from libkombilo import *
10
11 try:
12     os.system('rm t1.db*')
13 except:
14     pass
15
16 def process(filenames):
17     """Process a list of sgf files, put the game info into "table" of the database
18     given by con, and call the relevant processing functions for the algorithms in algos"""
19
20     starttime = time.time()
21     try:
22         pop = ProcessOptions()
23         # pop.algos = 0
24         # pop.rootNodeTags = 'PW,PB,RE,DT'
25         pop.sgfInDB = False
26         gl = GameList('t1.db', 'id', '', pop, 1000)
27     except DBError:
28         print 'Database error'
29     gl.start_processing()
30     counter = 0
31     for filename in filenames:
32         # print filename
33         try:
34             file = open(filename)
35             sgf = file.read()
36             file.close()
37         except:
38             print 'Unable to read file %s' % filename
39             continue
40
41         path, fn = os.path.split(filename)
42         if gl.process(sgf, path, fn, '', CHECK_FOR_DUPLICATES_STRICT):
43             if gl.process_results() & IS_DUPLICATE:
44                 print 'duplicate', counter
45         else: print 'SGF error'
46         counter += 1
47        
48     gl.finalize_processing()
49     print 'Processed %d games in %.2f seconds' % (counter, time.time()-starttime)
50
51 # filelist = glob.glob('./*.sgf')
52 filelist = glob.glob('/home/ug/go/gogod06/*/*.sgf')
53 # filelist = glob.glob('/home/ug/go/KGS2005/*.sgf')
54
55 filelist.sort()
56 process(filelist)
57
58 gl = GameList("t1.db", "id", "[[filename.]], ")
59
60 p = Pattern(CENTER_PATTERN, 19, 3, 5, ".X..OX.OX.OXOXO")
61 so = SearchOptions()
62
63 gl.reset()
64 gl.search(p, so)
65
66 for i in range(gl.size())[-10:]:
67       print gl.currentEntryAsString(i)
68
69
Note: See TracBrowser for help on using the browser.