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
def test_levenshtein_distance_difference_1(): assert levenshtein_distance("aac", "abc") == 1 assert levenshtein_distance("abc", "aac") == 1
def test_levenshtein_distance_from_equal_strings(): assert levenshtein_distance("abc", "abc") == 0
def test_levenshtein_distance_swapped_letters(): assert levenshtein_distance("help", "hepl") == 2
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
async def _precompile(self) -> None: log.debug("Started precompiling functions...") levenshtein_distance("", "") log.debug("Finished precompiling functions")