Exemplo n.º 1
0
    def test_likely_context_from_factor_meaning(self):
        left = Statement(
            predicate=
            "$part provided the means by which users controlled and operated $whole",
            terms=[
                Entity(name="the Java API"),
                Entity(name="the Java language")
            ],
        )
        right = Statement(
            predicate=
            "$part provided the means by which users controlled and operated $whole",
            terms=[
                Entity(name="the Lotus menu command hierarchy"),
                Entity(name="Lotus 1-2-3"),
            ],
        )
        likely = left._likely_context_from_meaning(right,
                                                   context=ContextRegister())

        assert (likely.get_factor(
            Entity(name="the Java API")).short_string == Entity(
                name="the Lotus menu command hierarchy").short_string)
Exemplo n.º 2
0
    def union(
        self, other: Union[Rule, Holding], context: Optional[ContextRegister] = None
    ) -> Optional[Holding]:
        """
        Infer a Holding from all inputs and outputs of self and other, in context.

        Creates a new Holding with all of the inputs and all of the outputs
        of both of the two original Holdings.

        However, you only get such a new Holding if it can be inferred by
        accepting the truth of the two original Holdings.

        If self contradicts() other, the operation returns None. Likewise, if
        the two original Holdings both have the value False for the parameter
        universal, the operation will return None if it’s possible that the
        “SOME” cases where one of the original Holdings applies don’t
        overlap with the “SOME” cases where the other applies.
        """
        context = context or ContextRegister()
        if isinstance(other, Rule):
            other = Holding(rule=other)
        if not isinstance(other, Holding):
            raise TypeError
        return self._union_with_holding(other, context=context)
Exemplo n.º 3
0
    def test_implication_complex_explain(self):
        """
        Check that when .implies() provides a ContextRegister as an "explanation",
        it uses elements only from the left as keys and from the right as values.
        """

        context_names = ContextRegister()
        context_names.insert_pair(key=Entity(name="Alice"),
                                  value=Entity(name="Craig"))
        context_names.insert_pair(key=Entity(name="Bob"),
                                  value=Entity(name="Dan"))

        complex_whether = self.relevant_whether.new_context(context_names)
        explanation = self.relevant_fact.explain_implication(complex_whether)
        assert explanation.context.get("<Alice>").compare_keys(
            Entity(name="Craig"))
        assert "<Alice> is like <Craig>, and <Bob> is like <Dan>" in str(
            explanation)
        assert explanation.context.get(Entity(name="Craig").key) is None
        assert explanation.context.get(Entity(name="Alice").key).compare_keys(
            Entity(name="Craig"))
Exemplo n.º 4
0
 def test_no_iterables_in_register(self):
     left = FactorGroup()
     right = FactorGroup()
     context = ContextRegister()
     with pytest.raises(TypeError):
         context.insert_pair(left, right)
Exemplo n.º 5
0
 def test_not_same_register_one_term(self):
     left = ContextRegister.from_lists([Entity(name="Odysseus")],
                                       [Entity(name="Ulysses")])
     right = ContextRegister.from_lists([Entity(name="Odysseus")],
                                        [Entity(name="Jason")])
     assert not right.means(left)
Exemplo n.º 6
0
 def test_cannot_create_register_from_one_list(self):
     with pytest.raises(ValueError):
         ContextRegister.create([Entity(name="Alice"), Entity(name="Bob")])
Exemplo n.º 7
0
    def test_context_indicates_factors_match(self):
        alice_like_craig = ContextRegister()
        alice_like_craig.insert_pair(alice, craig)

        assert alice_rich.means(craig_rich, context=alice_like_craig)
Exemplo n.º 8
0
 def test_group_inconsistent_with_one_statement(self):
     group = FactorGroup([self.slower_specific_statement, self.farm_statement])
     register = ContextRegister()
     register.insert_pair(Entity(name="the car"), Entity(name="the pickup"))
     assert not group.consistent_with(self.faster_statement, context=register)
Exemplo n.º 9
0
 def test_failed_match(self):
     context = ContextRegister()
     context.insert_pair(Entity(name="Bob"), Entity(name="Alice"))
     assert context.check_match(Entity(name="Craig"),
                                Entity(name="Dan")) is False
Exemplo n.º 10
0
def make_context_register() -> ContextRegister:
    context_names = ContextRegister()
    context_names.insert_pair(key=Entity(name="Alice"), value=Entity(name="Craig"))
    context_names.insert_pair(key=Entity(name="Bob"), value=Entity(name="Dan"))
    return context_names
Exemplo n.º 11
0
 def test_two_inconsistent_groups(self):
     left = FactorGroup([self.slower_specific_statement])
     right = FactorGroup([self.faster_statement])
     context = ContextRegister()
     context.insert_pair(Entity(name="the car"), Entity(name="the pickup"))
     assert not left.consistent_with(right, context=context)
Exemplo n.º 12
0
 def test_new_context_non_generic(self, make_holding, watt_factor):
     changes = ContextRegister()
     changes.insert_pair(watt_factor["f1"], watt_factor["f7"])
     different = make_holding["h1"].new_context(changes)
     assert "the distance between <Hideaway Lodge> and" in str(different)
Exemplo n.º 13
0
 def test_inconsistent_two_terms(self, make_statement):
     context = ContextRegister()
     context.insert_pair(Entity(name="Alice"), Entity(name="Alice"))
     context.insert_pair(Entity(name="Bob"), Entity(name="Bob"))
     assert not make_statement["shooting"].consistent_with(
         make_statement["no_shooting"], context=context)
Exemplo n.º 14
0
 def test_inconsistent(self, make_statement):
     context = ContextRegister()
     context.insert_pair(Entity(name="Alice"), Entity(name="Alice"))
     assert not make_statement["crime"].consistent_with(
         make_statement["no_crime"], context=context)
Exemplo n.º 15
0
 def test_context_not_equal_to_list(self):
     changes = ContextRegister.from_lists(
         [Entity(name="Alice")],
         [Entity(name="Dan")],
     )
     assert changes != [[Entity(name="Alice")], [Entity(name="Dan")]]
Exemplo n.º 16
0
 def test_insert_pair_with_wrong_type(self):
     context = ContextRegister()
     with pytest.raises(TypeError):
         context.insert_pair(Entity(name="Bob"),
                             Predicate(content="events transpired"))
Exemplo n.º 17
0
 def test_impossible_register(self):
     context = ContextRegister()
     context.insert_pair(Entity(name="Al"), Entity(name="Bob"))
     answers = self.fact_al.update_context_register(self.fact_alice,
                                                    context, means)
     assert not any(answers)
Exemplo n.º 18
0
 def test_group_contradicts_single_factor(self):
     group = FactorGroup([self.slower_specific_statement, self.farm_statement])
     register = ContextRegister()
     register.insert_pair(Entity(name="the car"), Entity(name="the pickup"))
     assert group.contradicts(self.faster_statement, context=register)
Exemplo n.º 19
0
 def test_possible_register(self):
     register = ContextRegister()
     register.insert_pair(Entity(name="Al"), Entity(name="Alice"))
     answers = self.fact_al.update_context_register(self.fact_alice,
                                                    register, means)
     assert Entity(name="the bull").key in next(answers).keys()
Exemplo n.º 20
0
 def test_one_statement_consistent_with_group(self):
     group = FactorGroup([self.slower_general_statement, self.farm_statement])
     register = ContextRegister()
     register.insert_pair(Entity(name="the pickup"), Entity(name="the pickup"))
     assert self.faster_statement.consistent_with(group, context=register)
Exemplo n.º 21
0
 def test_explain_consistency(self):
     register = ContextRegister()
     register.insert_pair(Entity(name="Al"), Entity(name="Alice"))
     explanation = self.fact_al.explain_consistent_with(
         self.fact_alice, register)
     assert "<the bull> is like <the cow>" in str(explanation.context)