示例#1
0
 def test_contradiction_of_group(self):
     lived_at = Predicate(content="$person lived at $residence")
     bob_lived = Fact(
         predicate=lived_at, terms=[Entity(name="Bob"), Entity(name="Bob's house")]
     )
     carl_lived = Fact(
         predicate=lived_at, terms=[Entity(name="Carl"), Entity(name="Carl's house")]
     )
     distance_long = Comparison(
         content="the distance from the center of $city to $residence was",
         sign=">=",
         expression="50 miles",
     )
     statement_long = Fact(
         predicate=distance_long,
         terms=[Entity(name="Houston"), Entity(name="Bob's house")],
     )
     distance_short = Comparison(
         content="the distance from the center of $city to $residence was",
         sign="<=",
         expression="10 kilometers",
     )
     statement_short = Fact(
         predicate=distance_short,
         terms=[Entity(name="El Paso"), Entity(name="Carl's house")],
     )
     left = FactorGroup([bob_lived, statement_long])
     right = FactorGroup([carl_lived, statement_short])
     explanation = left.explain_contradiction(right)
     assert explanation.context["<Houston>"].name == "El Paso"
     assert contradicts(left, right)
示例#2
0
class TestConsistent:
    p_small_weight = Comparison(
        content="the amount of gold $person possessed was",
        sign="<",
        expression=Q_("1 gram"),
    )
    p_large_weight = Comparison(
        content="the amount of gold $person possessed was",
        sign=">=",
        expression=Q_("100 kilograms"),
    )
    small = Fact(predicate=p_large_weight, terms=Entity(name="Alice"))
    big = Fact(predicate=p_small_weight, terms=Entity(name="Bob"))

    def test_contradictory_facts_about_same_entity(self):
        register = ContextRegister()
        register.insert_pair(Entity(name="Alice"), Entity(name="Bob"))
        assert not self.small.consistent_with(self.big, register)
        explanations = list(
            self.small.explanations_consistent_with(self.big,
                                                    context=register))
        assert not explanations

    def test_factor_consistent_with_none(self):
        assert self.small.consistent_with(None)
示例#3
0
    def test_new_context_replace_fact(self):
        predicate_shot = Predicate(content="$shooter shot $victim")
        predicate_no_gun = Predicate(content="$suspect had a gun", truth=False)
        predicate_told = Predicate(content="$speaker told $hearer $statement")
        shot = Fact(predicate=predicate_shot,
                    terms=[Entity(name="Alice"),
                           Entity(name="Bob")])
        told = Fact(
            predicate=predicate_told,
            terms=[Entity(name="Henry"),
                   Entity(name="Jenna"), shot],
        )
        no_gun = Fact(predicate=predicate_no_gun, terms=Entity(name="Dan"))

        changes = ContextRegister.from_lists(
            [
                Entity(name="Alice"),
                Entity(name="Henry"),
                Entity(name="Jenna"), shot
            ],
            [
                Entity(name="Dan"),
                Entity(name="Leslie"),
                Entity(name="Mike"), no_gun
            ],
        )
        result = told.new_context(changes)
        assert (
            "told <Mike> the fact it was false that <Dan> had a gun".lower()
            in result.short_string.lower())
示例#4
0
 def test_load_factor_marked_reciprocal(self):
     fact = Fact(
         predicate=Comparison(
             content="the distance between $place1 and $place2 was",
             sign="<",
             expression="5 miles",
         ),
         terms=TermSequence(
             [Entity(name="the apartment"),
              Entity(name="the office")]),
     )
     assert hasattr(fact.predicate.quantity, "dimensionality")
     data = {
         "type":
         "fact",
         "content":
         "the distance between ${place1} and ${place2} was",
         "sign":
         "<",
         "expression":
         "5 miles",
         "terms": [
             {
                 "type": "entity",
                 "name": "the office"
             },
             {
                 "type": "entity",
                 "name": "the apartment"
             },
         ],
     }
     loaded_fact = Fact(**data)
     assert loaded_fact.means(fact)
    def test_holding_flagged_exclusive(self, make_regime, make_enactment):
        """
        Test that "exclusive" flag doesn't mess up the holding where it's placed.

        Test whether the Feist opinion object includes a holding
        with the output "Rural's telephone directory
        was copyrightable" and the input "Rural's telephone
        directory was original", when that holding was marked
        "exclusive" in the JSON.
        """
        to_read = load_holdings("holding_feist.json")
        feist_holdings = readers.read_holdings(to_read, regime=make_regime)

        directory = Entity("Rural's telephone directory")
        original = Fact(Predicate("{} was an original work"), directory)
        copyrightable = Fact(Predicate("{} was copyrightable"), directory)
        originality_enactments = [
            make_enactment["securing_for_authors"],
            make_enactment["right_to_writings"],
            make_enactment["copyright_requires_originality"],
        ]
        originality_rule = Rule(
            Procedure(outputs=copyrightable, inputs=original),
            mandatory=False,
            universal=False,
            enactments=originality_enactments,
        )
        assert any(
            feist_holding.rule.means(originality_rule)
            for feist_holding in feist_holdings
        )
示例#6
0
 def test_input_or_despite_factors(self):
     """Test part of the process of checking contradiction."""
     rural = Entity(name="Rural's telephone directory")
     compilation = Predicate(
         content="${rural_s_telephone_directory} was a compilation of facts"
     )
     idea = Predicate(content="${rural_s_telephone_directory} was an idea")
     copyrightable = Fact(
         predicate=Predicate(
             content="${rural_s_telephone_directory} was copyrightable"
         ),
         terms=rural,
     )
     left = Procedure(
         outputs=(copyrightable),
         inputs=(Fact(predicate=compilation, terms=rural)),
     )
     right = Procedure(
         outputs=(copyrightable),
         inputs=(Fact(predicate=idea, terms=rural)),
     )
     context = ContextRegister()
     explanation = Explanation.from_context(context)
     gen = left._has_input_or_despite_factors_implied_by_all_inputs_of(
         right, explanation
     )
     with pytest.raises(StopIteration):
         next(gen)
示例#7
0
    def test_implies_due_to_more_complex_entity_order(self, make_exhibit):
        """Test the entire _registers_for_interchangeable_context function."""

        hit = Fact(
            predicate="$person1 hit $target1 and $target2",
            terms=[Entity(name="Moe"), Entity(name="Curly"), Entity(name="Larry")],
        )
        hit2 = Fact(
            predicate="$person1 hit $target1 and $target2",
            terms=[
                Entity(name="Joker"),
                Entity(name="Batman"),
                Entity(name="Superman"),
            ],
        )
        exhibit = Exhibit(
            form="testimony",
            offered_by=Entity(name="Curly"),
            statement=hit,
            statement_attribution=Entity(name="Larry"),
        )
        exhibit2 = Exhibit(
            form="testimony",
            offered_by=Entity(name="Joker"),
            statement=hit2,
            statement_attribution=Entity(name="Batman"),
        )
        assert exhibit.implies(exhibit2)
示例#8
0
 def test_concrete_to_abstract(self):
     predicate = Predicate(content="$person had a farm")
     statement = Fact(predicate=predicate,
                      terms=Entity(name="Old MacDonald"))
     assert str(
         statement).lower() == "the fact that <old macdonald> had a farm"
     generic_str = str(statement.make_generic()).lower()
     assert generic_str == "<the fact that <old macdonald> had a farm>"
示例#9
0
 def test_equal_referencing_diffent_generic_terms(self):
     predicate = Predicate(content="$speaker greeted $listener")
     fact = Fact(predicate=predicate,
                 terms=[Entity(name="Al"),
                        Entity(name="Meg")])
     fact_b = Fact(predicate=predicate,
                   terms=[Entity(name="Jim"),
                          Entity(name="Ned")])
     assert fact.means(fact_b)
示例#10
0
 def test_equality_because_factors_are_generic_entities(self):
     predicate = Predicate(content="$speaker greeted $listener")
     fact = Fact(predicate=predicate,
                 terms=[Entity(name="Al"),
                        Entity(name="Meg")])
     fact_b = Fact(predicate=predicate,
                   terms=[Entity(name="Ed"),
                          Entity(name="Imogene")])
     assert fact.means(fact_b)
示例#11
0
 def test_equality_factor_from_same_predicate(self):
     predicate = Predicate(content="$speaker greeted $listener")
     fact = Fact(predicate=predicate,
                 terms=[Entity(name="Al"),
                        Entity(name="Meg")])
     fact_b = Fact(predicate=predicate,
                   terms=[Entity(name="Al"),
                          Entity(name="Meg")])
     assert fact.means(fact_b)
示例#12
0
    def test_no_implication_complex(self):
        murder_fact = Fact(
            predicate=self.murder_predicate,
            terms=[Entity(name="Alice"),
                   Entity(name="Craig")],
        )
        relevant_to_craig = Fact(predicate=self.relevant_predicate,
                                 terms=[self.shot_fact, murder_fact])

        assert not self.relevant_fact >= relevant_to_craig
示例#13
0
 def test_add_unrelated_factors(self):
     murder = Fact(
         predicate=Predicate(content="$person committed a murder"),
         terms=Entity(name="Al"),
     )
     crime = Fact(
         predicate=Predicate(content="$person committed a crime"),
         terms=Entity(name="Al"),
     )
     assert murder + crime is None
示例#14
0
 def test_means_despite_plural(self):
     directory = Entity(name="the telephone directory", plural=False)
     listings = Entity(name="the telephone listings", plural=True)
     directory_original = Fact(
         predicate=Predicate(content="$thing was original"),
         terms=directory)
     listings_original = Fact(
         predicate=Predicate(content="$thing were original"),
         terms=listings)
     assert directory_original.means(listings_original)
示例#15
0
 def test_statement_implies_no_truth_value(self):
     fact = Fact(
         predicate=Predicate(content="$person was a person"),
         terms=Entity(name="Alice"),
     )
     whether = Fact(
         predicate=Predicate(content="$person was a person", truth=None),
         terms=Entity(name="Alice"),
     )
     assert fact >= whether
     assert not whether > fact
示例#16
0
 def test_new_statement_from_entities(self):
     predicate = Predicate(content="$person managed $place")
     statement = Fact(
         predicate=predicate,
         terms=[Entity(name="Steve Jobs"),
                Entity(name="Apple")])
     different = statement.new_context(
         [Entity(name="Darth Vader"),
          Entity(name="the Death Star")])
     assert "<Darth Vader> managed" in str(different)
     assert isinstance(different.term_sequence, TermSequence)
示例#17
0
 def test_changing_order_of_concrete_terms_changes_meaning(self):
     ann = Entity(name="Ann", generic=False)
     bob = Entity(name="Bob", generic=False)
     parent_sentence = Predicate(content="$mother was ${child}'s parent")
     ann_parent = Fact(predicate=parent_sentence, terms=(ann, bob))
     bob_parent = Fact(predicate=parent_sentence, terms=(bob, ann))
     assert str(ann_parent).lower(
     ) == "the fact that Ann was Bob's parent".lower()
     assert str(bob_parent).lower(
     ) == "the fact that Bob was Ann's parent".lower()
     assert not ann_parent.means(bob_parent)
示例#18
0
 def test_unequal_because_a_factor_is_not_generic(self):
     predicate = Predicate(content="$speaker greeted $listener")
     fact = Fact(predicate=predicate,
                 terms=[Entity(name="Al"),
                        Entity(name="Meg")])
     fact_b = Fact(
         predicate=predicate,
         terms=[Entity(name="Ed"),
                Entity(name="Imogene", generic=False)],
     )
     assert not fact.means(fact_b)
示例#19
0
 def test_same_predicate_true_vs_false(self):
     fact = Fact(
         predicate=Predicate(content="$person was a person"),
         terms=Entity(name="Alice"),
     )
     fiction = Fact(
         predicate=Predicate(content="$person was a person", truth=False),
         terms=Entity(name="Alice"),
     )
     assert fact.contradicts(fiction)
     assert fact.truth != fiction.truth
示例#20
0
 def test_factor_different_predicate_truth_unequal(self):
     predicate = Predicate(content="$shooter shot $victim")
     false_predicate = Predicate(content="$shooter shot $victim",
                                 truth=False)
     fact = Fact(predicate=predicate,
                 terms=[Entity(name="Al"),
                        Entity(name="Meg")])
     fact_b = Fact(predicate=false_predicate,
                   terms=[Entity(name="Al"),
                          Entity(name="Meg")])
     assert not fact.means(fact_b)
示例#21
0
    def test_is_beard_implied(
        self,
        facial_hair_over_5mm,
        facial_hair_on_or_below_chin,
        facial_hair_uninterrupted,
        outcome,
        fake_beard_client,
        make_beard_rule,
    ):
        beard = Entity(name="a facial feature")

        sec_4 = fake_beard_client.read("/test/acts/47/4/")

        was_facial_hair = Predicate(content="$thing was facial hair")
        fact_was_facial_hair = Fact(predicate=was_facial_hair, terms=beard)
        hypothetical = Rule(
            procedure=Procedure(
                inputs=[
                    fact_was_facial_hair,
                    Fact(
                        predicate=Comparison(
                            content="the length of $thing was",
                            sign=">=",
                            expression=Q_("5 millimeters"),
                            truth=facial_hair_over_5mm,
                        ),
                        terms=beard,
                    ),
                    Fact(
                        predicate=Predicate(
                            content="$thing occurred on or below the chin",
                            truth=facial_hair_on_or_below_chin,
                        ),
                        terms=beard,
                    ),
                    Fact(
                        predicate=Predicate(
                            content=
                            "$thing existed in an uninterrupted line from the front "
                            "of one ear to the front of the other ear below the nose",
                            truth=facial_hair_uninterrupted,
                        ),
                        terms=beard,
                    ),
                ],
                outputs=Fact(predicate=Predicate(content="$thing was a beard"),
                             terms=beard),
            ),
            enactments=sec_4,
        )

        meets_chin_test = make_beard_rule[0].implies(hypothetical)
        meets_ear_test = make_beard_rule[1].implies(hypothetical)
        assert outcome == meets_chin_test or meets_ear_test
示例#22
0
 def test_unequal_because_one_factor_is_absent(self):
     predicate = Predicate(content="$shooter shot $victim")
     fact = Fact(predicate=predicate,
                 terms=[Entity(name="Al"),
                        Entity(name="Meg")])
     fact_b = Fact(
         predicate=predicate,
         terms=[Entity(name="Al"), Entity(name="Meg")],
         absent=True,
     )
     assert not fact.means(fact_b)
示例#23
0
    def test_unequal_to_statement(self, watt_factor, e_copyright):
        stole_predicate = Predicate(content="$defendant stole $object")
        stole_fact = Fact(
            predicate=stole_predicate,
            terms=[Entity(name="Alice"),
                   Entity(name="the gold bar")],
        )

        assert not stole_fact.means(e_copyright)
        with pytest.raises(TypeError):
            e_copyright.means(watt_factor["f1"])
示例#24
0
 def test_specific_statement_implies_generic(self):
     concrete = Fact(
         predicate=Predicate(content="$person was a person"),
         terms=Entity(name="Alice"),
     )
     generic = Fact(
         predicate=Predicate(content="$person was a person"),
         terms=Entity(name="Alice"),
         generic=True,
     )
     assert concrete > generic
     assert not generic > concrete
示例#25
0
    def test_specific_implies_generic_form_of_another_fact(self):
        concrete = Fact(
            predicate=Predicate(content="$person was a person"),
            terms=Entity(name="Alice"),
        )
        generic_merperson = Fact(
            predicate=Predicate(content="$person was a merperson"),
            terms=Entity(name="Alice"),
            generic=True,
        )

        assert concrete > generic_merperson
示例#26
0
 def test_new_concrete_context(self):
     """
     "Dragonfly Inn" is still a string representation of an Entity
     object, but it's not in angle brackets because it can't be
     replaced by another Entity object without changing the meaning
     of the Fact.
     """
     predicate = Predicate(content="$place was a hotel")
     statement = Fact(predicate=predicate,
                      terms=[Entity(name="Independence Inn")])
     different = statement.new_context(
         [Entity(name="Dragonfly Inn", generic=False)])
     assert "Dragonfly Inn was a hotel" in str(different)
示例#27
0
 def test_get_factor_from_recursive_search(self):
     predicate_shot = Predicate(content="$shooter shot $victim")
     predicate_told = Predicate(content="$speaker told $hearer $statement")
     shot = Fact(predicate=predicate_shot,
                 terms=[Entity(name="Alice"),
                        Entity(name="Bob")])
     told = Fact(
         predicate=predicate_told,
         terms=[Entity(name="Henry"),
                Entity(name="Jenna"), shot],
     )
     factors = told.recursive_terms
     assert factors["<Alice>"].compare_keys(Entity(name="Alice"))
示例#28
0
    def test_specific_implies_generic_explain(self):
        concrete = Fact(
            predicate=Predicate(content="$person was a person"),
            terms=Entity(name="Alice"),
        )
        generic = Fact(
            predicate=Predicate(content="$person was a person"),
            terms=Entity(name="Alice"),
            generic=True,
        )

        answer = concrete.explain_implication(generic)
        assert (str(concrete), generic) in answer.context.items()
示例#29
0
 def test_too_much_info_to_change_context(self):
     """Test that a list of terms to replace requires "changes" to be consistent."""
     statement = Fact(
         predicate="$person1 loved $person2",
         terms=[Entity(name="Donald"),
                Entity(name="Daisy")],
     )
     new = statement.new_context(
         changes=[Entity(name="Mickey")],
         terms_to_replace=[Entity(name="Donald"),
                           Entity(name="Daisy")],
     )
     assert "<Mickey> loved <Daisy>" in str(new)
示例#30
0
    def test_is_beard_implied(
        self,
        facial_hair_over_5mm,
        facial_hair_on_or_below_chin,
        facial_hair_uninterrupted,
        outcome,
        make_beard_rule,
    ):
        beard = Entity("a facial feature")

        sec_4 = client.read(path="/test/acts/47/4/")

        hypothetical = Rule(
            procedure=Procedure(
                inputs=[
                    Fact(Predicate("{} was facial hair"),
                         context_factors=beard),
                    Fact(
                        Predicate(
                            "the length of {} was {}",
                            comparison=">=",
                            quantity=Q_("5 millimeters"),
                            truth=facial_hair_over_5mm,
                        ),
                        context_factors=beard,
                    ),
                    Fact(
                        Predicate(
                            "{} occurred on or below the chin",
                            truth=facial_hair_on_or_below_chin,
                        ),
                        context_factors=beard,
                    ),
                    Fact(
                        Predicate(
                            "{} existed in an uninterrupted line from the front "
                            "of one ear to the front of the other ear below the nose",
                            truth=facial_hair_uninterrupted,
                        ),
                        context_factors=beard,
                    ),
                ],
                outputs=Fact(Predicate("{} was a beard"),
                             context_factors=beard),
            ),
            enactments=sec_4,
        )

        meets_chin_test = make_beard_rule[0].implies(hypothetical)
        meets_ear_test = make_beard_rule[1].implies(hypothetical)
        assert outcome == meets_chin_test or meets_ear_test