refactor: decompose helpers.py into domain-focused modules#303
Open
Wolfvin wants to merge 1 commit into
Open
Conversation
Split the 1146-line helpers.py into 6 focused modules following single-responsibility and domain-cohesion principles: - citation_metadata.py: extract and attach metadata to citations (add_post_citation, add_pre_citation, add_law_metadata, add_journal_metadata, get_year, clean_pin_cite, process_parenthetical) - case_name.py: find case names in plain text and HTML (find_case_name, find_case_name_in_html, plus all helper functions) - pin_cite.py: pin cite extraction (extract_pin_cite) - court_matching.py: court code lookup from citation strings (get_court_by_paren) - token_matching.py: token pattern matching utility (match_on_tokens, MAX_MATCH_CHARS) - citation_filter.py: citation filtering and disambiguation (filter_citations, disambiguate_reporters, overlapping_citations, joke_cite) helpers.py preserved as thin re-export module for backward compatibility. All existing imports (from eyecite.helpers import ...) continue to work. Verified with Regrets regression testing: - 11 clusters: all GREEN (find-case-citation, find-law-citation, find-journal-citation, find-supra-citation, find-id-citation, clean-html, clean-whitespace, clean-underscores, resolve-citations, get-year-validation, get-court-by-paren) - 2 chains: all match (full-citation-pipeline, short-cite-resolution) - Zero drift across 5 consecutive runs - Raw output identical to pre-refactor baseline (KEBENARAN 1) - All fingerprints match pre-refactor baseline (KEBENARAN 2) - Existing test suite: 20 non-hyperscan tests pass
|
|
Member
|
Thanks! Are you using eyecite for something or is this a drive-by PR from an AI or something? A few immediate thoughts:
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was refactored and why
The 1146-line
helpers.pywas a god module containing 10+ public functions spanning 5 distinct domains: citation metadata extraction, case name finding, pin cite extraction, court matching, token pattern matching, and citation filtering. This made the file difficult to navigate, maintain, and test in isolation.New module structure
citation_metadata.pyadd_post_citation,add_pre_citation,add_law_metadata,add_journal_metadata,get_yearcase_name.pyfind_case_name,find_case_name_in_htmlpin_cite.pyextract_pin_citecourt_matching.pyget_court_by_parentoken_matching.pymatch_on_tokenscitation_filter.pyfilter_citations,disambiguate_reportershelpers.pyis preserved as a thin re-export module for full backward compatibility. All existing imports (from eyecite.helpers import ...) continue to work unchanged.Refactoring principles applied
Verification Results
This refactoring was verified using the Regrets regression testing framework with dual-truth verification:
KEBENARAN 1 — Raw Output Comparison
All entry function outputs are identical before and after refactoring:
KEBENARAN 2 — Fingerprint Comparison
All behavioral fingerprints match:
Chain Hash Comparison
Additional Verification