Skip to content

Commit

Permalink
feat(eyecite): Fix california style
Browse files Browse the repository at this point in the history
These complex styles were failing with square brackets
and years before the citation.  Also addressed
an issue with extra running too long and
simplified the check for parallel citations
  • Loading branch information
flooie committed Mar 6, 2025
1 parent e99ccdd commit 9e576fe
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
9 changes: 7 additions & 2 deletions eyecite/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,13 @@ def get_citations(
citation = _extract_shortform_citation(words, i)
else:
citation = _extract_full_citation(words, i)
if citations and isinstance(citation, FullCitation):
citation.is_parallel_citation(citations[-1])
if (
citations
and isinstance(citation, FullCaseCitation)
and isinstance(citations[-1], FullCaseCitation)
):
pre = cast(FullCaseCitation, citations[-1]) # type: ignore
citation.is_parallel_citation(pre)

# Check for reference citations that follow a full citation
# Using the plaintiff or defendant
Expand Down
9 changes: 8 additions & 1 deletion eyecite/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Tokens,
)
from eyecite.regexes import (
DEFENDNAT_YEAR_REGEX,
POST_FULL_CITATION_REGEX,
POST_JOURNAL_CITATION_REGEX,
POST_LAW_CITATION_REGEX,
Expand Down Expand Up @@ -164,8 +165,14 @@ def add_defendant(citation: CaseCitation, words: Tokens) -> None:
citation.full_span_start = citation.span()[0] - offset
defendant = "".join(
str(w) for w in words[start_index : citation.index]
).strip(", ()")
).strip(", (")
if defendant.strip():
# Check if year follows defendant before citation
match = re.search(DEFENDNAT_YEAR_REGEX, defendant)
if match:
defendant, year = match.groups()
citation.year = int(year)
citation.metadata.year = year
citation.metadata.defendant = defendant


Expand Down
13 changes: 6 additions & 7 deletions eyecite/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Hashable,
List,
Optional,
Self,
Sequence,
Tuple,
Union,
Expand Down Expand Up @@ -359,25 +360,23 @@ class FullCitation(ResourceCitation):
"""Abstract base class indicating that a citation fully identifies a
resource."""

def is_parallel_citation(self, preceding: CitationBase):
def is_parallel_citation(self, preceding: Self):
"""Check if preceding citation is parallel
Args:
preceding (): The previous citation found
Returns: None
"""
is_parallel = (
self.full_span_start == preceding.full_span_start
and self.full_span_end == preceding.full_span_end
and isinstance(preceding, FullCaseCitation)
)
if is_parallel:
if self.full_span_start == preceding.full_span_start:
# if parallel get plaintiff/defendant data from
# the earlier citation, since it won't be on the
# parallel one.
self.metadata.defendant = preceding.metadata.defendant
self.metadata.plaintiff = preceding.metadata.plaintiff
# California style may have a year prior to citation; merge as well
self.metadata.year = preceding.metadata.year
self.year = preceding.year


@dataclass(eq=False, unsafe_hash=False, repr=False)
Expand Down
5 changes: 4 additions & 1 deletion eyecite/regexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def short_cite_re(regex):
# pin cite with comma and extra:
{PIN_CITE_REGEX}?
,?\ ?
(?P<extra>[^(]*)
(?P<extra>[^(;]*)
)
# content within year paren:
[\(\[](?:
Expand Down Expand Up @@ -314,3 +314,6 @@ def short_cite_re(regex):
\ ?
{PARENTHETICAL_REGEX}
"""

# A simple regex to check if year precedes citation
DEFENDNAT_YEAR_REGEX = r"(?P<defendant>.*)\s\((?P<year>\d{4})\)$"
24 changes: 24 additions & 0 deletions tests/test_FindTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,31 @@ def test_find_citations(self):
metadata={'plaintiff': 'Commonwealth', 'defendant': 'Muniz',
'court': 'pa'})]),
('Foo v. Bar, 1 F.Supp. 1 (SC 1967)', [case_citation(volume='1', reporter='F.Supp.', year=1967, page='1', metadata={'plaintiff': 'Foo', 'defendant': 'Bar', 'court': 'sc'})]),
('trial court’s ruling. (See In re K.F. (2009) 1 U.S. 1 ', [
case_citation(
year=2009, metadata={'defendant': 'K.F.', "year": "2009"})]
),
('(See In re K.F. (2009) 1 U.S. 1, 4 [92 Cal.Rptr.3d 784]; Yield Dynamics, Inc. v. TEA Systems Corp. (2007) 154 Cal.App.4th 547, 558 [66 Cal.Rptr.3d 1].)”', [
case_citation(
year=2009,
metadata={'defendant': 'K.F.', "year": "2009", 'pin_cite': '4'}
),
case_citation(
year=2009, volume='92', reporter='Cal.Rptr.3d', page='784',
metadata={'defendant': 'K.F.', "year": "2009"}
),
case_citation(
year=2007, volume='154', reporter='Cal.App.4th', page='547',
metadata={'plaintiff': 'Inc.', 'defendant': 'TEA Systems Corp.', "year": "2007", "pin_cite": "558"}
),
case_citation(
year=2007, volume='66', reporter='Cal.Rptr.3d', page='1',
metadata={'plaintiff': 'Inc.', 'defendant': 'TEA Systems Corp.', "year": "2007"}
),
])
)

# d this conclusion is supported by People v. Beach (1983) 147 Cal.App.3d 612 [195 Cal.Rptr. 381] (relocation away from home community as
# fmt: on
self.run_test_pairs(test_pairs, "Citation extraction")

Expand Down

0 comments on commit 9e576fe

Please sign in to comment.