From dedc031696a361a8111939514c251c17b55b9e86 Mon Sep 17 00:00:00 2001 From: Ozbolt Menegatti Date: Wed, 21 Aug 2019 12:16:10 +0200 Subject: [PATCH] Step recorded: generate_renders --- src/database.py | 3 +++ src/word_stats.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/database.py b/src/database.py index 32da2a2..547abee 100644 --- a/src/database.py +++ b/src/database.py @@ -10,6 +10,9 @@ class Database: self.new = not os.path.exists(filename) self.db = sqlite3.connect(filename) + + self.init("CREATE TABLE StepsDone ( step varchar(32) )") + self.commit() def execute(self, *args, **kwargs): return self.db.execute(*args, **kwargs) diff --git a/src/word_stats.py b/src/word_stats.py index 0462bee..341e8d6 100644 --- a/src/word_stats.py +++ b/src/word_stats.py @@ -42,6 +42,12 @@ class WordStats: return self.all_words 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: + print("Skipping GenerateRenders, already complete") + return + lemmas = [lemma for (lemma, ) in self.db.execute("SELECT DISTINCT lemma FROM UniqWords")] for lemma in progress(lemmas, 'word-count'): num_words = defaultdict(int) @@ -51,6 +57,8 @@ class WordStats: for msd0, freq in num_words.items(): 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() def common_lemma_msd(self, lemma, msd):