def test_unify_multi_var_deep(self): collection = RDFCollection() self.assertIsNotNone(collection) collection.add_entity("TEST1", "ISA", "TEST2", "TEST") collection.add_entity("TEST2", "ISA", "TEST3", "TEST") collection.add_entity("TEST3", "ISA", "TEST4", "TEST") collection.add_entity("TEST4", "ISA", "TEST5", "TEST") 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.assertEqual(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_unify_on_single_var(self): collection = RDFCollection() self.assertIsNotNone(collection) collection.add_entity("MONKEY", "LEGS", "2", "ANIMAL") collection.add_entity("MONKEY", "HASFUR", "true", "ANIMAL") collection.add_entity("ZEBRA", "LEGS", "4", "ANIMAL") collection.add_entity("BIRD", "LEGS", "2", "ANIMAL") collection.add_entity("ELEPHANT", "TRUNK", "true", "ANIMAL") set1 = collection.match_to_vars("?x", "LEGS", "2") set2 = collection.match_to_vars("?x", "HASFUR", "true") unified = collection.unify(["?x"], [set1, set2]) self.assertIsNotNone(unified) self.assertEqual(1, len(unified)) self.assertTrue([['?x', 'MONKEY']] in unified)
def test_unify_on_single_var(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.match_to_vars("?x", "HASFUR", "true") unified = collection.unify(["?x"], [set1, set2]) self.assertIsNotNone(unified) self.assertEquals(1, len(unified)) self.assertTrue([['?x', 'MONKEY']] in unified)
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_match_vars_object_with_subject_predicate_params(self): collection = RDFCollection() self.assertIsNotNone(collection) self.add_data(collection) matched = collection.match_to_vars(subject="MONKEY", predicate="LEGS", obj="?x") self.assertIsNotNone(matched) self.assertEqual(1, len(matched)) self.assertTrue([['subj', 'MONKEY'], ['pred', 'LEGS'], ['?x', '2']] in matched)
def test_match_vars_subject_predicate_with_subject_params(self): collection = RDFCollection() self.assertIsNotNone(collection) self.add_data(collection) matched = collection.match_to_vars(subject="MONKEY", predicate="?y") self.assertIsNotNone(matched) self.assertEquals(2, len(matched)) self.assertTrue([['subj', 'MONKEY'], ['?y', 'LEGS'], ['obj', '2']] in matched) self.assertTrue([['subj', 'MONKEY'], ['?y', 'HASFUR'], ['obj', 'true']] in matched)
def test_chungyilinxrspace_issue_175(self): collection = RDFCollection() self.assertIsNotNone(collection) collection.add_entity("ACTOR", "ISA", "PERSON", "TEST") collection.add_entity("ACTOR", "ISA", "MAN", "TEST") set1 = collection.match_to_vars("ACTOR", "ISA", "?x") self.assertTrue( [['subj', 'ACTOR'], ['pred', 'ISA'], ['?x', 'MAN']] in set1) self.assertTrue( [['subj', 'ACTOR'], ['pred', 'ISA'], ['?x', 'PERSON']] in set1)
def test_match_vars_object_with_subject_predicate_params(self): collection = RDFCollection() self.assertIsNotNone(collection) self.add_data(collection) matched = collection.match_to_vars(subject="MONKEY", predicate="LEGS", obj="?x") self.assertIsNotNone(matched) self.assertEqual(1, len(matched)) self.assertTrue( [['subj', 'MONKEY'], ['pred', 'LEGS'], ['?x', '2']] in matched)
def test_match_vars_subject_predicate_with_subject_params(self): collection = RDFCollection() self.assertIsNotNone(collection) self.add_data(collection) matched = collection.match_to_vars(subject="MONKEY", predicate="?y") self.assertIsNotNone(matched) self.assertEqual(2, len(matched)) self.assertTrue( [['subj', 'MONKEY'], ['?y', 'LEGS'], ['obj', '2']] in matched) self.assertTrue( [['subj', 'MONKEY'], ['?y', 'HASFUR'], ['obj', 'true']] in matched)
def test_match_vars_predicate_object(self): collection = RDFCollection() self.assertIsNotNone(collection) self.add_data(collection) matched = collection.match_to_vars(predicate="?x", obj="?y") self.assertIsNotNone(matched) self.assertTrue([['subj', 'MONKEY'], ['?x', 'LEGS'], ['?y', '2']] in matched) self.assertTrue([['subj', 'MONKEY'], ['?x', 'HASFUR'], ['?y', 'true']] in matched) self.assertTrue([['subj', 'ELEPHANT'], ['?x', 'TRUNK'], ['?y', 'true']] in matched) self.assertTrue([['subj', 'ZEBRA'], ['?x', 'LEGS'], ['?y', '4']] in matched) self.assertTrue([['subj', 'BIRD'], ['?x', 'LEGS'], ['?y', '2']] in matched)
def test_match_vars_subject_object(self): collection = RDFCollection() self.assertIsNotNone(collection) self.add_data(collection) matched = collection.match_to_vars(subject="?x",obj="?z") self.assertIsNotNone(matched) self.assertEquals(5, len(matched)) self.assertTrue([['?x', 'MONKEY'], ['pred', 'LEGS'], ['?z', '2']] in matched) self.assertTrue([['?x', 'MONKEY'], ['pred', 'HASFUR'], ['?z', 'true']] in matched) self.assertTrue([['?x', 'ELEPHANT'], ['pred', 'TRUNK'], ['?z', 'true']] in matched) self.assertTrue([['?x', 'ZEBRA'], ['pred', 'LEGS'], ['?z', '4']] in matched) self.assertTrue([['?x', 'BIRD'], ['pred', 'LEGS'], ['?z', '2']] in matched)
def test_unify_on_multi_vars(self): collection = RDFCollection() self.assertIsNotNone(collection) collection.add_entity("TEST1", "ISA", "TEST2", "TEST") collection.add_entity("TEST2", "ISA", "TEST3", "TEST") 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.assertEqual(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_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_match_vars_predicate_object(self): collection = RDFCollection() self.assertIsNotNone(collection) self.add_data(collection) matched = collection.match_to_vars(predicate="?x", obj="?y") self.assertIsNotNone(matched) self.assertTrue( [['subj', 'MONKEY'], ['?x', 'LEGS'], ['?y', '2']] in matched) self.assertTrue( [['subj', 'MONKEY'], ['?x', 'HASFUR'], ['?y', 'true']] in matched) self.assertTrue( [['subj', 'ELEPHANT'], ['?x', 'TRUNK'], ['?y', 'true']] in matched) self.assertTrue( [['subj', 'ZEBRA'], ['?x', 'LEGS'], ['?y', '4']] in matched) self.assertTrue( [['subj', 'BIRD'], ['?x', 'LEGS'], ['?y', '2']] in matched)
def test_match_vars_subject(self): collection = RDFCollection() self.assertIsNotNone(collection) self.add_data(collection) matched = collection.match_to_vars("?x") self.assertIsNotNone(matched) self.assertEqual(5, len(matched)) self.assertTrue( [['?x', 'MONKEY'], ['pred', 'LEGS'], ['obj', '2']] in matched) self.assertTrue( [['?x', 'MONKEY'], ['pred', 'HASFUR'], ['obj', 'true']] in matched) self.assertTrue([['?x', 'ELEPHANT'], ['pred', 'TRUNK'], ['obj', 'true']] in matched) self.assertTrue( [['?x', 'ZEBRA'], ['pred', 'LEGS'], ['obj', '4']] in matched) self.assertTrue( [['?x', 'BIRD'], ['pred', 'LEGS'], ['obj', '2']] in matched)