Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Features:
-

Changes:
-
- Handle sequential citations (in close proximity) better

Fixes:
- Modifies rendering of AhocorasickTokenizer parameter in API docs II
Expand Down
18 changes: 12 additions & 6 deletions eyecite/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def _scan_for_case_boundaries(
word_str.endswith(";")
or word_str.endswith("”")
or word_str.endswith('"')
or (word_str.endswith("),") and state["v_token"] is not None)
):
state["start_index"] = index + 2
state["candidate_case_name"] = _extract_text(
Expand All @@ -227,7 +228,10 @@ def _scan_for_case_boundaries(

# Handle year before citation
if re.match(r"\(\d{4}\)", word_str):
state["title_starting_index"] = index - 1
# Don't override title_starting_index if we already found a v. token
# and have a case name set, as this would corrupt the extraction
if state["v_token"] is None or not state["candidate_case_name"]:
state["title_starting_index"] = index - 1
state["pre_cite_year"] = word_str[1:5]
continue

Expand Down Expand Up @@ -264,11 +268,13 @@ def _scan_for_case_boundaries(

# Handle "v" token - store it but don't break yet
if _is_v_token(word):
state["v_token"] = word
state["start_index"] = index - 2
state["candidate_case_name"] = _extract_text(
words, state["start_index"], state["title_starting_index"]
)
# Don't overwrite a case name we already found from a more recent v. token
if state["v_token"] is None:
state["v_token"] = word
state["start_index"] = index - 2
state["candidate_case_name"] = _extract_text(
words, state["start_index"], state["title_starting_index"]
)
continue

# Break on likely new sentence after "v" token
Expand Down
8 changes: 7 additions & 1 deletion tests/test_FindTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,13 @@ def test_find_citations(self):
# Fix for index error when searching for case name
("<p>State v. Luna-Benitez (S53965). Alternative writ issued, dismissed, 342 Or 255</p>",
[case_citation(volume="342", reporter="Or", page="255")],
{'clean_steps': ['html', 'inline_whitespace']})
{'clean_steps': ['html', 'inline_whitespace']}),
# Sequential full case citations.
("West v. Atkins, 487 U.S. 42, 54-58 (1988), Polk Cty. v. Dodson, 454 U.S. 312, 325-26 (1981), and Monell v. Department of Soc. Servs., 436 U.S. 658, 694 (1978)",
[case_citation(volume="487", reporter="U.S.", page="42", metadata={"plaintiff": "West", "defendant": "Atkins", "year": "1988", "pin_cite": "54-58"}),
case_citation(volume="454", reporter="U.S.", page="312", metadata={"plaintiff": "Polk Cty.", "defendant": "Dodson", "year": "1981", "pin_cite": "325-26"}),
case_citation(volume="436", reporter="U.S.", page="658", metadata={"plaintiff": "Monell", "defendant": "Department of Soc. Servs.", "year": "1978", "pin_cite": "694"}),
]),
)

# fmt: on
Expand Down
Loading