Пример #1
0
    def testEquals(self):
        block = self.kb.root
        literal = self.kb.addEntity(Literal(10))
        statement = Statement("foo", {"x": literal})
        self.kb.addStatement(block, statement)

        literal2 = self.kb.addEntity(Literal(10))
        statement2 = Statement("foo", {"x": literal2})
        self.kb.addStatement(block, statement)
        self.assertTrue(statement.equals(self.kb, statement2))
Пример #2
0
    def testSubstitute(self):
        # foo(a: x, b: x)[x -> 10] == foo(a: 10, b: 10)

        block = self.kb.root
        variable = Variable("x")
        statement = Statement("foo", {"a": variable, "b": variable})
        statementID = self.kb.addStatement(block, statement)

        literal = self.kb.addEntity(Literal(10))
        statement2 = statement.substitute(statementID, self.kb, {"x": literal})

        statement3 = self.kb.addStatement(block, Statement("foo", {"a": literal, "b": literal}))

        self.assertTrue(self.kb[statement2].equals(self.kb, self.kb[statement3]))
Пример #3
0
    def testUnify(self):
        # foo(l: bar(a: x), r: y) ~~ foo(l: z, r:z) == { y -> bar(a: x), z -> bar(a: x) }

        block = self.kb.root
        x = Variable("x")
        y = Variable("y")
        z = Variable("z")
        statement = Statement("bar", {"a": x})
        statementID = self.kb.addEntity(statement)
        statement2 = Statement("foo", {"l": statementID, "r": y})
        statement2ID = self.kb.addStatement(block, statement2)
        statement3 = Statement("foo", {"l": z, "r": z})
        statement3ID = self.kb.addStatement(block, statement3)

        self.assertTrue(statement2.unify(self.kb, statement3ID) == {"y": statementID, "z": statementID})
Пример #4
0
    def testNotEquals(self):
        block = self.kb.root
        literal = self.kb.addEntity(Literal(10))
        statement = Statement("foo", {"x": literal})
        self.kb.addStatement(block, statement)
        self.assertFalse(self.kb[literal].equals(self.kb, statement))

        literal2 = self.kb.addEntity(Literal(10))
        statement2 = Statement("foo", {"x": literal2, "y": literal2})
        self.kb.addStatement(block, statement)
        self.assertFalse(statement.equals(self.kb, statement2))

        literal3 = self.kb.addEntity(Literal(5))
        statement3 = Statement("foo", {"x": literal3})
        self.kb.addStatement(block, statement)
        self.assertFalse(statement.equals(self.kb, statement3))