Local pipeline to:
- Extract English legal/regulatory terms from
.docx/.pdfstudy pages (via an OpenAI-compatible LLM such as LM Studio), or consume a plain bullet/line list. - Look up definitions in Black's Law Dictionary PDF volumes using a BM25 + cascade matcher (
EXACT→NORMALIZED→COMPONENT). - Optionally map terms to Russian wording + retrieve snippets from your own
.txtcorpus of Russian legislation (mini-RAG).
python -m venv .venv
source .venv/bin/activate
pip install -e .
cp .env.example .env
# Edit .env for LM Studio: LLM_BASE_URL / LLM_MODELPlace dictionary PDFs in any folder. You can point to that folder with --dictionary-dir.
See docs/MAC_SETUP.md.
# 1) Extract terms from a textbook (needs running LLM server)
legal-agent run-extract -i ./18-33.docx --out-json terms.json
# 2) Lookup a fixed list against Black's PDFs
legal-agent run-lookup \
--terms ./data/sample_terms.txt \
--dictionary-dir . \
--dictionary-glob '*.pdf' \
--output ./output
# 3) Full graph (uses --terms if provided, otherwise LLM extraction from --input)
legal-agent run-all -i ./18-33.docx --dictionary-dir . --dictionary-glob '*.pdf' --output ./output
# Optional RU mini-RAG (corpus is your local .txt files)
legal-agent run-lookup \
--terms ./data/sample_terms.txt \
--dictionary-dir . \
--dictionary-glob '*.pdf' \
--output ./output_ru \
--enable-ru \
--ru-corpus ./data/sample_ru_corpus.txt
# 4) Super-simple mode (for non-technical users)
legal-agent run-simple \
--terms ./data/sample_terms.txt \
--dictionary-dir ./dictionaries \
--output ./output_simple- Put dictionary PDF files in one of these places:
./dictionaries/(inside the project folder), or../dictionaries/(same parent folder as the project — handy next to a copied app folder), or- macOS + DMG: a folder named
dictionariesnext to the.dmgfile` on disk (same directory as the disk image).
- Put your terms (one per line) into one of:
terms.txtnext to the.dmgon Mac (recommended for DMG), orwords.txt/sample_terms.txt/my_terms.txtthere,- or
./data/sample_terms.txtinside the project, - or
../terms.txtnext to the project folder.
- Run (auto-detects terms + dictionaries; optional explicit paths):
bash ./run_simple.shExplicit dictionary/output (still supported):
bash ./run_simple.sh ./data/sample_terms.txt ./dictionaries ./output_simpleResult file: ./output_simple/results_human.xlsx inside the project when writable.
If you run from a read-only DMG, the Excel report is written **next to the .dmg file** (same folder as terms.txt/dictionaries/): output_simple/results_human.xlsxthere. Only if that folder is not writable does it fall back to~/Library/Application Support/LegalTermsAgent/output_simple/`.
Notes:
- You do not need to create
.venvmanually. The script creates it automatically on first run (under the project or under~/Library/Application Support/LegalTermsAgenton read-only media). - If the executable bit is missing after copying project files, use
bash ./run_simple.sh ...(works withoutchmod +x).
Outputs:
results.json— structuredTermWithRuMappingrecordsresults.xlsx— flattened columns for reviewresults_human.xlsx— simplified table: word / status / confidence / definitionrun_meta.json— which inputs/dictionaries were used
First PDF index build can take several minutes for large volumes. Reuse cache:
legal-agent run-lookup --terms data/sample_terms.txt --index-cache .cache/blacks_index.pklSkip cache with --no-index-cache.
LangGraph nodes live in app/graphs/legal_terms_graph.py:
load_input → extract_terms → normalize_terms → lookup_definitions → validate_output → optional_ru → export_report
See docs/EVALUATION.md.
- PDF retrieval uses page/chunk windows; quotes may start mid-entry if a dictionary page is split.
FOUND_COMPONENTmatches can be noisy for very generic words—reviewmanual_reviewrows.- LM Studio must expose an OpenAI-compatible
/v1/chat/completionsendpoint for extraction/RU translation steps.