fix(tokenizers): relax whitespace at full-cite template boundaries - #339
fix(tokenizers): relax whitespace at full-cite template boundaries#339jaysoma wants to merge 2 commits into
Conversation
Glued citations (846F.2d746, 410U.S.113) extract as nothing because the full-cite template requires exactly one literal space at the volume-reporter and reporter-page boundaries. Relax both to \s*, extending the freelawproject#305 within-reporter relaxation, and trim the trailing \s* from _relax_ws output so the reporter group cannot capture boundary whitespace once the mandatory template space is gone. Fixes freelawproject#338
The nonalphanum boundary wrappers consume one character on each side of a match, so under finditer semantics a separator consumed as one citation's trailing boundary was unavailable as the next citation's leading boundary, and the second of two adjacent citations was silently skipped: "347 U.S. 483,349 U.S. 294" lost "349 U.S. 294". The swallow predates the glued-citation relaxation and exists on main for unglued text; glued OCR text simply produces more adjacent pairs. TokenExtractor.get_matches now resumes scanning at the end of the token content (group 1) rather than the end of the boundary-consuming match, so the separator stays available. HyperscanTokenizer reports overlapping matches and never had this blind spot; this aligns the pure-Python tokenizers with it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
I ran this patch against real-world data to validate it beyond the unit tests: Recovery: 7,416 windows in 4,141 documents gained citations that main Regressions: the diff initially showed 14 windows where the branch lost a
Over-capture, documented honestly: when OCR glues a preceding number Also observed: the overlap filter now sees pairings it has no rule for Replay harness and full per-window diffs are available if useful. |
Fixes
Fixes: #338
Summary
Glued citations (
846F.2d746) currently extract as nothing: the full-citetemplate requires exactly one literal space at the volume-reporter and
reporter-page boundaries. This extends #305's whitespace relaxation to those
two boundaries:
full_citetemplate becomesr"$volume\s*$reporter,?\s*$page"_relax_wsnow trims its trailing\s*so the reporter group cannotcapture boundary whitespace (
reporter='U.S. ') once the mandatorytemplate space is gone.
Measured on the 7,740 glued-citation opinions from the bulk scan (details in
#338): 7,737 recovered citations across 4,141 documents, no losses of
previously-extracted citations, existing test suite unchanged. New regression
tests cover glued full/short cites, composition with #305, group cleanliness,
and a non-citation negative.
AI Disclosure