This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a fork of the freelawproject's eyecite that is being oxidized (ported from Python to Rust). Eyecite is a tool for extracting legal citations from text, recognizing various citation formats including full case citations, statutory citations, law journal citations, and reference citations (supra, id., etc.).
The Rust port maintains a similar structure to the Python codebase with the following key mappings:
Core Modules:
eyecite/__init__.py→src/lib.rs- Main library entry pointeyecite/find.py→src/find.rs- Citation extraction logiceyecite/models.py→src/find/models.rs- Citation data structureseyecite/tokenizers.py→src/tokenizers.rs- Text tokenizationeyecite/regexes.py→src/regexes.rs- Regular expressions for pattern matching
Key Components:
-
Tokenizers: Convert text into tokens (citations, stop words, sections, etc.)
- Python: Uses
pyahocorasickfor efficient string matching - Rust: Uses
daachorse(Double Array Aho-Corasick) for the same purpose
- Python: Uses
-
Citation Models:
- Python: Dataclasses with inheritance hierarchy (CitationBase → FullCaseCitation, etc.)
- Rust: Enum-based approach with
Citationenum containing variants for each citation type
-
Token Types:
- Python: Class hierarchy with Token base class
- Rust:
Tokenenum with variants (Word, Space, Citation, Section, Supra, Id, etc.)
# Run tests
uv run python -m unittest discover -s tests -p 'test_*.py'
# Install dependencies
pip install eyecite# Build
cargo build
# Run tests
cargo test
# Run clippy
cargo clippy
# Format code
cargo fmt
# Run with cargo-husky hooks (configured in Cargo.toml)
cargo test # Will trigger pre-commit/pre-push hooks- Text is processed through extractors that identify patterns (citations, stop words, etc.)
- Aho-Corasick algorithm efficiently finds all pattern matches
- Tokens are created with position information and metadata
- Overlapping tokens are merged when possible
- FullCase: Complete case citations with names and reporters
- ShortCase: Abbreviated references to previously cited cases
- Law: Statutory citations (e.g., "Mass. Gen. Laws ch. 1, § 2")
- Journal: Law review and journal citations
- Supra: References to citations above in the document
- Id: References to immediately preceding citations
- Unknown: Catch-all for unrecognized citation patterns
- reporters-db: Database of legal reporters (local path:
../reporters-db) - regex: Regular expression processing
- daachorse: Efficient string matching (Rust port of pyahocorasick)
The Rust implementation currently has:
- Basic tokenizer infrastructure (
Ahocorasicktokenizer) - Token models and citation models defined
- Regex patterns ported from Python
- Test infrastructure started
Still needs implementation:
- Complete
get_citations()function logic - Citation extraction functions (
_extract_full_citation,_extract_shortform_citation, etc.) - Helper functions for disambiguation and filtering
- Annotation and resolution functionality
- Clean text functionality
The Python test suite in tests/ directory provides comprehensive test cases that should be ported to Rust tests. Key test files:
test_FindTest.py- Citation extraction teststest_TokenizeTest.py- Tokenization teststest_RegexTest.py- Regex pattern teststest_ResolveTest.py- Citation resolution tests