Ejemplo n.º 1
0
    def test_atom_4(self):
        wff = "Person( X, Y, Z)"
        expr = Predicate("Person", [Const("X"), Const("Y"), Const("Z")])

        tree = FoplParser.parse(wff)

        self.assertEqual(tree.expr, expr)
        self.assertEqual(tree.constants, ["X", "Y", "Z"])
Ejemplo n.º 2
0
    def test_eq_3(self):
        wff = "Person(A) <-> Person(B)"
        expr = Eq(Predicate("Person", [Const("A")]),
                  Predicate("Person", [Const("B")]))

        tree = FoplParser.parse(wff)

        self.assertEqual(tree.expr, expr)
        self.assertEqual(tree.constants, ["A", "B"])
Ejemplo n.º 3
0
    def test_complex_4(self):
        wff = "P(A)|P(B)&P(C)|P(D)"
        expr = Or(
            Or(Predicate("P", [Const("A")]),
               And(Predicate("P", [Const("B")]), Predicate("P",
                                                           [Const("C")]))),
            Predicate("P", [Const("D")]))

        tree = FoplParser.parse(wff)

        self.assertEqual(tree.expr, expr)
        self.assertEqual(tree.constants, ["A", "B", "C", "D"])
Ejemplo n.º 4
0
    def test_atom_7(self):
        wff = "Person(A,f(X,g(Y,Z)),B)"
        expr = Predicate("Person", [
            Const("A"),
            Func("f",
                 [Const("X"), Func("g", [Const("Y"), Const("Z")])]),
            Const("B")
        ])

        tree = FoplParser.parse(wff)

        self.assertEqual(tree.expr, expr)
        self.assertEqual(tree.constants, ["A", "X", "Y", "Z", "B"])
Ejemplo n.º 5
0
    def test_clamp_2(self):
        wff = "( Person(A) )"
        expr = Predicate("Person", [Const("A")])

        tree = FoplParser.parse(wff)

        self.assertEqual(tree.expr, expr)
        self.assertEqual(tree.constants, ["A"])
Ejemplo n.º 6
0
    def test_not_3(self):
        wff = "!!Person(A)"
        expr = Not(Not(Predicate("Person", [Const("A")])))

        tree = FoplParser.parse(wff)

        self.assertEqual(tree.expr, expr)
        self.assertEqual(tree.constants, ["A"])
Ejemplo n.º 7
0
    def test_atom_8(self):
        wff = "(A)a Person(a,B)"
        expr = AllQuantor(Var("a"), Predicate("Person",
                                              [Var("a"), Const("B")]))

        tree = FoplParser.parse(wff)

        self.assertEqual(tree.expr, expr)
        self.assertEqual(tree.constants, ["B"])
Ejemplo n.º 8
0
    def test_complex_5(self):
        wff = "(A)a (P(a)->K(f(a,B))&P(C)<->!(E(C,D)|K(a)))"
        expr = AllQuantor(
            Var("a"),
            Eq(
                Impl(
                    Predicate("P", [Var("a")]),
                    And(Predicate("K",
                                  [Func("f", [Var("a"), Const("B")])]),
                        Predicate("P", [Const("C")]))),
                Not(
                    Or(Predicate("E", [Const("C"), Const("D")]),
                       Predicate("K", [Var("a")])))))

        tree = FoplParser.parse(wff)

        self.assertEqual(tree.expr, expr)
        self.assertEqual(tree.constants, ["B", "C", "D"])
Ejemplo n.º 9
0
    def test_complex_3(self):
        wff = "(P(A)->K(f(A,B))&P(C))<->!(E(C,D)|K(A))"
        expr = Eq(
            Impl(
                Predicate("P", [Const("A")]),
                And(Predicate("K",
                              [Func("f", [Const("A"), Const("B")])]),
                    Predicate("P", [Const("C")]))),
            Not(
                Or(Predicate("E", [Const("C"), Const("D")]),
                   Predicate("K", [Const("A")]))))

        tree = FoplParser.parse(wff)

        self.assertEqual(tree.expr, expr)
        self.assertEqual(tree.constants, ["A", "B", "C", "D"])