From 9c6b3871a585cbbe99352c2e50fec45e64142416 Mon Sep 17 00:00:00 2001 From: Kevin Ramirez Date: Fri, 6 Dec 2024 20:00:30 -0600 Subject: [PATCH] fix(get_court_by_paren): try with an exact match add test --- eyecite/helpers.py | 4 ++++ tests/test_FindTest.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/eyecite/helpers.py b/eyecite/helpers.py index 662f71a..fd36f26 100644 --- a/eyecite/helpers.py +++ b/eyecite/helpers.py @@ -46,6 +46,10 @@ def get_court_by_paren(paren_string: str) -> Optional[str]: court_code = None if court_str: + # Try with an exact match, e.g. Pa. + exact_match = next((court["id"] for court in courts if strip_punct(court["citation_string"].replace(" ", "")) == court_str), None) + if exact_match: + return exact_match # Map the string to a court, if possible. for court in courts: # Use startswith because citation strings are often missing final diff --git a/tests/test_FindTest.py b/tests/test_FindTest.py index f84b47c..de37c54 100644 --- a/tests/test_FindTest.py +++ b/tests/test_FindTest.py @@ -128,6 +128,12 @@ def test_find_citations(self): '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,