match_num now loaded from database

and --keep-db deprecated in favour of --new-db (harder for me to fu*k up)
This commit is contained in:
Ozbolt Menegatti 2019-09-09 15:29:15 +02:00
parent 07242f74c8
commit 4124036474
3 changed files with 5 additions and 4 deletions

View File

@ -5,7 +5,7 @@ class Database:
def __init__(self, args): def __init__(self, args):
filename = ":memory:" if args.db is None else args.db 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) os.remove(filename)
self.new = not os.path.exists(filename) self.new = not os.path.exists(filename)

View File

@ -9,7 +9,6 @@ class MatchStore:
def __init__(self, args, db): def __init__(self, args, db):
self.db = db self.db = db
self.dispersions = {} self.dispersions = {}
self.match_num = 0
self.db.init("""CREATE TABLE Colocations ( 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 col_r ON Representations (colocation_id)")
self.db.init("CREATE INDEX disp_key ON Dispersions (structure_id, component_id, lemma)") 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): def _add_match(self, key, structure, match):
structure_id, key_str = key[0], str(key[1:]) structure_id, key_str = key[0], str(key[1:])
cid = self.db.execute("SELECT colocation_id FROM Colocations WHERE key=? AND structure_id=?", cid = self.db.execute("SELECT colocation_id FROM Colocations WHERE key=? AND structure_id=?",

View File

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