From 33528f1495ad045162e0927ab7e7360cfdb9edfd Mon Sep 17 00:00:00 2001 From: Ozbolt Menegatti Date: Wed, 21 Aug 2019 12:57:42 +0200 Subject: [PATCH] step_done now implemented in database.py --- src/database.py | 9 +++++++++ src/match_store.py | 8 ++------ src/word_stats.py | 6 ++---- 3 files changed, 13 insertions(+), 10 deletions(-) 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