def search(self, word, max_cost=2, size=5): """ parameters: - word: the word to return autocomplete results for - max_cost: Maximum Levenshtein edit distance to be considered when calculating results - size: The max number of results to return """ word = normalize_node_name(word) if not word: return [] key = f'{word}-{max_cost}-{size}' result = self._lfu_cache.get(key) if result == -1: result = list(self._find_and_sort(word, max_cost, size)) self._lfu_cache.set(key, result) return result
def test_normalize_node_name(self, name, extra_chars, expected_result): result = normalize_node_name(name, extra_chars=extra_chars) assert expected_result == result
def get_word_context(self, word): """ Gets the word's context from the words dictionary """ word = normalize_node_name(word) return self.words.get(word)