def read_holdings_with_anchors(record: List[RawHolding], regime: Optional[Regime] = None, many: bool = True) -> AnchoredHoldings: r""" Load a list of :class:`Holding`\s from JSON, with text links. :param record: a list of dicts representing holdings, in the JSON input format :param regime: A collection of :class:`.Jurisdiction`\s and the :class:`.Code`\s that have been enacted in each. Used for constructing :class:`.Enactment`\s referenced by :class:`.Holding`\s. :param many: a bool indicating whether to use the "many" form of the Marshmallow schema (whether there are multiple Holdings) :returns: a namedtuple listing :class:`.Holding` objects with a list matching :class:`.Holding`\s to selectors and an index matching :class:`.Factor`\s to selectors. """ holdings, mentioned, holding_anchors = read_holdings_with_index( record=record, regime=regime, many=many) text_anchors = anchors.get_named_anchors(mentioned) return AnchoredHoldings(holdings, holding_anchors, text_anchors)
def test_enactment_with_anchor(self, make_regime): record, mentioned = name_index.index_names(self.test_enactments[1]) schema = schemas.EnactmentSchema(many=False) schema.context["mentioned"] = mentioned schema.context["regime"] = make_regime enactment = schema.load(record) factor_anchors = anchors.get_named_anchors(mentioned) assert enactment.text.startswith( "nor shall any State deprive any person of life, liberty, or property" ) assert (factor_anchors[enactment.name][0].exact == "reference to the Due Process Clause")
def test_read_holding_with_no_anchor(self, make_opinion, make_analysis): oracle = make_opinion["oracle_majority"] raw_analysis = make_analysis["no anchors"] oracle_holdings, mentioned, holding_anchors = readers.read_holdings_with_index( raw_analysis ) named_anchors = anchors.get_named_anchors(mentioned) oracle.posit( oracle_holdings, holding_anchors=holding_anchors, named_anchors=named_anchors, ) has_no_anchors = oracle.holdings[0] assert oracle.holding_anchors[has_no_anchors] == []
def test_read_holdings_and_then_get_anchors(self, make_regime): """ Test whether read_holdings mutates raw_holding and makes it impossible to get text anchors. """ raw_holdings = load_holdings(f"holding_oracle.json") oracle_holdings, mentioned, holding_anchors = readers.read_holdings_with_index( raw_holdings, regime=make_regime ) named_anchors = anchors.get_named_anchors(mentioned) assert isinstance(oracle_holdings[0], Holding) assert isinstance(named_anchors.popitem()[1].pop(), TextQuoteSelector) from authorityspoke.io.loaders import load_holdings_with_index
def test_selectors_not_duplicated(self, make_opinion, 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, mentioned, holding_anchors = readers.read_holdings_with_index( [watch]) named_anchors = anchors.get_named_anchors(mentioned) cardenas = make_opinion["cardenas_majority"] cardenas.posit_holdings(holdings, named_anchors=named_anchors) output = holdings[0].outputs[0] assert any(selector.exact == "Mark stole a watch" for selector in cardenas.factors[output]) assert any(selector.exact == "a watch was stolen by Mark" for selector in cardenas.factors[output]) assert len(cardenas.factors[output]) == 2
def test_import_enactments_and_anchors(self, make_regime, make_opinion): """ 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", "anchors": [ {"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": [ { "exact": "are not copyrightable", "prefix": "The first is that facts", }, {"exact": "no one may copyright", "suffix": "facts"}, ], }, "enactments": [ { "source": "/us/const/article-I/8/8", "exact": ( "To promote the Progress of Science and useful Arts, " "by securing for limited Times to Authors" ), "name": "securing for authors", }, { "source": "/us/const/article-I/8/8", "exact": "the exclusive Right to their respective Writings", "name": "right to writings", }, ], "mandatory": True, "universal": True, }, { "outputs": { "type": "fact", "content": "Rural's telephone directory was copyrightable", "anchors": [ { "exact": "copyrightable", "prefix": "first is that facts are not", }, "The sine qua non of|copyright|", ], }, "enactments": ["securing for authors", "right to writings"], "mandatory": True, "anchors": "compilations of facts|generally are|", }, ] record, mentioned = name_index.index_names(raw_holdings) holding_anchors = anchors.get_holding_anchors(record) named_anchors = anchors.get_named_anchors(mentioned) schema = schemas.HoldingSchema(many=True) schema.context["mentioned"] = mentioned schema.context["regime"] = make_regime feist_holdings = schema.load(record) feist = make_opinion["feist_majority"] feist.posit( feist_holdings, holding_anchors=holding_anchors, named_anchors=named_anchors ) assert feist.holdings[0].enactments[0].name == "securing for authors" assert feist.holdings[1].enactments[0].name == "securing for authors"
def test_make_enactment_anchor(self): record, mentioned = index_names(self.enactment_anchor) named_anchors = anchors.get_named_anchors(mentioned) enactment_anchors = named_anchors["copyright protection provision"] assert enactment_anchors[0].exact == "17 U.S.C. ยง 102(a)"
def test_anchors_from_fact_with_inferred_name(self): record, mentioned = index_names(self.fact) factor_anchors = anchors.get_named_anchors(mentioned) fact_anchors = factor_anchors[ "false Rural's telephone directory was copyrightable"] assert fact_anchors[1].exact == "no one may copyright"