comparison service/mqtt_to_rdf/inference_test.py @ 1664:1a7c1261302c

logic fix- some bindings were being returned 2+; some 0 times
author drewp@bigasterisk.com
date Mon, 20 Sep 2021 23:19:08 -0700
parents 7a61113fd17d
children 4fd9fdfcf16a
comparison
equal deleted inserted replaced
1663:a0bf320c70fe 1664:1a7c1261302c
1 """ 1 """
2 also see https://github.com/w3c/N3/tree/master/tests/N3Tests 2 also see https://github.com/w3c/N3/tree/master/tests/N3Tests
3 """ 3 """
4 from collections import defaultdict 4 import unittest
5 from decimal import Decimal 5 from decimal import Decimal
6 from typing import cast 6 from typing import cast
7 import unittest
8 7
9 from rdflib import ConjunctiveGraph, Graph, Literal, Namespace 8 from rdflib import ConjunctiveGraph, Graph, Literal, Namespace
10 from rdflib.graph import ReadOnlyGraphAggregate
11 from rdflib.parser import StringInputSource 9 from rdflib.parser import StringInputSource
12 10
13 from inference import Inference, Lhs 11 from inference import Inference
14 from rdflib_debug_patches import patchBnodeCounter, patchSlimReprs 12 from rdflib_debug_patches import patchBnodeCounter, patchSlimReprs
15 13
16 patchSlimReprs() 14 patchSlimReprs()
17 patchBnodeCounter() 15 patchBnodeCounter()
18 16
143 141
144 def testRuleVarBindsToInputBNode(self): 142 def testRuleVarBindsToInputBNode(self):
145 inf = makeInferenceWithRules("{ ?z :a :b . } => { :new :stmt :here } .") 143 inf = makeInferenceWithRules("{ ?z :a :b . } => { :new :stmt :here } .")
146 implied = inf.infer(N3("[] :a :b .")) 144 implied = inf.infer(N3("[] :a :b ."))
147 self.assertGraphEqual(implied, N3(":new :stmt :here .")) 145 self.assertGraphEqual(implied, N3(":new :stmt :here ."))
146
147
148 class TestBnodeAliasingSetup(WithGraphEqual):
149
150 def setUp(self):
151 self.inf = makeInferenceWithRules("""
152 {
153 ?var0 :a ?x; :b ?y .
154 } => {
155 :xVar :value ?x .
156 :yVar :value ?y .
157 } .
158 """)
159
160 def assertResult(self, actual):
161 self.assertGraphEqual(actual, N3("""
162 :xVar :value :x0, :x1 .
163 :yVar :value :y0, :y1 .
164 """))
165
166 def testMatchesDistinctStatements(self):
167 implied = self.inf.infer(N3("""
168 :stmt0 :a :x0; :b :y0 .
169 :stmt1 :a :x1; :b :y1 .
170 """))
171 self.assertResult(implied)
172
173 def testMatchesDistinctBnodes(self):
174 implied = self.inf.infer(N3("""
175 [ :a :x0; :b :y0 ] .
176 [ :a :x1; :b :y1 ] .
177 """))
178 self.assertResult(implied)
148 179
149 180
150 class TestBnodeGenerating(WithGraphEqual): 181 class TestBnodeGenerating(WithGraphEqual):
151 182
152 def testRuleBnodeMakesNewBnode(self): 183 def testRuleBnodeMakesNewBnode(self):