refactor(stage-3): add Keep-Alive connection pool for Ollama, implement offline lemma resolution in dictionary

This commit is contained in:
2026-10-07 14:45:05 +03:00
parent 9072fc365a
commit 4e1f809018
3 changed files with 131 additions and 82 deletions
+20
View File
@@ -303,9 +303,29 @@ async def lookup_term(query: str) -> Dict[str, Any]:
"SELECT term, translation, phonetic, pos FROM offline_dictionary WHERE term = ? COLLATE NOCASE",
(query_clean,)
).fetchone()
lemma_found = None
if not off_row and len(words) == 1:
try:
from app.phrasal import lemmatize_word
for cand in lemmatize_word(query_clean):
if cand.lower() != query_clean.lower():
row = conn.execute(
"SELECT term, translation, phonetic, pos FROM offline_dictionary WHERE term = ? COLLATE NOCASE",
(cand,)
).fetchone()
if row:
off_row = row
lemma_found = row["term"]
break
except Exception:
pass
if off_row:
raw_trans = off_row["translation"] or ""
clean_trans = clean_russian_translation(raw_trans)
if lemma_found and lemma_found.lower() != query_clean.lower():
clean_trans = f"{clean_trans} (от {lemma_found})"
tr_list = [t.strip() for t in clean_trans.split(",") if t.strip()]
res = {
"query": query_clean,