Example #1
0
    def test_factor_contradiction_absent_predicate(self):
        predicate = Predicate(content="$person was a person")
        fact = Fact(predicate=predicate, terms=Entity(name="Alice"))
        absent_fact = Fact(predicate=predicate,
                           terms=Entity(name="Alice"),
                           absent=True)

        assert fact.contradicts(absent_fact)
        assert absent_fact.contradicts(fact)
Example #2
0
 def test_factor_no_contradiction_no_truth_value(self):
     fact = Fact(
         predicate=Predicate(content="$person was a person"),
         terms=Entity(name="Alice"),
     )
     fact_no_truth = Fact(
         predicate=Predicate(content="$person was a person"),
         terms=Entity(name="Alice"),
     )
     assert not fact.contradicts(fact_no_truth)
     assert not fact_no_truth.contradicts(fact)
Example #3
0
 def test_false_does_not_contradict_absent(self):
     absent_fact = Fact(
         predicate=Predicate(
             content="${rural_s_telephone_directory} was copyrightable",
             truth=True),
         terms=(Entity(name="Rural's telephone directory")),
         absent=True,
     )
     false_fact = Fact(
         predicate=Predicate(content="${the_java_api} was copyrightable",
                             truth=False),
         terms=(Entity(name="the Java API", generic=True, plural=False)),
         absent=False,
     )
     assert not false_fact.contradicts(absent_fact)
     assert not absent_fact.contradicts(false_fact)
Example #4
0
    def test_factor_different_predicate_truth_contradicts(self):
        predicate = Comparison(
            content="the distance between $place1 and $place2 was",
            sign=">",
            expression=Q_("30 miles"),
        )
        predicate_opposite = Comparison(
            content="the distance between $place1 and $place2 was",
            sign="<",
            expression=Q_("30 miles"),
        )
        terms = [Entity(name="New York"), Entity(name="Los Angeles")]
        fact = Fact(predicate=predicate, terms=terms)
        fact_opposite = Fact(predicate=predicate_opposite, terms=terms)

        assert fact.contradicts(fact_opposite)
        assert fact_opposite.contradicts(fact)
Example #5
0
    def test_no_contradiction_with_more_specific_absent(self):
        predicate_less = Comparison(
            content="${vehicle}'s speed was",
            sign="<",
            expression=Q_("30 miles per hour"),
        )
        predicate_more = Comparison(
            content="${vehicle}'s speed was",
            sign="<",
            expression=Q_("60 miles per hour"),
        )
        terms = [Entity(name="the car")]
        general_fact = Fact(predicate=predicate_more, terms=terms)
        absent_specific_fact = Fact(predicate=predicate_less,
                                    terms=terms,
                                    absent=True)

        assert not general_fact.contradicts(absent_specific_fact)
        assert not absent_specific_fact.contradicts(general_fact)
Example #6
0
    def test_broader_absent_factor_contradicts_quantity_statement(self):
        predicate_less = Comparison(
            content="${vehicle}'s speed was",
            sign=">",
            expression=Q_("30 miles per hour"),
        )
        predicate_more = Comparison(
            content="${vehicle}'s speed was",
            sign=">",
            expression=Q_("60 miles per hour"),
        )
        terms = [Entity(name="the car")]
        absent_general_fact = Fact(predicate=predicate_less,
                                   terms=terms,
                                   absent=True)
        specific_fact = Fact(predicate=predicate_more, terms=terms)

        assert absent_general_fact.contradicts(specific_fact)
        assert specific_fact.contradicts(absent_general_fact)
Example #7
0
    def test_absences_of_contradictory_facts_consistent(self):
        predicate = Comparison(
            content="the distance between $place1 and $place2 was",
            sign=">",
            expression=Q_("30 miles"),
        )
        predicate_opposite = Comparison(
            content="the distance between $place1 and $place2 was",
            sign="<",
            expression=Q_("30 miles"),
        )
        terms = [Entity(name="New York"), Entity(name="Los Angeles")]
        fact = Fact(predicate=predicate, terms=terms, absent=True)
        fact_opposite = Fact(predicate=predicate_opposite,
                             terms=terms,
                             absent=True)

        assert not fact.contradicts(fact_opposite)
        assert not fact_opposite.contradicts(fact)
Example #8
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
Example #9
0
 def test_no_contradiction_complex(self):
     shot_predicate = Predicate(content="$shooter shot $victim")
     shot_fact = Fact(predicate=shot_predicate,
                      terms=[Entity(name="Alice"),
                             Entity(name="Bob")])
     murder_predicate = Predicate(content="$shooter murdered $victim")
     murder_fact = Fact(predicate=murder_predicate,
                        terms=[Entity(name="Alice"),
                               Entity(name="Bob")])
     murder_socrates = Fact(
         predicate=murder_predicate,
         terms=[Entity(name="Alice"),
                Entity(name="Socrates")],
     )
     relevant_predicate = Predicate(
         content="$clue was relevant to $conclusion")
     relevant_fact = Fact(predicate=relevant_predicate,
                          terms=[shot_fact, murder_fact])
     irrelevant_predicate = Predicate(
         content="$clue was relevant to $conclusion", truth=False)
     irrelevant_fact = Fact(predicate=irrelevant_predicate,
                            terms=[shot_fact, murder_socrates])
     assert not relevant_fact.contradicts(irrelevant_fact)
     assert not irrelevant_fact.contradicts(relevant_fact)
Example #10
0
 def test_inconsistent_statements_about_different_entities(self):
     """
     Alice and Bob are both generics. So it's possible to reach a
     contradiction if you assume they correspond to one another.
     """
     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"),
     )
     alice = Entity(name="Alice")
     bob = Entity(name="Bob")
     alice_rich = Fact(predicate=p_large_weight, terms=alice)
     bob_poor = Fact(predicate=p_small_weight, terms=bob)
     assert alice_rich.contradicts(bob_poor)
Example #11
0
 def test_inconsistent_statements_about_corresponding_entities(self):
     """
     Even though Alice and Bob are both generics, it's known that
     Alice in the first context corresponds with Alice in the second.
     So there's no contradiction.
     """
     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"),
     )
     alice = Entity(name="Alice")
     bob = Entity(name="Bob")
     alice_rich = Fact(predicate=p_large_weight, terms=alice)
     bob_poor = Fact(predicate=p_small_weight, terms=bob)
     register = ContextRegister()
     register.insert_pair(alice, alice)
     assert not alice_rich.contradicts(bob_poor, context=register)
Example #12
0
 def test_no_contradiction_of_None(self):
     shot_predicate = Predicate(content="$shooter shot $victim")
     shot_fact = Fact(predicate=shot_predicate,
                      terms=[Entity(name="Alice"),
                             Entity(name="Bob")])
     assert not shot_fact.contradicts(None)
Example #13
0
    def test_factor_does_not_contradict_predicate(self):
        predicate = Predicate(content="$person was a person")
        fact = Fact(predicate=predicate, terms=Entity(name="Alice"))

        with pytest.raises(TypeError):
            fact.contradicts(predicate)