diff --git a/eyecite/helpers.py b/eyecite/helpers.py index 662f71a..774c360 100644 --- a/eyecite/helpers.py +++ b/eyecite/helpers.py @@ -48,11 +48,15 @@ def get_court_by_paren(paren_string: str) -> Optional[str]: if court_str: # Map the string to a court, if possible. for court in courts: - # 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): + # Also check for equality without the last character because + # citation strings are often missing final period, e.g. "2d Cir" + citation_string = court["citation_string"].replace(" ", "") + if ( + citation_string == court_str + or citation_string[:-1] == court_str + ): court_code = court["id"] break diff --git a/tests/test_FindTest.py b/tests/test_FindTest.py index f84b47c..348489c 100644 --- a/tests/test_FindTest.py +++ b/tests/test_FindTest.py @@ -632,6 +632,42 @@ def test_date_in_editions(self): % (edition[0], year, expected, date_in_reporter), ) + def test_court_slug_extraction(self): + """Can we map court parentheticals to the proper slugs from courts-db?""" + # fmt: off + test_pairs = [ + ("Leday v. State, 983 S.W.2d 713, 718 (Tex. Crim. App. 1998)", "texcrimapp"), + ("Worsdale v. City of Killeen, 578 S.W.3d 57, 69-72 (Tex. 2019)", "tex"), + ("United States v. Chatman, 584 F.2d 1358 (4th Cir. 1978)", "ca4"), + ("Brown v. Wainwright, 665 F.2d 607 (5th Cir. 1982)", "ca5"), + ("United States v. Ehrlichman, 546 F.2d 910, 929 (D.C. Cir. 1976)", "cadc"), + ("Commonwealth v. Griffin, 24 A.3d 1037, 1041 (Pa. Super. Ct. 2011)", "pasuperct"), + ("Commonwealth v. Shaffer, 209 A.3d 957, 969 (Pa. 2019)", "pa"), + ("Sixty-Eight Liquors, Inc. v. Colvin , 118 S.W.3d 171 (Ky. 2003)", "ky"), + ("Steffan v. Smyzer by and through Rankins , 540 S.W.3d 387, 392 (Ky. Ct. App. 2018)", "kyctapp"), + ("Louisiana State Bar Ass\u2019n v. Reis, 513 So. 2d 1173 (La. 1987)", "la"), + ("Sursely v. Peake, 551 F.3d 1351, 1357 (Fed. Cir. 2009)", "cafc"), + ("Vieland v. First Fed. Sav. Bank (In re Vieland), 41 B.R. 134, 138 (Bankr. N.D. Ohio 1984)", "ohnb"), + ("Bowman v. Bond (In re Bowman), 253 B.R. 233, 237 (8th Cir. BAP 2000)", "bap8"), + ("United States v. H & R Block, Inc., 833 F. Supp. 2d 36, 49 (D.D.C. 2011)", "dcd"), + ("Elhady v. Piehota , 303 F. Supp. 3d 453, 462 (E.D. Va. 2017)", "vaed"), + ("See Schneider v. Phila. Gas Works, 223 F. Supp. 3d 308, 316-17 (E.D. Pa. 2016)", "paed"), + ("Wisniewski v. Johns-Manville Corp., 812 F.2d 81, 83 (3rd Cir. 1987).", "ca3"), + ("Veasey v. Perry, 71 F. Supp. 3d 627, 694 (S.D. Tex. 2014)", "txsd"), + ("Animal Legal Defense Fund v. Reynolds, 353 F.Supp.3d 812, 820 (S.D. Iowa 2019)", "iasd"), + ("United States v. Shelton, 336 F. Supp. 3d 940 (S.D.N.Y. 2018)", "nysd"), + ("See Pool v. Superior Court, 677 P.2d 261, 271-72 (Ariz. 1984)", "ariz"), + ("State v. Breit, 930 P.2d 792, 803 (N.M. 1996)", "nm"), + ("State Kennedy, 666 P.2d 1316, 1326 (Or. 1983)", "or"), + ("State v. Michael J., 875 A.2d 510, 534-35 (Conn. 2005)", "conn"), + ("Commonwealth v. Muniz, 164 A.3d 1189 (Pa. 2017)", "pa"), + ("Foo v. Bar, 123 F.3d. 456 (8th Cir 2000)", "ca8"), # missing period after Cir + ] + # fmt: on + for citation_string, court_slug in test_pairs: + citation = get_citations(citation_string) + self.assertEqual(citation[0].metadata.court, court_slug) + def test_disambiguate_citations(self): # fmt: off test_pairs = [