Ejemplo n.º 1
0
class TestUnionGroup(unittest.TestCase):

    def setUp(self):
        self.store = TripleStore()
        self.store.add_triples(('a', 'name', 'name-a'), ('b', 'name', 'name-b'),
                    ('a', 'weight', 'weight-a'), ('b', 'size', 'size-b'))
        self.p = UnionGroup(Pattern(self.store, VariableExpression('id'), LiteralExpression('name'), VariableExpression('name')),
                            Pattern(self.store, VariableExpression('id'), LiteralExpression('weight'), VariableExpression('weight')))

    def test_match_empty_solution(self):
        self.assertEqual(
            [dict(id='a', name='name-a'), dict(id='b', name='name-b'),
             dict(id='a', weight='weight-a')],
            list(self.p.match({}))
        )
    
    def test_match_with_constraining_solution(self):
        self.assertEqual(
            [dict(id='a', name='name-a'), dict(id='a', weight='weight-a')],
            list(self.p.match({'id': 'a'}))
        )
        self.assertEqual(
            [dict(id='b', name='name-b'), dict(id='a', weight='weight-a', name='name-b')],
            list(self.p.match({'name': 'name-b'}))
        )
        self.assertEqual(
            [],
            list(self.p.match({'id': 'c'}))
        )
Ejemplo n.º 2
0
 def setUp(self):
     self.store = TripleStore()
     self.store.add_triples(('a', 'name', 'name-a'), ('b', 'name', 'name-b'),
                 ('a', 'weight', 'weight-a'), ('b', 'size', 'size-b'))
     self.p = UnionGroup(Pattern(self.store, VariableExpression('id'), LiteralExpression('name'), VariableExpression('name')),
                         Pattern(self.store, VariableExpression('id'), LiteralExpression('weight'), VariableExpression('weight')))