Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 def test_normalize_node_name(self, name, extra_chars, expected_result):
     result = normalize_node_name(name, extra_chars=extra_chars)
     assert expected_result == result
Ejemplo n.º 3
0
 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)