Browse Source

- Move to a ranked match for fuzzy matching

plan_generation
Dan 1 year ago
parent
commit
1dab6466e8
  1. 37
      ui/workers/gather_evolutions_worker.py

37
ui/workers/gather_evolutions_worker.py

@ -439,14 +439,29 @@ class GatherEvolutions(QRunnable):
stripped_form = self.strip_pokemon_name(name, form)
best_match = None
best_score = -1
for entry in results:
stripped_db_form = self.strip_pokemon_name(entry["name"], entry["form_name"])
if self.fuzzy_match_form(stripped_form, stripped_db_form, threshold):
return entry["pfic"]
stripped_db_form_genderless = self.strip_gender_from_form(stripped_db_form)
#if self.fuzzy_match_form(stripped_form, stripped_db_form, threshold):
# return entry["pfic"]
match_score = self.fuzzy_match_form(stripped_form, stripped_db_form)
genderless_score = self.fuzzy_match_form(stripped_form, stripped_db_form_genderless)
stripped_db_form = self.strip_gender_from_form(stripped_db_form)
if self.fuzzy_match_form(stripped_form, stripped_db_form, threshold):
return entry["pfic"]
#if self.fuzzy_match_form(stripped_form, stripped_db_form, threshold):
# return entry["pfic"]
if match_score > best_score:
best_match = entry["pfic"]
best_score = match_score
if genderless_score > best_score:
best_match = entry["pfic"]
best_score = genderless_score
return best_match if best_score >= threshold else None
# Some times we get a form for a pokemon that doesn't really have one.
#if len(results) > 1 and form != None and gender and threshold != 100:
@ -468,7 +483,11 @@ class GatherEvolutions(QRunnable):
form_name = form_name.replace("Male", "").replace("male", "").strip()
return form_name
def fuzzy_match_form(self, form1: str, form2: str, threshold: int = 80) -> bool:
if form1 is None or form2 is None:
return form1 == form2
return fuzz.ratio(form1.lower(), form2.lower()) >= threshold
def fuzzy_match_form(self, form1: str, form2: str) -> bool:
if form1 is None:
form1 = ""
if form2 is None:
form2 = ""
return fuzz.ratio(form1.lower(), form2.lower())
Loading…
Cancel
Save