diff --git a/src/database.py b/src/database.py index 547abee..6c38e5b 100644 --- a/src/database.py +++ b/src/database.py @@ -24,3 +24,12 @@ class Database: def commit(self): self.db.commit() + + def is_step_done(self, step_name): + wc_done = self.db.execute("SELECT count(*) FROM StepsDone WHERE step=?", (step_name, )).fetchone() + return wc_done[0] != 0 + + def step_is_done(self, step_name): + self.db.execute("INSERT INTO StepsDone (step) VALUES (?)", (step_name, )) + self.db.commit() + diff --git a/src/match_store.py b/src/match_store.py index 9835b91..a5fe6d6 100644 --- a/src/match_store.py +++ b/src/match_store.py @@ -104,9 +104,7 @@ class MatchStore: def determine_colocation_dispersions(self): step_name = 'dispersions' - wc_done = self.db.execute("SELECT count(*) FROM StepsDone WHERE step=?", (step_name, )).fetchone() - - if wc_done[0] == 1: + if self.db.is_step_done(step_name): self.load_dispersions() return @@ -120,9 +118,7 @@ class MatchStore: print("Storing dispersions...") self.store_dispersions() - self.db.execute("INSERT INTO StepsDone (step) VALUES (?)", (step_name, )) - self.db.commit() - + self.db.step_is_done(step_name) def store_dispersions(self): for (structure_id, component_id, lemma), disp in self.dispersions.items(): diff --git a/src/word_stats.py b/src/word_stats.py index 341e8d6..85b83fe 100644 --- a/src/word_stats.py +++ b/src/word_stats.py @@ -43,8 +43,7 @@ class WordStats: def generate_renders(self): step_name = 'generate_renders' - wc_done = self.db.execute("SELECT count(*) FROM StepsDone WHERE step=?", (step_name, )).fetchone() - if wc_done[0] == 1: + if self.db.is_step_done(step_name): print("Skipping GenerateRenders, already complete") return @@ -58,8 +57,7 @@ class WordStats: self.db.execute("INSERT INTO WordCount (lemma, msd0, frequency) VALUES (?,?,?)", (lemma, msd0, freq)) - self.db.execute("INSERT INTO StepsDone (step) VALUES (?)", (step_name, )) - self.db.commit() + self.db.step_is_done(step_name) def common_lemma_msd(self, lemma, msd): lf = self.lemma_features