Exemplo n.º 1
0
 def test_with_optional_group(self):
     p = PatternGroup([Pattern(self.store, VariableExpression('id'), LiteralExpression('name'), VariableExpression('name')),
                       OptionalGroup(
                         PatternGroup([Pattern(self.store, VariableExpression('id'), LiteralExpression('weight'), VariableExpression('weight')),
                                       Pattern(self.store, VariableExpression('id'), LiteralExpression('size'), VariableExpression('size'))])
                       )])
     self.assertEqual(
         [dict(id='a', name='name-a'),
          dict(id='b', name='name-b')],
         list(p.match({}))
     )
     
     self.store.add_triples(('a', 'size', 'size-a'))
     
     self.assertEqual(
         [dict(id='a', name='name-a', weight='weight-a', size='size-a'),
          dict(id='b', name='name-b')],
         list(p.match({}))
     )
     self.assertEqual(
         [dict(id='a', name='name-a', weight='weight-a', size='size-a')],
         list(p.match({'id': 'a'}))
     )
     self.assertEqual(
         [dict(id='b', name='name-b')],
         list(p.match({'id': 'b'}))
     )
Exemplo n.º 2
0
 def test_match_empty_solution(self):
     p = PatternGroup([Pattern(self.store, VariableExpression('id'), LiteralExpression('name'), VariableExpression('name')),
                       Pattern(self.store, VariableExpression('id'), LiteralExpression('weight'), VariableExpression('weight'))])
     self.assertEqual(
         [dict(id='a', name='name-a', weight='weight-a')],
         list(p.match({}))
     )
Exemplo n.º 3
0
 def test_match_with_constraining_solution(self):
     p = PatternGroup([Pattern(self.store, VariableExpression('id'), LiteralExpression('name'), VariableExpression('name')),
                       Pattern(self.store, VariableExpression('id'), LiteralExpression('weight'), VariableExpression('weight'))])
     self.assertEqual(
         [],
         list(p.match({'id': 'b'}))
     )
     self.assertEqual(
         [dict(id='a', name='name-a', weight='weight-a')],
         list(p.match({'id': 'a'}))
     )