mgaitan/dictionary

GitHub: mgaitan/dictionary

一个基于 FastAPI 和 SQLite 的多语言双向词典 Web 搜索引擎,附带从旧式 PDB 和 IDO/LEO 格式中逆向提取数据的 pipeline。

Stars: 0 | Forks: 0

# 词典 用于德语-西班牙语和英语-西班牙语双向查询的网页搜索引擎,基于旧版应用程序重建。 目前发布的应用使用 FastAPI 运行,并使用 SQLite 作为查询数据库。数据生成依然使用 Python,并借助一个小型逆向工程 pipeline,将数据从 `IDO/LEO` 转换为可进行 Web 查询的格式。 ## 网站功能 - 支持按源词在四个方向上进行搜索 - 在服务器端对结果进行分页 - 高亮显示语法缩写、语义标记和标签 - 直接使用项目中包含的四个 SQLite 数据库 ## 结构 ``` dictionary/ app.py FastAPI app y wiring de templates/estáticos search.py lógica de búsqueda, normalización y render de glosas templates/index.html interfaz HTML server-side static/styles.css estilos site/data/ de-es-dictionary.sqlite alemán → español es-de-dictionary.sqlite español → alemán en-es-dictionary.sqlite inglés → español es-en-dictionary.sqlite español → inglés *.json artefactos intermedios locales, no versionados tools/ analyze_slagro.py exporta índices auténticos desde IDO/LEO build_raw_dictionary.py genera diccionario crudo desde IDO/LEO + DLL build_site_dictionary.py limpia y agrupa entradas build_site_sqlite.py genera SQLite para la web extract_msdict.py inspecciona PDB MSDict y genera SQLite ``` ## 运作方式 ### 1. 构建(Build)数据 网站不直接读取 `IDO` 或 `LEO`。在此之前,会按方向生成一个 SQLite 数据库: ``` flowchart LR A[slagrods.ido / slagrods.leo] --> B[analyze_slagro.py] A --> C[build_raw_dictionary.py] B --> D[de-es-index.json] C --> E[de-es-dictionary.json] D --> F[build_site_dictionary.py] E --> F F --> G[de-es-dictionary-indexed.json] G --> H[build_site_sqlite.py] D --> H H --> I[de-es-dictionary.sqlite] ``` 对于 `es → de`,会在 `slagrosd.IDO/LEO` 上使用相同的 pipeline。Oxford 字典 `en → es` 和 `es → en` 直接从其 MSDict PDB 中提取: ``` flowchart LR A[EnglishSpanish.pdb] --> C[extract_msdict.py] B[SpanishEnglish.pdb] --> C C --> D[BER + DEFLATE ramificado] D --> E[SQLite] ``` ### 2. Web 查询 FastAPI 应用会根据 query param `dict` 打开相应的 SQLite: - `de-es` - `es-de` - `en-es` - `es-en` 接着: 1. 规范化搜索词 2. 查询 `search_terms` 3. 对完全匹配进行排名,其次是前缀匹配,最后是内容匹配 4. 从 `senses` 中获取词义 5. 使用 Jinja2 渲染 HTML ``` sequenceDiagram participant U as Usuario participant F as FastAPI participant S as SQLite U->>F: GET /?dict=de-es&q=machen&page=1 F->>S: buscar entry_id en search_terms S-->>F: ids candidatos F->>S: traer entries + senses S-->>F: filas normalizadas F-->>U: HTML renderizado ``` ## FastAPI 技术细节 应用程序提供: - entrypoint:`dictionary.app:app` - 主路由:`GET /` - healthcheck:`GET /healthz` 渲染在服务器端进行,没有 SPA 或编译的前端。UI 由 [`dictionary/templates/index.html`](dictionary/templates/index.html) 输出,并使用在 [`dictionary/app.py`](dictionary/app.py) 中注册到 Jinja2 的 helper。 搜索逻辑集中在 [`dictionary/search.py`](dictionary/search.py): - `normalize_for_search()`:去除重音并规范化文本 - `search_entries()`:进行排名和分页 - `find_unresolved_index_entry()`:如果索引知道某个 lemma 但尚无重建的条目,则显示 fallback - `render_gloss_html()`:为标签、注释和缩写上色 ## SQLite 技术细节 每个数据库都包含以下主要表: - `entries`:每个分组的 lemma 对应一行 - `senses`:每个 lemma 的词义 - `search_terms`:用于搜索的已索引词汇 - `index_entries`:从 `IDO` 派生的真实索引,即使目前尚无已解码的条目 - `metadata`:计数器和构建来源 ``` erDiagram entries ||--o{ senses : has entries ||--o{ search_terms : indexed_by index_entries { integer id text headword text normalized_headword integer leo_offset integer page_span integer has_decoded_entry } entries { integer id text headword text normalized_headword integer decoded_complete } senses { integer id integer entry_id integer sense_index text source text glosses_json text tags_json } search_terms { integer entry_id text term text normalized_term text kind } ``` ## 实用命令 重新生成所有内容: ``` make build-data ``` 仅德语 → 西班牙语: ``` make build-data-de-es ``` 仅西班牙语 → 德语: ``` make build-data-es-de ``` 仅两个 PDB 字典: ``` make build-pdb-data ``` 检查元数据和一些条目而不生成数据库: ``` uv run tools/extract_msdict.py EnglishSpanish.pdb --samples 5 ``` 所有工具都是 PEP 723 脚本。默认不包含本地路径:输入和输出通过 CLI 传递,因此可以从任何检出中执行。每个脚本在其 docstring 和 `--help` 中都包含完整的示例。 本地运行: ``` make lock-fastapi make serve ``` ## 部署 FastAPI Cloud 会从 `pyproject.toml` 中检测应用程序: ``` [tool.fastapi] entrypoint = "dictionary.app:app" ``` 该项目包含 `uv.lock`,因此在部署时依赖项也会被锁定。 ## 版本化工件 该 repo 发布了四个准备就绪可供 Web 查询的 SQLite 数据库。 - `site/data/de-es-dictionary.sqlite` - `site/data/es-de-dictionary.sqlite` - `site/data/en-es-dictionary.sqlite` - `site/data/es-en-dictionary.sqlite` 用于提取和清理的中间 JSON 依然作为 pipeline 的一部分存在,但在 git 中会被忽略,并在需要时在本地重新生成。原始的 PDB 和 APK 是专有的本地输入,也被排除在 repo 之外。 ## 格式和关键词 该 repo 包含关于 **MSDict Palm PDB 逆向工程**、定长 BER 以及带有按位对齐延续的 **branched raw DEFLATE** 的可复现研究。它还记录了使用从 DLL 中恢复的 codebook 提取 UniLex `IDO/LEO` 格式的过程。 关键词:`MSDict`、`Palm PDB`、`PDB dictionary decompiler`、`BER parser`、`branched DEFLATE`、`UniLex`、`IDO`、`LEO`、`dictionary reverse engineering`。 ## 附加文档 - [格式的逆向工程](./docs/ingenieria-inversa.md)
标签:AV绕过, FastAPI, SQLite, 字典查询, 数据清洗, 数据解析, 逆向工具