Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix court string matching with whitespace #144

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
9 changes: 6 additions & 3 deletions eyecite/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ def get_court_by_paren(paren_string: str) -> Optional[str]:
needs to be handled after disambiguation has been completed.
"""
court_str = strip_punct(paren_string)
court_str = court_str.replace(" ", "")

court_code = None
if court_str:
# Map the string to a court, if possible.
for court in courts:
# Use startswith because citations are often missing final period,
# e.g. "2d Cir"
if court["citation_string"].startswith(court_str):
# Use startswith because citation strings are often missing final
# period, e.g. "2d Cir"
# Remove whitespace because citation strings sometimes lack
# internal spaces, e.g. "Pa.Super."
if court["citation_string"].replace(" ", "").startswith(court_str):
court_code = court["id"]
break

Expand Down
7 changes: 7 additions & 0 deletions tests/test_FindTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ def test_find_citations(self):
'defendant': 'test',
'court': 'ca4',
'pin_cite': '347-348'})]),
# Test with court string without space
('bob lissner v. test 1 U.S. 12, 347-348 (Pa.Super. 1982)',
[case_citation(page='12', year=1982,
metadata={'plaintiff': 'lissner',
'defendant': 'test',
'court': 'pasuperct',
'pin_cite': '347-348'})]),
# Parallel cite with parenthetical
('bob lissner v. test 1 U.S. 12, 347-348, 1 S. Ct. 2, 358 (4th Cir. 1982) (overruling foo)',
[case_citation(page='12', year=1982,
Expand Down
Loading