Port cache-`dict` search to new `rapidfuzz` api
parent
81a8cd1685
commit
e5fdb33e31
|
@ -43,7 +43,7 @@ from typing import (
|
||||||
Iterator,
|
Iterator,
|
||||||
)
|
)
|
||||||
import time
|
import time
|
||||||
# from pprint import pformat
|
from pprint import pformat
|
||||||
|
|
||||||
from rapidfuzz import process as fuzzy
|
from rapidfuzz import process as fuzzy
|
||||||
import trio
|
import trio
|
||||||
|
@ -1139,21 +1139,25 @@ async def search_simple_dict(
|
||||||
|
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
|
|
||||||
tokens = []
|
tokens: list[str] = []
|
||||||
for key in source:
|
for key in source:
|
||||||
if not isinstance(key, str):
|
match key:
|
||||||
tokens.extend(key)
|
case str():
|
||||||
else:
|
tokens.append(key)
|
||||||
tokens.append(key)
|
case []:
|
||||||
|
tokens.extend(key)
|
||||||
|
|
||||||
# search routine can be specified as a function such
|
# search routine can be specified as a function such
|
||||||
# as in the case of the current app's local symbol cache
|
# as in the case of the current app's local symbol cache
|
||||||
matches = fuzzy.extractBests(
|
matches = fuzzy.extract(
|
||||||
text,
|
text,
|
||||||
tokens,
|
tokens,
|
||||||
score_cutoff=90,
|
score_cutoff=90,
|
||||||
)
|
)
|
||||||
|
log.info(
|
||||||
|
'cache search results:\n'
|
||||||
|
f'{pformat(matches)}'
|
||||||
|
)
|
||||||
return [item[0] for item in matches]
|
return [item[0] for item in matches]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue