|
42 | 42 | get_representative_parenthetical,
|
43 | 43 | )
|
44 | 44 | from cl.citations.match_citations import (
|
| 45 | + MULTIPLE_MATCHES_RESOURCE, |
45 | 46 | NO_MATCH_RESOURCE,
|
46 | 47 | do_resolve_citations,
|
47 | 48 | resolve_fullcase_citation,
|
@@ -512,6 +513,7 @@ def setUpTestData(cls) -> None:
|
512 | 513 | # Courts
|
513 | 514 | cls.court_scotus = CourtFactory(id="scotus")
|
514 | 515 | court_ca1 = CourtFactory(id="ca1")
|
| 516 | + cls.court_ca5 = CourtFactory(id="ca5") |
515 | 517 |
|
516 | 518 | # Citation 1
|
517 | 519 | cls.citation1 = CitationWithParentsFactory.create(
|
@@ -588,6 +590,83 @@ def setUpTestData(cls) -> None:
|
588 | 590 | ),
|
589 | 591 | ),
|
590 | 592 | )
|
| 593 | + |
| 594 | + cls.citation6 = CitationWithParentsFactory.create( |
| 595 | + volume="114", |
| 596 | + reporter="F.3d", |
| 597 | + page="1182", |
| 598 | + cluster=OpinionClusterFactoryWithChildrenAndParents( |
| 599 | + docket=DocketFactory(court=cls.court_ca5), |
| 600 | + case_name="Foo v. Bar", |
| 601 | + date_filed=date(1997, 4, 10), |
| 602 | + ), |
| 603 | + ) |
| 604 | + |
| 605 | + cls.citation7 = CitationWithParentsFactory.create( |
| 606 | + volume="114", |
| 607 | + reporter="F.3d", |
| 608 | + page="1182", |
| 609 | + cluster=OpinionClusterFactoryWithChildrenAndParents( |
| 610 | + docket=DocketFactory(court=cls.court_ca5), |
| 611 | + case_name="Lorem v. Ipsum", |
| 612 | + date_filed=date(1997, 4, 8), |
| 613 | + ), |
| 614 | + ) |
| 615 | + |
| 616 | + cls.citation8 = CitationWithParentsFactory.create( |
| 617 | + volume="1", |
| 618 | + reporter="U.S.", |
| 619 | + page="1", |
| 620 | + cluster=OpinionClusterFactoryWithChildrenAndParents( |
| 621 | + docket=DocketFactory(court=cls.court_ca5), |
| 622 | + case_name="John v. Doe", |
| 623 | + date_filed=date(1997, 4, 9), |
| 624 | + sub_opinions=RelatedFactory( |
| 625 | + OpinionWithChildrenFactory, |
| 626 | + factory_related_name="cluster", |
| 627 | + plain_text="""Lorem ipsum, 114 F.3d 1182""", |
| 628 | + ), |
| 629 | + ), |
| 630 | + ) |
| 631 | + |
| 632 | + cls.citation9 = CitationWithParentsFactory.create( |
| 633 | + volume="114", |
| 634 | + reporter="F.3d", |
| 635 | + page="1181", |
| 636 | + cluster=OpinionClusterFactoryWithChildrenAndParents( |
| 637 | + docket=DocketFactory(court=cls.court_ca5), |
| 638 | + case_name="Lorem v. Ipsum", |
| 639 | + date_filed=date(1997, 4, 8), |
| 640 | + ), |
| 641 | + ) |
| 642 | + |
| 643 | + cls.citation10 = CitationWithParentsFactory.create( |
| 644 | + volume="114", |
| 645 | + reporter="F.3d", |
| 646 | + page="1181", |
| 647 | + cluster=OpinionClusterFactoryWithChildrenAndParents( |
| 648 | + docket=DocketFactory(court=cls.court_ca5), |
| 649 | + case_name="Lorem v. Ipsum", |
| 650 | + date_filed=date(1997, 4, 8), |
| 651 | + ), |
| 652 | + ) |
| 653 | + |
| 654 | + cls.citation11 = CitationWithParentsFactory.create( |
| 655 | + volume="1", |
| 656 | + reporter="U.S.", |
| 657 | + page="1", |
| 658 | + cluster=OpinionClusterFactoryWithChildrenAndParents( |
| 659 | + docket=DocketFactory(court=cls.court_ca5), |
| 660 | + case_name="Foo v. Bar", |
| 661 | + date_filed=date(1997, 4, 9), |
| 662 | + sub_opinions=RelatedFactory( |
| 663 | + OpinionWithChildrenFactory, |
| 664 | + factory_related_name="cluster", |
| 665 | + plain_text="""Lorem ipsum, 114 F.3d 1182, consectetur adipiscing elit, 114 F.3d 1181""", |
| 666 | + ), |
| 667 | + ), |
| 668 | + ) |
| 669 | + |
591 | 670 | call_command(
|
592 | 671 | "cl_index_parent_and_child_docs",
|
593 | 672 | search_type=SEARCH_TYPES.OPINION,
|
@@ -906,6 +985,40 @@ def test_citation_matching_issue621(self) -> None:
|
906 | 985 | results = resolve_fullcase_citation(citation)
|
907 | 986 | self.assertEqual(NO_MATCH_RESOURCE, results)
|
908 | 987 |
|
| 988 | + def test_citation_multiple_matches(self) -> None: |
| 989 | + """Make sure that we can identify multiple matches for a single citation""" |
| 990 | + citation_str = "114 F.3d 1182" |
| 991 | + citation = get_citations(citation_str, tokenizer=HYPERSCAN_TOKENIZER)[ |
| 992 | + 0 |
| 993 | + ] |
| 994 | + results = resolve_fullcase_citation(citation) |
| 995 | + self.assertEqual(MULTIPLE_MATCHES_RESOURCE, results) |
| 996 | + |
| 997 | + # Verify if the annotated citation is correct |
| 998 | + opinion = self.citation8.cluster.sub_opinions.all().first() |
| 999 | + get_and_clean_opinion_text(opinion) |
| 1000 | + citations = get_citations( |
| 1001 | + opinion.cleaned_text, tokenizer=HYPERSCAN_TOKENIZER |
| 1002 | + ) |
| 1003 | + citation_resolutions = do_resolve_citations(citations, opinion) |
| 1004 | + new_html = create_cited_html(opinion, citation_resolutions) |
| 1005 | + |
| 1006 | + expected_citation_annotation = '<pre class="inline">Lorem ipsum, </pre><span class="citation multiple-matches"><a href="/c/F.3d/114/1182/">114 F.3d 1182</a></span><pre class="inline"></pre>' |
| 1007 | + self.assertIn(expected_citation_annotation, new_html, msg="Failed!!") |
| 1008 | + |
| 1009 | + # Verify if we can annotate multiple citations that can't be |
| 1010 | + # disambiguated |
| 1011 | + opinion = self.citation11.cluster.sub_opinions.all().first() |
| 1012 | + get_and_clean_opinion_text(opinion) |
| 1013 | + citations = get_citations( |
| 1014 | + opinion.cleaned_text, tokenizer=HYPERSCAN_TOKENIZER |
| 1015 | + ) |
| 1016 | + self.assertEqual(len(citations), 2) |
| 1017 | + citation_resolutions = do_resolve_citations(citations, opinion) |
| 1018 | + new_html = create_cited_html(opinion, citation_resolutions) |
| 1019 | + expected_citation_annotation = '<pre class="inline">Lorem ipsum, </pre><span class="citation multiple-matches"><a href="/c/F.3d/114/1182/">114 F.3d 1182</a></span><pre class="inline">, consectetur adipiscing elit, </pre><span class="citation multiple-matches"><a href="/c/F.3d/114/1181/">114 F.3d 1181</a></span><pre class="inline"></pre>' |
| 1020 | + self.assertIn(expected_citation_annotation, new_html) |
| 1021 | + |
909 | 1022 | def test_citation_increment(self) -> None:
|
910 | 1023 | """Make sure that found citations update the increment on the cited
|
911 | 1024 | opinion's citation count"""
|
|
0 commit comments