Use basedpyright refactor
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import functools
|
||||
import time
|
||||
import typing
|
||||
from collections.abc import Callable, Iterable, Iterator
|
||||
from collections.abc import Callable, Iterable
|
||||
|
||||
import Levenshtein
|
||||
from folkugat_web.config import search as config
|
||||
@@ -12,7 +12,7 @@ from folkugat_web.model import search as search_model
|
||||
from folkugat_web.model import temes as model
|
||||
|
||||
|
||||
def get_query_word_similarity(query_word: str, text_ngrams: model.NGrams) -> search_model.SearchMatch:
|
||||
def get_query_word_similarity(query_word: str, text_ngrams: search_model.NGrams) -> search_model.SearchMatch:
|
||||
n = len(query_word)
|
||||
if n < config.MIN_NGRAM_LENGTH:
|
||||
return search_model.SearchMatch(distance=0.0, ngram='')
|
||||
@@ -27,13 +27,13 @@ def get_query_word_similarity(query_word: str, text_ngrams: model.NGrams) -> sea
|
||||
default=search_model.SearchMatch(distance=float("inf"), ngram=""))
|
||||
|
||||
|
||||
def get_query_similarity(query: str, ngrams: model.NGrams) -> search_model.SearchMatch:
|
||||
def get_query_similarity(query: str, ngrams: search_model.NGrams) -> search_model.SearchMatch:
|
||||
query_words = query.lower().split()
|
||||
word_matches = map(lambda query_word: get_query_word_similarity(query_word, ngrams), query_words)
|
||||
return search_model.SearchMatch.combine_matches(word_matches)
|
||||
|
||||
|
||||
def build_result(query: str, entry: tuple[int, model.NGrams]) -> search_model.QueryResult:
|
||||
def build_result(query: str, entry: tuple[int, search_model.NGrams]) -> search_model.QueryResult:
|
||||
if len(query) == 0:
|
||||
return search_model.QueryResult(
|
||||
id=entry[0],
|
||||
@@ -51,6 +51,7 @@ def build_result(query: str, entry: tuple[int, model.NGrams]) -> search_model.Qu
|
||||
T = typing.TypeVar("T")
|
||||
|
||||
|
||||
@typing.no_type_check
|
||||
def _thread(it: Iterable[T], *funcs: Callable[[Iterable], Iterable]) -> Iterable:
|
||||
return functools.reduce(lambda i, fn: fn(i), funcs, it)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user