def get_ending(self,new_word,n=7): begin=self.nearest_begin(new_word) words=self.full_words(begin) words=tools.unique_list(words) if(len(words)<n): n=len(words) nearest_words=knn.nearest_k(new_word,words,k=n) nearest_words=[distance.decode_digraphs(word_i) for word_i in nearest_words] return nearest_words
def correct(self,new_word,unique=False): new_word=code_digraphs(new_word) keys=self.forms_dict.all_basic() words=knn.nearest_k(new_word,keys,k=5,metric=norm_begin_metric) #tools.print_unicode(words) if(unique): full_words=[] for word_i in words: full_word_i=self.forms_dict.full_words([word_i])[0] full_words.append(full_word_i) else: full_words=self.forms_dict.full_words(words) prob_pairs=[ (word_i,self.p(new_word,word_i)) for word_i in full_words] prob_pairs.sort(key=lambda x: x[1], reverse=True) return prob_pairs
def correct(self, new_word, unique=False): new_word = code_digraphs(new_word) keys = self.forms_dict.all_basic() words = knn.nearest_k(new_word, keys, k=5, metric=norm_begin_metric) #tools.print_unicode(words) if (unique): full_words = [] for word_i in words: full_word_i = self.forms_dict.full_words([word_i])[0] full_words.append(full_word_i) else: full_words = self.forms_dict.full_words(words) prob_pairs = [(word_i, self.p(new_word, word_i)) for word_i in full_words] prob_pairs.sort(key=lambda x: x[1], reverse=True) return prob_pairs