From b217372fea536d3af83c92ee19be2e694debcc7c Mon Sep 17 00:00:00 2001 From: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> Date: Mon, 5 May 2025 19:18:20 -0400 Subject: [PATCH] Core: Make Perfect Fuzzy Match Prioritize Casing (#4956) --- Utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Utils.py b/Utils.py index 46a0d106..a3a529d7 100644 --- a/Utils.py +++ b/Utils.py @@ -635,6 +635,8 @@ def get_fuzzy_results(input_word: str, word_list: typing.Collection[str], limit: import jellyfish def get_fuzzy_ratio(word1: str, word2: str) -> float: + if word1 == word2: + return 1.01 return (1 - jellyfish.damerau_levenshtein_distance(word1.lower(), word2.lower()) / max(len(word1), len(word2))) @@ -655,8 +657,10 @@ def get_intended_text(input_text: str, possible_answers) -> typing.Tuple[str, bo picks = get_fuzzy_results(input_text, possible_answers, limit=2) if len(picks) > 1: dif = picks[0][1] - picks[1][1] - if picks[0][1] == 100: + if picks[0][1] == 101: return picks[0][0], True, "Perfect Match" + elif picks[0][1] == 100: + return picks[0][0], True, "Case Insensitive Perfect Match" elif picks[0][1] < 75: return picks[0][0], False, f"Didn't find something that closely matches '{input_text}', " \ f"did you mean '{picks[0][0]}'? ({picks[0][1]}% sure)"