def execute(self): db = Db() l = text_to_list(self.file_contents) d = list_to_dict(l) db.update_word_counts(d, self.doc_type) db.update_doctype_count(self.count, self.doc_type) return self.count
def set_text(self, text): words = text_to_list(text) if not len(words): raise ValueError('Text did not contain any valid words') self.words = words return self
def set_text(self, text): #just pass list here one line only self.text = text lines = [] # shorten this later words = text_to_list(line) if not len(words): raise ValueError('Text doesnt contain valid keywords' ) ## sabb ma nepali message pass garnu else: for word in words: lines.append(word) self.lines = lines return self
def learn_file(self, name, count): file_contents = None words_count = 0 db = self.db try: f = open(name, 'r') file_contents = f.read() f.close() l = text_to_list(file_contents) d = list_to_dict(l) words_count = db.update_word_counts(d, self.doc_type) db.update_doctype_count(count, self.doc_type) print '>> TRAINING [ %s ]: %5d words learned from "%s"' % (self.doc_type, words_count, name) except Exception as e: raise ValueError(usage + '\nUnable to read specified file "%s", the error message was: %s' % (args[3], e)) return words_count