def known_edits2(self, word): # words = set(e2 for e1 in edits1(word) for e2 in edits1(e1) if self.lookup(e2)) v = set() for c in words: if(spelltools.is_valid(c)): v.add(c) return words
def known_edits2(self, word): # words = set(e2 for e1 in edits1(word) for e2 in edits1(e1) if self.lookup(e2)) v = set() for c in words: if (spelltools.is_valid(c)): v.add(c) return words
def correct(self, word): """ Give suggestion to wrong word @param word: input word @type word: unicode @return: a list of suggested words @rtype: list of unicode """ candidates = self.known([word]) if not candidates: candidates = self.known(edits1(word)) #ToDo: implement the second error edits #if not candidates: #candidates = self.known_edits2(word) if not candidates: candidates = [word] return sorted(candidates, key=lambda x: spelltools.phonetic_distance(word,x))
def known_edits2(self, word): return set(e2 for e1 in edits1(word) for e2 in edits1(e1) if self.lookup(e2))