fix differing behaviour when used with dicts
This commit is contained in:
parent
a4bfbeb2f5
commit
4715ea4390
|
@ -10,7 +10,7 @@ def iterExtract(query: str, choices: Iterable, scorer: Callable = fuzz.WRatio, p
|
||||||
score_cutoff: float = 0) -> Generator[Tuple[str, float], None, None]:
|
score_cutoff: float = 0) -> Generator[Tuple[str, float], None, None]:
|
||||||
a = processor(query) if processor else query
|
a = processor(query) if processor else query
|
||||||
|
|
||||||
if hasattr(choices, "items"):
|
if isinstance(choices, dict):
|
||||||
for choice, match_choice in choices.items():
|
for choice, match_choice in choices.items():
|
||||||
b = processor(match_choice) if processor else match_choice
|
b = processor(match_choice) if processor else match_choice
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ def iterExtract(query: str, choices: Iterable, scorer: Callable = fuzz.WRatio, p
|
||||||
score_cutoff=score_cutoff)
|
score_cutoff=score_cutoff)
|
||||||
|
|
||||||
if score >= score_cutoff:
|
if score >= score_cutoff:
|
||||||
yield (choice, score)
|
yield (match_choice, score, choice)
|
||||||
else:
|
else:
|
||||||
for choice in choices:
|
for choice in choices:
|
||||||
b = processor(choice) if processor else choice
|
b = processor(choice) if processor else choice
|
||||||
|
@ -135,7 +135,8 @@ def extractOne(query: str, choices: Iterable, scorer: Callable = fuzz.WRatio, pr
|
||||||
result_score = 0
|
result_score = 0
|
||||||
result_choice = ""
|
result_choice = ""
|
||||||
|
|
||||||
if hasattr(choices, "items"):
|
if isinstance(choices, dict):
|
||||||
|
choice_key = ""
|
||||||
for choice, match_choice in choices.items():
|
for choice, match_choice in choices.items():
|
||||||
b = processor(match_choice) if processor else match_choice
|
b = processor(match_choice) if processor else match_choice
|
||||||
|
|
||||||
|
@ -149,23 +150,25 @@ def extractOne(query: str, choices: Iterable, scorer: Callable = fuzz.WRatio, pr
|
||||||
# elements have the same score the first one is used
|
# elements have the same score the first one is used
|
||||||
score_cutoff = score + 0.00001
|
score_cutoff = score + 0.00001
|
||||||
if score_cutoff > 100:
|
if score_cutoff > 100:
|
||||||
return (choice, score)
|
return (match_choice, score, choice)
|
||||||
result_score = score
|
result_score = score
|
||||||
result_choice = choice
|
result_choice = match_choice
|
||||||
else:
|
choice_key = choice
|
||||||
for choice in choices:
|
return (choice_key, result_score, result_choice) if result_score else None
|
||||||
b = processor(choice) if processor else choice
|
|
||||||
|
for choice in choices:
|
||||||
|
b = processor(choice) if processor else choice
|
||||||
|
|
||||||
score = scorer(
|
score = scorer(
|
||||||
a, b,
|
a, b,
|
||||||
processor=None,
|
processor=None,
|
||||||
score_cutoff=score_cutoff)
|
score_cutoff=score_cutoff)
|
||||||
|
|
||||||
if score >= score_cutoff:
|
if score >= score_cutoff:
|
||||||
score_cutoff = score + 0.00001
|
score_cutoff = score + 0.00001
|
||||||
if score_cutoff > 100:
|
if score_cutoff > 100:
|
||||||
return (choice, score)
|
return (choice, score)
|
||||||
result_score = score
|
result_score = score
|
||||||
result_choice = choice
|
result_choice = choice
|
||||||
|
|
||||||
return (result_choice, result_score) if result_score else None
|
return (result_choice, result_score) if result_score else None
|
||||||
|
|
Loading…
Reference in New Issue