Skip to content

fix: keep the pin cite on an Id. citation that refers to a section - #343

Open
aseem-ai wants to merge 1 commit into
freelawproject:mainfrom
aseem-ai:fix/id-cite-section-pin-cite
Open

fix: keep the pin cite on an Id. citation that refers to a section#343
aseem-ai wants to merge 1 commit into
freelawproject:mainfrom
aseem-ai:fix/id-cite-section-pin-cite

Conversation

@aseem-ai

@aseem-ai aseem-ai commented Sep 1, 2026

Copy link
Copy Markdown

Fixes

Refs #299 — deliberately not Fixes, see the note at the end.

Summary

Id. § 1985 lost its pin cite, and the section mark was reported as a
separate UnknownCitation. A plain Id. at 5 was always fine, so this only
hit Id. cites pointing at a section.

The cause is the one named in the issue: the mark is its own token, and
match_on_tokens() stops at any non-string token when strings_only=True,
so the scan never saw past it. This is fix option 2 from the issue.

Two changes in helpers.py:

  • match_on_tokens() reads through a SectionToken instead of stopping at
    it. The mark is a marker, not a citation, and its text is already pin cite
    vocabulary — PIN_CITE_TOKEN_REGEX has listed §{1,2} as a label all
    along, it just never got to see one.
  • filter_citations() drops an UnknownCitation that overlaps the citation
    before it. Once the mark is part of the pin cite it is not a citation of
    its own, and this also silences the "Unknown overlap case" warning the
    pairing was logging. A mark inside a parenthetical is still kept, by the
    rule directly above.

Tests

python -m unittest discover -s tests -p 'test_*.py' → 56 tests, OK.

New test test_id_citation_with_section_pin_cite fails on main (the stray
UnknownCitation is the extra element) and passes here. It covers
42 U.S.C. § 1983. Id. § 1985., Id. §§ 5-7., the glued Id. §5. form,
Id. § 5, 7., a guard that Id. at 5 still works, and a guard that a mark
no citation absorbs is still reported on its own.

match_on_tokens() is shared, so I read its six call sites and diffed
behaviour on the neighbours, including the backward scans for party names
and supra antecedents: § 3.1 (2d ed. 1977), Strawberry Hill, 725 S.W.2d at 176, 1 U.S. 1 (citing § 5), § 5. Adarand, supra, at 240, lorem ipsum see §99 of the U.S. code., Fla. Stat. § 120.68 (2007), Mass. Gen. Laws ch. 1, §§ 2-3. All byte-identical before and after. Extraction over
tests/assets/opinion.txt is unchanged at 170 citations.

Why this is Refs and not Fixes

The example in the issue, Id. § 394-ccc(2)-(3), still does not produce a
pin cite after this change — but for an unrelated reason. 394-ccc is a
section number with letters in it, which is #146, and #331 is open for it.
Widening PIN_CITE_TOKEN_REGEX to swallow that shape would put a statute
section grammar inside the pin cite every case citation uses (at 5-ccc(2)
would start matching) and would overlap #331, so I have left it alone.
Say the word if you would rather this close #299 and track the lettered
form solely on #146.

AI Disclosure

  • No AI tools were used to create the content of this PR.
  • Parts of this PR were created with the help of an AI tool, and I have carefully reviewed all of its content and take full responsibility for it.

The section mark is tokenized separately, and match_on_tokens stopped at
any non-string token, so "Id. § 1985" lost its pin cite and left the mark
behind as its own UnknownCitation. The mark's text is ordinary pin cite
vocabulary, so scanning now reads through it, and a mark absorbed into the
preceding citation is no longer reported twice.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Id. citation doesn't capture pin cite with § section references

1 participant