fix problem from claude

This commit is contained in:
SlimusMinus
2026-10-20 00:37:43 +03:00
parent f01f776d32
commit 28d91ce6d4
31 changed files with 994 additions and 284 deletions

View File

@@ -1,3 +1,5 @@
from functools import lru_cache
import pymorphy3
@@ -5,11 +7,21 @@ class Lemmatizer:
def __init__(self):
self.morph = pymorphy3.MorphAnalyzer()
# Разбор pymorphy — самое дорогое в детекторе, а слова повторяются
self._normalize_cached = lru_cache(maxsize=50_000)(self._normalize)
self._is_known_cached = lru_cache(maxsize=50_000)(self.morph.word_is_known)
def is_known(self, word: str) -> bool:
"""Есть ли слово в словаре pymorphy (обычное слово, а не сленг/опечатка)."""
return self._is_known_cached(word)
def _normalize(self, word: str) -> str:
result = self.morph.parse(word)
return result[0].normal_form
def normalize(
self,
word: str
) -> str:
result = self.morph.parse(word)
return result[0].normal_form
return self._normalize_cached(word)