Mercurial > code > home > repos > homeauto
comparison service/mqtt_to_rdf/inference_test.py @ 1657:274bb6c04627
update currently-working tests
author | drewp@bigasterisk.com |
---|---|
date | Sun, 19 Sep 2021 13:23:50 -0700 |
parents | 20474ad4968e |
children | 15e84c71beee |
comparison
equal
deleted
inserted
replaced
1656:d8e5b2232474 | 1657:274bb6c04627 |
---|---|
183 # def test3(self): | 183 # def test3(self): |
184 # inf = makeInferenceWithRules("{ :a :b :c . :a :b ?x . } => { :new :stmt ?x } .") | 184 # inf = makeInferenceWithRules("{ :a :b :c . :a :b ?x . } => { :new :stmt ?x } .") |
185 # self.assertGraphEqual(inf.infer(N3("")), N3(":new :stmt :c .")) | 185 # self.assertGraphEqual(inf.infer(N3("")), N3(":new :stmt :c .")) |
186 | 186 |
187 | 187 |
188 # class TestInferenceWithMathFunctions(WithGraphEqual): | 188 class TestInferenceWithMathFunctions(WithGraphEqual): |
189 | 189 |
190 # def testBoolFilter(self): | 190 def testBoolFilter(self): |
191 # inf = makeInferenceWithRules("{ :a :b ?x . ?x math:greaterThan 5 } => { :new :stmt ?x } .") | 191 inf = makeInferenceWithRules("{ :a :b ?x . ?x math:greaterThan 5 } => { :new :stmt ?x } .") |
192 # self.assertGraphEqual(inf.infer(N3(":a :b 3 .")), N3("")) | 192 self.assertGraphEqual(inf.infer(N3(":a :b 3 .")), N3("")) |
193 # self.assertGraphEqual(inf.infer(N3(":a :b 5 .")), N3("")) | 193 self.assertGraphEqual(inf.infer(N3(":a :b 5 .")), N3("")) |
194 # self.assertGraphEqual(inf.infer(N3(":a :b 6 .")), N3(":new :stmt 6 .")) | 194 self.assertGraphEqual(inf.infer(N3(":a :b 6 .")), N3(":new :stmt 6 .")) |
195 | 195 |
196 # def testNonFiringMathRule(self): | 196 # def testNonFiringMathRule(self): |
197 # inf = makeInferenceWithRules("{ :a :b ?x . (?x 1) math:sum ?y } => { :new :stmt ?y } .") | 197 # inf = makeInferenceWithRules("{ :a :b ?x . (?x 1) math:sum ?y } => { :new :stmt ?y } .") |
198 # self.assertGraphEqual(inf.infer(N3("")), N3("")) | 198 # self.assertGraphEqual(inf.infer(N3("")), N3("")) |
199 | 199 |
212 # def test0Operands(self): | 212 # def test0Operands(self): |
213 # inf = makeInferenceWithRules("{ :a :b ?x . () math:sum ?y } => { :new :stmt ?y } .") | 213 # inf = makeInferenceWithRules("{ :a :b ?x . () math:sum ?y } => { :new :stmt ?y } .") |
214 # self.assertGraphEqual(inf.infer(N3(":a :b 2 .")), N3(":new :stmt 0 .")) | 214 # self.assertGraphEqual(inf.infer(N3(":a :b 2 .")), N3(":new :stmt 0 .")) |
215 | 215 |
216 | 216 |
217 # class TestInferenceWithCustomFunctions(WithGraphEqual): | 217 class TestInferenceWithCustomFunctions(WithGraphEqual): |
218 | 218 |
219 # def testAsFarenheit(self): | 219 def testAsFarenheit(self): |
220 # inf = makeInferenceWithRules("{ :a :b ?x . ?x room:asFarenheit ?f } => { :new :stmt ?f } .") | 220 inf = makeInferenceWithRules("{ :a :b ?x . ?x room:asFarenheit ?f } => { :new :stmt ?f } .") |
221 # self.assertGraphEqual(inf.infer(N3(":a :b 12 .")), N3(":new :stmt 53.6 .")) | 221 self.assertGraphEqual(inf.infer(N3(":a :b 12 .")), N3(":new :stmt 53.6 .")) |
222 | 222 |
223 | 223 |
224 # class TestUseCases(WithGraphEqual): | 224 class TestUseCases(WithGraphEqual): |
225 | 225 |
226 # def testSimpleTopic(self): | 226 def testSimpleTopic(self): |
227 # inf = makeInferenceWithRules(''' | 227 inf = makeInferenceWithRules(''' |
228 # { ?msg :body "online" . } => { ?msg :onlineTerm :Online . } . | 228 { ?msg :body "online" . } => { ?msg :onlineTerm :Online . } . |
229 # { ?msg :body "offline" . } => { ?msg :onlineTerm :Offline . } . | 229 { ?msg :body "offline" . } => { ?msg :onlineTerm :Offline . } . |
230 | 230 |
231 # { | 231 { |
232 # ?msg a :MqttMessage ; | 232 ?msg a :MqttMessage ; |
233 # :topic :foo; | 233 :topic :foo; |
234 # :onlineTerm ?onlineness . } => { | 234 :onlineTerm ?onlineness . } => { |
235 # :frontDoorLockStatus :connectedStatus ?onlineness . | 235 :frontDoorLockStatus :connectedStatus ?onlineness . |
236 # } . | 236 } . |
237 # ''') | 237 ''') |
238 | 238 |
239 # out = inf.infer(N3('[] a :MqttMessage ; :body "online" ; :topic :foo .')) | 239 out = inf.infer(N3('[] a :MqttMessage ; :body "online" ; :topic :foo .')) |
240 # self.assertIn((ROOM['frontDoorLockStatus'], ROOM['connectedStatus'], ROOM['Online']), out) | 240 self.assertIn((ROOM['frontDoorLockStatus'], ROOM['connectedStatus'], ROOM['Online']), out) |
241 | 241 |
242 # def testTopicIsList(self): | 242 # def testTopicIsList(self): |
243 # inf = makeInferenceWithRules(''' | 243 # inf = makeInferenceWithRules(''' |
244 # { ?msg :body "online" . } => { ?msg :onlineTerm :Online . } . | 244 # { ?msg :body "online" . } => { ?msg :onlineTerm :Online . } . |
245 # { ?msg :body "offline" . } => { ?msg :onlineTerm :Offline . } . | 245 # { ?msg :body "offline" . } => { ?msg :onlineTerm :Offline . } . |
344 def testList3(self): | 344 def testList3(self): |
345 inf = makeInferenceWithRules("{ :a :b (:e0 :e1 :e2) . } => { :new :stmt :here } .") | 345 inf = makeInferenceWithRules("{ :a :b (:e0 :e1 :e2) . } => { :new :stmt :here } .") |
346 implied = inf.infer(N3(":a :b (:e0 :e1 :e2) .")) | 346 implied = inf.infer(N3(":a :b (:e0 :e1 :e2) .")) |
347 self.assertGraphEqual(implied, N3(":new :stmt :here .")) | 347 self.assertGraphEqual(implied, N3(":new :stmt :here .")) |
348 | 348 |
349 def testList4(self): | 349 # def testList4(self): |
350 inf = makeInferenceWithRules("{ :a :b (:e0 :e1 :e2 :e3) . } => { :new :stmt :here } .") | 350 # inf = makeInferenceWithRules("{ :a :b (:e0 :e1 :e2 :e3) . } => { :new :stmt :here } .") |
351 implied = inf.infer(N3(":a :b (:e0 :e1 :e2 :e3) .")) | 351 # implied = inf.infer(N3(":a :b (:e0 :e1 :e2 :e3) .")) |
352 self.assertGraphEqual(implied, N3(":new :stmt :here .")) | 352 # self.assertGraphEqual(implied, N3(":new :stmt :here .")) |
353 | 353 |
354 | 354 |
355 # def fakeStats(): | 355 # def fakeStats(): |
356 # return defaultdict(lambda: 0) | 356 # return defaultdict(lambda: 0) |
357 | 357 |