示例#1
0
 def test_repeating_read_holdings_has_same_result(self, make_analysis):
     raw = make_analysis["minimal"]
     holdings = readers.read_holdings_with_anchors(raw).holdings
     holdings_again = readers.read_holdings_with_anchors(raw).holdings
     assert all(
         left.holding.means(right.holding)
         for left, right in zip(holdings, holdings_again))
示例#2
0
    def test_posit_holding_with_selector(self, make_analysis, make_opinion):

        anchored_holdings = readers.read_holdings_with_anchors(
            make_analysis["minimal"])

        brad = make_opinion["brad_majority"]
        reading = OpinionReading(opinion_type="majority",
                                 opinion_author=brad.author)
        reading.posit(anchored_holdings.holdings)
        assert reading.holding_anchors[0].quotes[
            0].exact == "open fields or grounds"
示例#3
0
 def test_read_holding_with_no_anchor(self, make_analysis):
     raw_analysis = make_analysis["no anchors"]
     reading = OpinionReading()
     anchored_holdings = readers.read_holdings_with_anchors(raw_analysis)
     reading.posit(
         holdings=anchored_holdings.holdings,
         named_anchors=anchored_holdings.named_anchors,
         enactment_anchors=anchored_holdings.enactment_anchors,
     )
     assert not reading.holding_anchors[0].positions
     assert not reading.holding_anchors[0].quotes
示例#4
0
    def test_read_holdings_and_then_get_anchors(self, make_response):
        """
        Test whether read_holdings mutates raw_holding and makes it
        impossible to get text anchors.
        """
        mock_client = FakeClient(responses=make_response)
        raw_holdings = load_holdings("holding_oracle.yaml")
        loaded = readers.read_holdings_with_anchors(raw_holdings,
                                                    client=mock_client)

        assert isinstance(loaded.holdings[0], HoldingWithAnchors)
        assert isinstance(loaded.named_anchors[1].anchors.quotes[0],
                          TextQuoteSelector)
示例#5
0
    def test_selectors_not_duplicated(self, make_decision, raw_holding):
        """
        Test that the factors attribute for this Opinion contains
        one instance of the Fact "Mark stole a watch", but that both
        of the different text anchors for that Fact are attached to it.
        """
        watch = raw_holding["stolen watch"]
        holdings = readers.read_holdings_with_anchors([watch])
        cardenas = OpinionReading(anchored_holdings=holdings)

        assert any(selector.exact == "Mark stole the watch" for selector in
                   cardenas.anchored_holdings.holdings[0].anchors.quotes)
        assert any(selector.exact == "a watch was stolen by Mark" for selector
                   in cardenas.anchored_holdings.holdings[0].anchors.quotes)
        assert len(cardenas.anchored_holdings.holdings[0].anchors.quotes) == 2
示例#6
0
def read_anchored_holdings_from_file(
    filename: Optional[str] = None,
    directory: Optional[pathlib.Path] = None,
    filepath: Optional[pathlib.Path] = None,
    client: Optional[Client] = None,
) -> AnchoredHoldings:
    r"""
    Read holdings from file, with Opinion text anchors for holdings and factors.

    This function can accept a file containing :class:`.authorityspoke.holdings.Holding`
    summaries in the YAML format
    that may contain abbreviations and expandable named entities.

    In the example below, a :class:`~authorityspoke.io.fake_enactments.FakeClient` is used to
    add fields to :class:`~legislice.enactments.Enactment`\s in the Holding
    objects, to avoid using the network or making API calls. The
    real :class:`~authorityspoke.io.downloads.LegisClient` class
    would also have worked (with an appropriate API key).

        >>> from authorityspoke.io.fake_enactments import FakeClient
        >>> fake_client = FakeClient.from_file("usc.json")
        >>> filepath = filepaths.make_filepath(filename="holding_mazza_alaluf.yaml")
        >>> with open(filepath, "r") as f:
        ...     yaml.safe_load(f)
        [{'inputs': [{'type': 'fact', 'content': "{Mazza-Alaluf} used Mazza-Alaluf's business {Turismo Costa Brava} to commit the New York offense of engaging in the business of receiving money for transmission or transmitting the same, without a license therefor"}], 'outputs': [{'type': 'fact', 'content': 'Mazza-Alaluf operated Turismo Costa Brava without an appropriate money transmitting license in a State where such operation was punishable as a misdemeanor or a felony under State law', 'anchors': {'quotes': [{'exact': "we conclude that sufficient evidence supports Mazza-Alaluf's convictions under 18 U.S.C. § 1960(b)(1)(A) for conspiring to operate and operating a money transmitting business without appropriate state licenses."}]}, 'name': 'operated without license'}], 'enactments': [{'name': 'state money transmitting license provision', 'enactment': {'node': '/us/usc/t18/s1960/b/1'}, 'anchors': {'quotes': ['state money transmitting licenses, see |18 U.S.C. § 1960(b)(1)(A)|']}, 'selection': {'quotes': [{'exact': 'is operated without an appropriate money transmitting license in a State where such operation is punishable as a misdemeanor or a felony under State law, whether or not the defendant knew that the operation was required to be licensed or that the operation was so punishable'}]}}], 'universal': True}, {'inputs': ['operated without license', {'type': 'fact', 'content': 'Mazza-Alaluf operated Turismo Costa Brava as a business', 'anchors': {'quotes': 'Mazza-Alaluf does not contest that he owned and managed Turismo'}}, {'type': 'fact', 'content': 'Turismo Costa Brava was a money transmitting business', 'anchors': {'quotes': 'record evidence that Turismo conducted substantial money transmitting business in the three states'}}], 'despite': [{'type': 'fact', 'content': 'Turismo Costa Brava was a domestic financial institution', 'truth': False, 'anchors': {'quotes': 'without respect to whether or not Turismo was a "domestic financial institution"'}}], 'outputs': [{'type': 'fact', 'content': 'Mazza-Alaluf committed the offense of conducting a money transmitting business without a license required by state law', 'anchors': {'quotes': 'a crime to operate a money transmitting business without appropriate state licenses,'}}], 'enactments': ['state money transmitting license provision'], 'enactments_despite': [{'enactment': {'node': '/us/usc/t31/s5312/b/1'}, 'anchors': {'quotes': ['§ 5312(b)(1) (defining "domestic financial institution")']}}], 'anchors': {'quotes': [{'prefix': 'Accordingly, we conclude that the', 'suffix': 'In any event'}]}, 'universal': True, 'mandatory': True}]
        >>> result = read_anchored_holdings_from_file(filepath=filepath, client=fake_client)
        >>> selection = result.get_term_anchors("the fact it was false that <Turismo Costa Brava> was a domestic financial institution")
        >>> selection.quotes[0].exact
        'without respect to whether or not Turismo was a "domestic financial institution"'
        >>> print(result.holdings[0].holding.outputs[0])
        the fact that <Mazza-Alaluf> operated <Turismo Costa Brava> without an appropriate money transmitting license in a State where such operation was punishable as a misdemeanor or a felony under State law
    """
    raw_holdings = load_holdings(
        filename=filename, directory=directory, filepath=filepath
    )
    return readers.read_holdings_with_anchors(raw_holdings, client=client)
示例#7
0
    def test_import_enactments_and_anchors(self, make_opinion_with_holding,
                                           make_response):
        """
        Testing issue that caused enactment expansion to fail only when
        text anchors were loaded.
        """
        raw_holdings = [
            {
                "inputs": {
                    "type": "fact",
                    "content": "{Rural's telephone directory} was a fact",
                    "name": "Rural's telephone directory was a fact",
                    "anchors": {
                        "quotes": [
                            {
                                "exact": "facts",
                                "prefix": "The first is that"
                            },
                            {
                                "exact": "as to facts",
                                "prefix": "No one may claim originality",
                            },
                            {
                                "exact": "facts",
                                "prefix": "no one may copyright"
                            },
                        ]
                    },
                },
                "outputs": {
                    "type": "fact",
                    "content": "Rural's telephone directory was copyrightable",
                    "truth": False,
                    "anchors": {
                        "quotes": [
                            {
                                "exact": "copyrightable",
                                "prefix": "first is that facts are not",
                            },
                            "The sine qua non of|copyright|",
                            {
                                "exact": "no one may copyright",
                                "suffix": "facts"
                            },
                        ]
                    },
                },
                "enactments": [
                    {
                        "name": "securing for authors",
                        "enactment": {
                            "node":
                            "/us/const/article/I/8/8",
                            "exact":
                            ("To promote the Progress of Science and useful Arts, "
                             "by securing for limited Times to Authors"),
                        },
                    },
                    {
                        "name": "right to writings",
                        "enactment": {
                            "node":
                            "/us/const/article/I/8/8",
                            "exact":
                            "the exclusive Right to their respective Writings",
                        },
                    },
                ],
                "mandatory":
                True,
                "universal":
                True,
            },
            {
                "outputs": {
                    "type": "fact",
                    "content": "Rural's telephone directory was copyrightable",
                },
                "enactments": ["securing for authors", "right to writings"],
                "mandatory": True,
                "anchors": {
                    "quotes": ["compilations of facts|generally are|"]
                },
            },
        ]
        mock_client = FakeClient(responses=make_response)
        f_anchored_holdings = readers.read_holdings_with_anchors(
            record=raw_holdings, client=mock_client)

        feist = make_opinion_with_holding["feist_majority"]
        feist.clear_holdings()
        feist.posit(
            f_anchored_holdings.holdings,
            named_anchors=f_anchored_holdings.named_anchors,
            enactment_anchors=f_anchored_holdings.enactment_anchors,
        )
        assert feist.holdings[0].enactments[
            0].node == "/us/const/article/I/8/8"
        assert feist.holdings[1].enactments[
            0].node == "/us/const/article/I/8/8"