Exemple #1
0
 def _suggest_similar_command(self, unknown_command: str) -> str:
     min_dist = 100000
     suggestion = ""
     for command in self.config.commands.data.keys():
         dist = levenshtein_distance(unknown_command, command)
         if dist < min_dist:
             suggestion = command
             min_dist = dist
     for command in self.config.commands.aliases.keys():
         dist = levenshtein_distance(unknown_command, command)
         if dist < min_dist:
             suggestion = command
             min_dist = dist
     return suggestion
Exemple #2
0
def test_levenshtein_distance_difference_1():
    assert levenshtein_distance("aac", "abc") == 1
    assert levenshtein_distance("abc", "aac") == 1
Exemple #3
0
def test_levenshtein_distance_from_equal_strings():
    assert levenshtein_distance("abc", "abc") == 0
Exemple #4
0
def test_levenshtein_distance_swapped_letters():
    assert levenshtein_distance("help", "hepl") == 2
Exemple #5
0
def test_levenshtein_distance_different_length():
    assert levenshtein_distance("ab", "abc") == 1
    assert levenshtein_distance("abc", "ab") == 1
    assert levenshtein_distance("a", "abc") == 2
    assert levenshtein_distance("abc", "a") == 2
Exemple #6
0
 async def _precompile(self) -> None:
     log.debug("Started precompiling functions...")
     levenshtein_distance("", "")
     log.debug("Finished precompiling functions")