Skip to content

Commit f1d9ef3

Browse files
committed
fix(helpers): Check with html and check without it if nothing is found
1 parent f28a5e2 commit f1d9ef3

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

eyecite/helpers.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -289,22 +289,25 @@ def find_case_name(citation: CaseCitation, document: Document, short=False):
289289
defendant = candidate_case_name
290290

291291
defendant = strip_stop_words(defendant)
292-
if short is False:
293-
citation.metadata.defendant = defendant.strip(", ").strip()
294-
else:
295-
citation.metadata.antecedent_guess = (
296-
defendant.strip(" ").strip(",").strip("(")
297-
)
298292

299-
offset = (
300-
len(
301-
"".join(
302-
str(w) for w in words[start_index : citation.index - 1]
293+
clean_def = defendant.strip(", ").strip()
294+
if clean_def:
295+
if short is False and clean_def:
296+
citation.metadata.defendant = clean_def
297+
else:
298+
citation.metadata.antecedent_guess = (
299+
defendant.strip(" ").strip(",").strip("(")
300+
)
301+
302+
offset = (
303+
len(
304+
"".join(
305+
str(w) for w in words[start_index : citation.index - 1]
306+
)
303307
)
308+
+ 1
304309
)
305-
+ 1
306-
)
307-
citation.full_span_start = citation.span()[0] - offset
310+
citation.full_span_start = citation.span()[0] - offset
308311

309312
if pre_cite_year:
310313
# found pre citation year, store it

eyecite/models.py

+3
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@ def add_metadata(self, document: "Document"):
538538
else:
539539
find_case_name(self, document)
540540

541+
if self.metadata.defendant == None:
542+
find_case_name(self, document)
543+
541544
add_pre_citation(self, document)
542545
self.guess_court()
543546
super().add_metadata(document)

tests/test_FindTest.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,9 @@ def test_markup_plaintiff_and_antecedent_guesses(self) -> None:
13381338
volume="242",
13391339
short=False,
13401340
metadata={
1341-
"antecedent_guess": "Foy",
1341+
"plaintiff": "Thrift Funds Canal, Inc.",
1342+
"defendant": "Foy",
1343+
"pin_cite": "257",
13421344
"year": "1970",
13431345
},
13441346
)
@@ -1356,8 +1358,6 @@ def test_markup_plaintiff_and_antecedent_guesses(self) -> None:
13561358
reporter="U.S.",
13571359
year=2004,
13581360
metadata={
1359-
"plaintiff": None,
1360-
"defendant": None,
13611361
"court": "scotus",
13621362
},
13631363
)
@@ -1565,6 +1565,22 @@ def test_markup_plaintiff_and_antecedent_guesses(self) -> None:
15651565
],
15661566
{"clean_steps": ["html", "all_whitespace"]},
15671567
),
1568+
# can we extract out the citation if its not wrapped in html but in html
1569+
("dentification. Stovall v. Denno, 388 U.S. 293, ",
1570+
[
1571+
case_citation(
1572+
page="293",
1573+
volume="388",
1574+
reporter="U.S.",
1575+
short=False,
1576+
metadata={
1577+
"plaintiff": "Stovall",
1578+
"defendant": "Denno",
1579+
},
1580+
),
1581+
],
1582+
{"clean_steps": ["html", "all_whitespace"]},
1583+
),
15681584
# can we remove see also
15691585
(
15701586
"""<em>see also Cass v. Stephens</em>,\r\n156 S.W.3d 38""",

0 commit comments

Comments
 (0)