From 41240364740408db6990378d5dad3d17485bc041 Mon Sep 17 00:00:00 2001 From: Ozbolt Menegatti Date: Mon, 9 Sep 2019 15:29:15 +0200 Subject: [PATCH] match_num now loaded from database and --keep-db deprecated in favour of --new-db (harder for me to fu*k up) --- src/database.py | 2 +- src/match_store.py | 3 ++- src/wani.py | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/database.py b/src/database.py index 6c38e5b..bdb9cd2 100644 --- a/src/database.py +++ b/src/database.py @@ -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) diff --git a/src/match_store.py b/src/match_store.py index bebfe7a..d5736f6 100644 --- a/src/match_store.py +++ b/src/match_store.py @@ -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=?", diff --git a/src/wani.py b/src/wani.py index 253ad0a..d285c62 100644 --- a/src/wani.py +++ b/src/wani.py @@ -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")