match_num now loaded from database

and --keep-db deprecated in favour of --new-db (harder for me to fu*k up)
pull/1/head
Ozbolt Menegatti 5 years ago
parent 07242f74c8
commit 4124036474

@ -5,7 +5,7 @@ class Database:
def __init__(self, args):
filename = ":memory:" if args.db is None else args.db
if not args.keep_db and os.path.exists(filename):
if args.new_db and os.path.exists(filename):
os.remove(filename)
self.new = not os.path.exists(filename)

@ -9,7 +9,6 @@ class MatchStore:
def __init__(self, args, db):
self.db = db
self.dispersions = {}
self.match_num = 0
self.db.init("""CREATE TABLE Colocations (
@ -51,6 +50,8 @@ class MatchStore:
self.db.init("CREATE INDEX col_r ON Representations (colocation_id)")
self.db.init("CREATE INDEX disp_key ON Dispersions (structure_id, component_id, lemma)")
match_num = self.db.execute("SELECT MAX(match_id) FROM Matches").fetchone()[0]
self.match_num = 0 if match_num is None else match_num + 1
def _add_match(self, key, structure, match):
structure_id, key_str = key[0], str(key[1:])
cid = self.db.execute("SELECT colocation_id FROM Colocations WHERE key=? AND structure_id=?",

@ -125,8 +125,8 @@ if __name__ == '__main__':
parser.add_argument('--db',
help="Database file to use (instead of memory)", default=None)
parser.add_argument('--keep-db',
help="Does not recreate new database file", action='store_true')
parser.add_argument('--new-db',
help="Writes over database file, if there exists one", action='store_true')
parser.add_argument('--pc-tag',
help='Tag for separators, usually pc or c', default="pc")

Loading…
Cancel
Save