diff options
Diffstat (limited to 'dict.py')
-rw-r--r-- | dict.py | 40 |
1 files changed, 34 insertions, 6 deletions
@@ -76,7 +76,7 @@ class Word: self.word = None self.length = None self.synsetid_list = [] - return + return None else: return "Invalid Usage" @@ -92,6 +92,13 @@ class Word: def get_wordid(self): return self.wordid + + def get_category(self, categoryid): + self.category_list = [] + self.cur.execute("SELECT * from las_categorydef where categoryid = ?", (categoryid,)) + (categoryid, name, pos) = self.cur.fetchone() + return name + def get_synsetid(self): self.cur.execute("SELECT * from las_sense where wordid = ?", (self.wordid,)) @@ -99,14 +106,16 @@ class Word: self.synsetid_list.append(synsetid) return self.synsetid_list + def get_def(self): self.def_list = [] if self.synsetid_list == []: self.get_synsetid() for synsetid in self.synsetid_list: self.cur.execute("SELECT * from las_synset where synsetid = ?", (synsetid,) ) - for (synsetid, pos, definition) in self.cur: - self.def_list.append( (pos, definition)) + for (synsetid, pos, categoryid, definition) in self.cur: + cat_name = self.get_category(categoryid) + self.def_list.append((pos, definition, cat_name)) return self.def_list def get_usage(self): @@ -116,20 +125,39 @@ class Word: for synsetid in self.synsetid_list: self.cur.execute("SELECT * from las_sample where synsetid = ?", (synsetid,)) for (synsetid, sampleid, sample) in self.cur: - self.usage_list.append( (sample)) + self.usage_list.append((sample)) return self.usage_list + def update_score(self, wordid, action = "correct"): + if action == "correct": + try: + self.cur.execute("SELECT * from las_score where wordid = ?", (wordid,)) + (wordid, num_played, num_correct) = self.cur.fecthone() + num_played = num_played + 1 + num_correct = num_correct + 1 + self.cur.execute("UPDATE las_score SET num_played = ? , num_correct = ? where wordid = ?", (num_played, num_correct, wordid,)) + except : + self.cur.execute("INSERT into las_score (wordid, num_played, num_correct) VALUES (?,?,?) ", (wordid,1,1, )) + elif action == "incorrect": + try: + self.cur.execute("SELECT * from las_score where wordid = ?", (wordid,)) + (wordid, num_played, num_correct) = self.cur.fecthone() + num_played = num_played + 1 + self.cur.execute("UPDATE las_score SET num_played = ? where wordid = ?", (num_played, wordid,)) + except : + self.cur.execute("INSERT into las_score (wordid, num_played) VALUES (?,?) ", (wordid,1, )) + self.conn.commit() if __name__ == "__main__": k = Dict() num_words = k.get_num_words() print num_words - id = k.get_random_wordid(length = 5, numwords = 3) #will return word of length 15 + id = k.get_random_wordid(length = 5, numwords = 3) #will return word of length 5 for (wordid,) in id: print wordid l = Word("wordid", wordid ) print l.get_word() print l.get_def() - print l.get_usage()
\ No newline at end of file + print l.get_usage() |