Esempio n. 1
0
def index_names(record: Union[List, Dict]) -> Mentioned:
    """
    Call all functions to prepare "mentioned" index.

    The names are sorted by length so that if one mentioned Factor's name
    is a substring of another, the longest available name is expanded.

    :returns:
        a modified version of the dict to load, plus a dict of names
        and the objects to expand them with.
    """
    obj = deepcopy(record)
    obj = text_expansion.expand_shorthand(obj)
    obj, mentioned = collect_mentioned(obj)
    sorted_mentioned = mentioned.sorted_by_length()
    return obj, sorted_mentioned
Esempio n. 2
0
 def test_mentioned_context_changing(self):
     """
     The "mentioned" context should not change while data
     is being loaded with the schema. This is to test
     that the "content" field of a value in the "mentioned"
     dict isn't changed to replace the name of a Factor
     with bracketed text.
     """
     holdings = [
         {
             "inputs": {
                 "type": "fact",
                 "content": "{Bradley} lived at Bradley's house",
             },
             "outputs": {
                 "type": "evidence",
                 "exhibit": {
                     "offered_by": {
                         "type": "entity",
                         "name": "the People"
                     }
                 },
                 "to_effect": {
                     "type": "fact",
                     "name": "fact that Bradley committed a crime",
                     "content": "Bradley committed a crime",
                 },
                 "name": "evidence of Bradley's guilt",
                 "absent": True,
             },
         },
         {
             "inputs": "fact that Bradley committed a crime",
             "outputs": {
                 "type": "fact",
                 "content": "Bradley committed a tort"
             },
         },
     ]
     expanded = text_expansion.expand_shorthand(holdings)
     built = readers.read_holdings(expanded)
     new_factor = built[0].outputs[0].to_effect.terms[0]
     assert new_factor.name == "Bradley"
Esempio n. 3
0
    def test_make_fact_from_string(self, watt_factor):
        fact_float_data = {
            "content":
            "the distance between $person0 and $person1 was >= 20.1",
            "terms": [
                {
                    "type": "Entity",
                    "name": "Ann"
                },
                {
                    "type": "Entity",
                    "name": "Lee"
                },
            ],
        }
        record = expand_shorthand(fact_float_data)
        record, mentioned = index_names(record)
        expanded = readers.expand_factor(record, mentioned)

        fact_float_more = Fact(**expanded)
        fact_float_less = watt_factor["f8_int"]
        assert fact_float_more >= fact_float_less
 def test_mentioned_ordered_by_length(self, raw_factor):
     obj = text_expansion.expand_shorthand(raw_factor["relevant"])
     obj, mentioned = name_index.index_names(obj)
     shortest = mentioned.popitem()
     assert shortest[0] == "Short Name"
 def test_mentioned_from_fact_and_entities(self, raw_factor):
     obj = text_expansion.expand_shorthand(raw_factor["relevant"])
     obj, mentioned = name_index.collect_mentioned(obj)
     assert mentioned["relevant fact"]["type"] == "Fact"
     shooting = mentioned["relevant fact"]["context_factors"][0]
     assert mentioned[shooting]["context_factors"][0] == "Short Name"
    def test_holdings_with_allegation_and_exhibit(self):
        """
        Testing the error message:
        The number of items in 'context_factors' must be 1,
        to match predicate.context_slots for '{} committed
        an attempted robbery' for 'fact that defendant
        committed an attempted robbery'

        This was another bug involving mutation of the "mentioned" context object
        during deserialization.

        Fixed by having FactSchema.get_references_from_mentioned call
        add_found_context with deepcopy(obj) instead of obj for the
        "factor" parameter
        """
        holdings = [
            {
                "inputs": [
                    {
                        "type": "Exhibit",
                        "name": "officer's testimony that defendant was addicted to heroin",
                        "form": "testimony",
                        "statement": {
                            "type": "Fact",
                            "name": "fact that defendant was addicted to heroin",
                            "content": "the {defendant} was addicted to heroin",
                        },
                        "statement_attribution": {
                            "type": "entity",
                            "name": "parole officer",
                        },
                    },
                    {
                        "type": "Allegation",
                        "name": "the attempted robbery charge",
                        "pleading": {
                            "type": "Pleading",
                            "filer": {
                                "type": "Entity",
                                "name": "The People of California",
                            },
                        },
                        "statement": {
                            "type": "Fact",
                            "name": "fact that defendant committed an attempted robbery",
                            "content": "defendant committed an attempted robbery",
                        },
                    },
                ],
                "despite": [
                    {
                        "type": "Fact",
                        "content": "officer's testimony that defendant was addicted to heroin, was relevant to show the defendant had a motive to commit an attempted robbery",
                    }
                ],
                "outputs": [
                    {
                        "type": "Fact",
                        "content": "the probative value of officer's testimony that defendant was addicted to heroin, in showing fact that defendant committed an attempted robbery, was outweighed by unfair prejudice to defendant",
                    }
                ],
                "mandatory": True,
            },
            {
                "inputs": [
                    {
                        "type": "Fact",
                        "content": "the probative value of officer's testimony that defendant was addicted to heroin, in indicating fact that defendant committed an attempted robbery, was outweighed by unfair prejudice to defendant",
                    }
                ],
                "despite": [
                    {
                        "type": "Fact",
                        "content": "officer's testimony that defendant was addicted to heroin was relevant to show defendant had a motive to commit an attempted robbery",
                    }
                ],
                "outputs": [
                    {
                        "type": "Evidence",
                        "name": "evidence of officer's testimony that defendant was addicted to heroin",
                        "exhibit": "officer's testimony that defendant was addicted to heroin",
                        "to_effect": "fact that defendant committed an attempted robbery",
                        "absent": True,
                    }
                ],
                "mandatory": True,
            },
        ]
        expanded = text_expansion.expand_shorthand(holdings)
        built = readers.read_holdings(expanded)
        allegation = built[0].inputs[1]
        assert allegation.statement.context_factors[0].name == "defendant"
 def test_holding_without_enactments_or_regime(self, raw_holding):
     expanded = text_expansion.expand_shorthand(raw_holding["bradley_house"])
     built = readers.read_holding(expanded)
     new_factor = built.outputs[0].to_effect.context_factors[0]
     assert new_factor.name == "Bradley"
Esempio n. 8
0
 def test_load_example(self):
     procedure = text_expansion.expand_shorthand(self.example)
     procedure = readers.read_procedure(procedure)
     factor = procedure.outputs[0].context_factors[0]
     assert factor.name == "the Java API"
Esempio n. 9
0
    def test_import_fact_with_entity_name_containing_another(self):
        expanded = expand_shorthand(self.house_data)
        record, mentioned = index_names(expanded)

        assert mentioned["Alice's house"]["type"] == "Entity"