comparison service/mqtt_to_rdf/stmt_chunk_test.py @ 1670:6fa7ddee9ba8

update stmt_chunk_test
author drewp@bigasterisk.com
date Tue, 21 Sep 2021 23:20:41 -0700
parents 00a5624d1d14
children e6d28e6d47b2
comparison
equal deleted inserted replaced
1669:9d00adef0b22 1670:6fa7ddee9ba8
1 from time import clock_gettime
2 import unittest 1 import unittest
3 2
4 from rdflib.term import Variable 3 from rdflib import Namespace, Variable
5 4
5 from candidate_binding import CandidateBinding
6 from inference_test import N3 6 from inference_test import N3
7 from rdflib import ConjunctiveGraph, Graph, Literal, Namespace, Variable 7 from lhs_evaluation import functionsFor
8 8 from stmt_chunk import AlignedRuleChunk, Chunk, ChunkedGraph, applyChunky
9 from stmt_chunk import ChunkedGraph, Chunk, applyChunky
10 9
11 ROOM = Namespace('http://projects.bigasterisk.com/room/') 10 ROOM = Namespace('http://projects.bigasterisk.com/room/')
12
13 from lhs_evaluation import functionsFor
14 from candidate_binding import CandidateBinding
15 11
16 12
17 class TestChunkedGraph(unittest.TestCase): 13 class TestChunkedGraph(unittest.TestCase):
18 14
19 def testMakesSimpleChunks(self): 15 def testMakesSimpleChunks(self):
75 71
76 72
77 class TestApplyChunky(unittest.TestCase): 73 class TestApplyChunky(unittest.TestCase):
78 binding = CandidateBinding({Variable('x'): ROOM.xval}) 74 binding = CandidateBinding({Variable('x'): ROOM.xval})
79 75
80 def testBoundStatementsOnly(self): 76 def testAllStatements(self):
77 rule0 = Chunk((ROOM.a, Variable('pred'), Variable('x')))
78 rule1 = Chunk((ROOM.a, Variable('pred'), Variable('x')))
81 ret = list( 79 ret = list(
82 applyChunky(self.binding, 80 applyChunky(self.binding,
83 g=[Chunk((ROOM.a, ROOM.b, Variable('x'))), 81 g=[
84 Chunk((ROOM.ay, ROOM.by, Variable('y')))], 82 AlignedRuleChunk(ruleChunk=rule0, workingSetChunk=Chunk((ROOM.a, ROOM.b, ROOM.xval))),
85 returnBoundStatementsOnly=True)) 83 AlignedRuleChunk(ruleChunk=rule1, workingSetChunk=Chunk((ROOM.a, ROOM.b, ROOM.yval))),
86 self.assertEqual(ret, [Chunk((ROOM.a, ROOM.b, ROOM.xval))]) 84 ]))
87
88 def testAllStatements(self):
89 ret = list(
90 applyChunky(self.binding,
91 g=[Chunk((ROOM.a, ROOM.b, Variable('x'))),
92 Chunk((ROOM.ay, ROOM.by, Variable('y')))],
93 returnBoundStatementsOnly=False))
94 self.assertCountEqual( 85 self.assertCountEqual(
95 ret, 86 ret,
96 [ 87 [
97 Chunk((ROOM.a, ROOM.b, ROOM.xval)), # 88 AlignedRuleChunk(ruleChunk=Chunk((ROOM.a, Variable('pred'), ROOM.xval)), workingSetChunk=Chunk((ROOM.a, ROOM.b, ROOM.xval)))
98 Chunk((ROOM.ay, ROOM.by, Variable('y')))
99 ]) 89 ])