Exemplo n.º 1
0
    def _transform_biconditional_expression(self, term):
        first_implication = ImplicationTerm(self.transform(term.children[0]),
                                            self.transform(term.children[1]))

        second_implication = ImplicationTerm(self.transform(term.children[1]),
                                             self.transform(term.children[0]))

        # Biconditional term transformation; A <=> B == (A => B) AND (B => A)
        return AndTerm(self.transform(first_implication),
                       self.transform(second_implication))
Exemplo n.º 2
0
 def test_and(self):
     # Here comes my LISP nostalgia
     self._test_parser(
         "Java AND Haskell => Scala",
         AndTerm(
             SymbolTerm("Java"),
             ImplicationTerm(SymbolTerm("Haskell"), SymbolTerm("Scala"))))
Exemplo n.º 3
0
    def test_as_sentence(self):
        kb = KnowledgeBase()

        kb.tell_str("A")
        kb.tell_str("A OR B")
        kb.tell_str("C <=> D")
        kb.tell_str("E => NOT F")

        sentence = kb.as_sentence()
        expected_sentence = AndTerm(
            SymbolTerm("A"),
            AndTerm(
                OrTerm(SymbolTerm("A"), SymbolTerm("B")),
                AndTerm(
                    BiconditionalTerm(SymbolTerm("C"), SymbolTerm("D")),
                    ImplicationTerm(SymbolTerm("E"),
                                    NotTerm(SymbolTerm("F"))))))

        self.assertEqual(expected_sentence, sentence)
Exemplo n.º 4
0
 def test_complex_and(self):
     self._test_parser(
         "(A => B) AND (B => A)",
         AndTerm(ImplicationTerm(SymbolTerm("A"), SymbolTerm("B")),
                 ImplicationTerm(SymbolTerm("B"), SymbolTerm("A"))))
Exemplo n.º 5
0
 def test_complex_not(self):
     self._test_parser(
         "(Java AND NOT C) => Scala",
         ImplicationTerm(
             AndTerm(SymbolTerm("Java"), NotTerm(SymbolTerm("C"))),
             SymbolTerm("Scala")))
Exemplo n.º 6
0
 def test_parenth(self):
     self._test_parser(
         "(Java AND Haskell) => Scala",
         ImplicationTerm(AndTerm(SymbolTerm("Java"), SymbolTerm("Haskell")),
                         SymbolTerm("Scala")))
Exemplo n.º 7
0
 def test_parsing(self):
     self._test_parser(
         "(B11 => (NOT P11)) AND B11",
         AndTerm(
             ImplicationTerm(SymbolTerm("B11"), NotTerm(SymbolTerm("P11"))),
             SymbolTerm("B11")))