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
19 changes: 14 additions & 5 deletions eyecite/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,25 @@ 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):
# Remove whitespace because citation strings sometimes lack
# internal spaces, e.g. "Pa.Super."
s = strip_punct(court["citation_string"]).replace(" ", "")

# Check for an exact match first
if s == court_str:
return str(court["id"])

# If no exact match, try to record a startswith match for possible
# eventual return
if s.startswith(court_str):
court_code = court["id"]
break

return court_code

return court_code

Expand Down
13 changes: 13 additions & 0 deletions tests/test_FindTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ 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'})]),
# Test with court string exact match
('Commonwealth v. Muniz, 164 A.3d 1189 (Pa. 2017)',
[case_citation(page='1189', reporter='A.3d', volume='164', year=2017,
metadata={'plaintiff': 'Commonwealth',
'defendant': 'Muniz',
'court': 'pa'})]),
# 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