feat(dict): high-speed offline dictionary with wordforms and zero daemon SQLite mmap
This commit is contained in:
1 parent
9d4e911bfd
commit
9a5d588125
6 files changed
+602
-15
No files matched your search
+34
-2
@@ -240,8 +240,40 @@ async def lookup_term(query: str) -> Dict[str, Any]:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
words = query_clean.split()
|
||||
is_sentence = len(words) > 4
|
||||
# Check offline dictionary first (Zero Daemon, < 0.1ms via SQLite mmap)
|
||||
words = query_clean.split()
|
||||
is_sentence = len(words) > 4
|
||||
if not is_sentence:
|
||||
try:
|
||||
off_row = conn.execute(
|
||||
"SELECT term, translation, phonetic, pos FROM offline_dictionary WHERE term = ? COLLATE NOCASE",
|
||||
(query_clean,)
|
||||
).fetchone()
|
||||
if off_row:
|
||||
raw_trans = off_row["translation"] or ""
|
||||
tr_list = [t.strip() for t in raw_trans.split(",") if t.strip()]
|
||||
res = {
|
||||
"query": query_clean,
|
||||
"is_sentence": False,
|
||||
"translation": raw_trans,
|
||||
"translations_list": tr_list,
|
||||
"translation_ru": raw_trans,
|
||||
"phonetic": off_row["phonetic"] or "",
|
||||
"audio_file": "",
|
||||
"audio_url": "",
|
||||
"part_of_speech": off_row["pos"] or "",
|
||||
"definitions": [],
|
||||
"examples": [],
|
||||
"source": "offline",
|
||||
}
|
||||
conn.execute(
|
||||
"INSERT OR REPLACE INTO dictionary_cache (query, response_json) VALUES (?, ?)",
|
||||
(query_clean, json.dumps(res, ensure_ascii=False))
|
||||
)
|
||||
return res
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
result: Dict[str, Any] = {
|
||||
"query": query_clean,
|
||||
|
||||
Reference in new issue
Block a user