diff --git a/eyecite/helpers.py b/eyecite/helpers.py index 4380be6..ea50159 100644 --- a/eyecite/helpers.py +++ b/eyecite/helpers.py @@ -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 diff --git a/tests/test_FindTest.py b/tests/test_FindTest.py index 47339f1..de37c54 100644 --- a/tests/test_FindTest.py +++ b/tests/test_FindTest.py @@ -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,