Example #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)
Example #2
0
 def test_means_to_contradicts(self, make_statement):
     explanation = make_statement["crime"].explain_same_meaning(
         make_statement["crime_bob"])
     left = FactorGroup(
         [make_statement["shooting_craig"], make_statement["less"]])
     right = FactorGroup(
         [make_statement["murder_craig"], make_statement["more"]])
     new = left.explain_contradiction(right, context=explanation)
     assert len(new.reasons) == 2
     assert new.reasons[1].operation == contradicts
Example #3
0
    def test_implication_and_contradiction(self):
        lived_at = Predicate(content="$person lived at $residence")
        bob_lived = Statement(
            predicate=lived_at,
            terms=[Entity(name="Bob"),
                   Entity(name="Bob's house")])
        carl_lived = Statement(
            predicate=lived_at,
            terms=[Entity(name="Carl"),
                   Entity(name="Carl's house")])
        explanation = bob_lived.explain_implication(carl_lived)

        distance_long = Comparison(
            content="the distance from the center of $city to $residence was",
            sign=">=",
            expression="50 miles",
        )
        statement_long = Statement(
            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 = Statement(
            predicate=distance_short,
            terms=[Entity(name="El Paso"),
                   Entity(name="Carl's house")],
        )

        left = FactorGroup(statement_long)
        right = FactorGroup(statement_short)
        new_explanation = left.explain_contradiction(right,
                                                     context=explanation)

        expected = "the statement that <bob> lived at <bob's house>"
        assert new_explanation.reasons[0].left.key.lower() == expected
        assert new_explanation.reasons[0].operation == operator.ge

        part = "from the center of <houston> to <bob's house> was at least 50 mile"
        assert part in new_explanation.reasons[1].left.key.lower()
        assert new_explanation.reasons[1].operation == contradicts