def test_unify_multi_var_deep(self): collection = RDFCollection() self.assertIsNotNone(collection) collection.add_entity("TEST1", "ISA", "TEST2") collection.add_entity("TEST2", "ISA", "TEST3") collection.add_entity("TEST3", "ISA", "TEST4") collection.add_entity("TEST4", "ISA", "TEST5") set1 = collection.match_to_vars("?x", "ISA", "?y") set2 = collection.match_to_vars("?y", "ISA", "?z") set3 = collection.match_to_vars("?z", "ISA", "?w") unified = collection.unify(("?x", "?y", "?z", "?w"), [set1, set2, set3]) self.assertIsNotNone(unified) self.assertEquals(2, len(unified)) self.assertTrue([ ['?x', 'TEST1'], ['?y', 'TEST2'], ['?z', 'TEST3'], ['?w', 'TEST4'], ] in unified) self.assertTrue([['?x', 'TEST2'], ['?y', 'TEST3'], ['?z', 'TEST4'], ['?w', 'TEST5']] in unified)
def test_add_collection(self): collection = RDFCollection() self.assertIsNotNone(collection) collection.add_entity("ACCOUNT", "hasSize", "0") self.assertTrue(collection.has_subject('ACCOUNT')) self.assertTrue(collection.has_predicate('ACCOUNT', 'hasSize')) self.assertTrue(collection.has_object('ACCOUNT', 'hasSize', "0"))
def test_unify_on_multi_vars(self): collection = RDFCollection() self.assertIsNotNone(collection) collection.add_entity("TEST1", "ISA", "TEST2") collection.add_entity("TEST2", "ISA", "TEST3") set1 = collection.match_to_vars("?x", "ISA", "?y") set2 = collection.match_to_vars("?y", "ISA", "?z") unified = collection.unify(("?x", "?y", "?z"), [set1, set2]) self.assertIsNotNone(unified) self.assertEquals(1, len(unified)) self.assertTrue(["?x", "TEST1"] in unified[0]) self.assertTrue(["?y", "TEST2"] in unified[0]) self.assertTrue(["?z", "TEST3"] in unified[0])
def test_unify_on_single_var_with_not(self): collection = RDFCollection() self.assertIsNotNone(collection) collection.add_entity("MONKEY", "LEGS", "2") collection.add_entity("MONKEY", "HASFUR", "true") collection.add_entity("ZEBRA", "LEGS", "4") collection.add_entity("BIRD", "LEGS", "2") collection.add_entity("ELEPHANT", "TRUNK", "true") set1 = collection.match_to_vars("?x", "LEGS", "2") set2 = collection.not_match_to_vars("?x", "HASFUR", "true") unified = collection.unify(["?x"], [set1, set2]) self.assertIsNotNone(unified) self.assertEquals(1, len(unified)) self.assertTrue([['?x', 'BIRD']] in unified)