Mercurial > code > home > repos > homeauto
comparison service/mqtt_to_rdf/inference_test.py @ 1625:64f4fb8c233f
mostly cleanup; scraps of the next rewrite; unskip tests that are ok now
author | drewp@bigasterisk.com |
---|---|
date | Wed, 08 Sep 2021 23:22:45 -0700 |
parents | 91e9d4eb612a |
children | ea559a846714 |
comparison
equal
deleted
inserted
replaced
1624:91e9d4eb612a | 1625:64f4fb8c233f |
---|---|
4 from collections import defaultdict | 4 from collections import defaultdict |
5 from decimal import Decimal | 5 from decimal import Decimal |
6 from typing import cast | 6 from typing import cast |
7 import unittest | 7 import unittest |
8 | 8 |
9 from rdflib import RDF, BNode, ConjunctiveGraph, Graph, Literal, Namespace | 9 from rdflib import ConjunctiveGraph, Graph, Literal, Namespace |
10 from rdflib.graph import ReadOnlyGraphAggregate | 10 from rdflib.graph import ReadOnlyGraphAggregate |
11 from rdflib.parser import StringInputSource | 11 from rdflib.parser import StringInputSource |
12 | 12 |
13 from inference import Inference, Lhs | 13 from inference import Inference, Lhs |
14 from rdflib_debug_patches import patchBnodeCounter, patchSlimReprs | 14 from rdflib_debug_patches import patchBnodeCounter, patchSlimReprs |
243 | 243 |
244 vlit = cast(Literal, out.value(EX['airQualityIndoorTemperature'], EX['temperatureF'])) | 244 vlit = cast(Literal, out.value(EX['airQualityIndoorTemperature'], EX['temperatureF'])) |
245 valueF = cast(Decimal, vlit.toPython()) | 245 valueF = cast(Decimal, vlit.toPython()) |
246 self.assertAlmostEqual(float(valueF), 75.02) | 246 self.assertAlmostEqual(float(valueF), 75.02) |
247 | 247 |
248 @unittest.skip("still too slow") | |
249 def testPerformance1(self): | 248 def testPerformance1(self): |
250 inf = makeInferenceWithRules(''' | 249 inf = makeInferenceWithRules(''' |
251 { | 250 { |
252 ?msg a :MqttMessage; | 251 ?msg a :MqttMessage; |
253 :topic ( "air_quality_indoor" "sensor" "bme280_temperature" "state" ); | 252 :topic ( "air_quality_indoor" "sensor" "bme280_temperature" "state" ); |
254 :bodyFloat ?valueC . | 253 :bodyFloat ?valueC . |
255 ?valueC math:greaterThan -999 . | 254 ?valueC math:greaterThan -999 . |
256 ?valueC :asFarenheit ?valueF . | 255 ?valueC room:asFarenheit ?valueF . |
257 } => { | 256 } => { |
258 :airQualityIndoorTemperature :temperatureF ?valueF . | 257 :airQualityIndoorTemperature :temperatureF ?valueF . |
259 } . | 258 } . |
260 ''') | 259 ''') |
261 out = inf.infer( | 260 out = inf.infer( |
285 def testList3(self): | 284 def testList3(self): |
286 inf = makeInferenceWithRules("{ :a :b (:e0 :e1 :e2) . } => { :new :stmt :here } .") | 285 inf = makeInferenceWithRules("{ :a :b (:e0 :e1 :e2) . } => { :new :stmt :here } .") |
287 implied = inf.infer(N3(":a :b (:e0 :e1 :e2) .")) | 286 implied = inf.infer(N3(":a :b (:e0 :e1 :e2) .")) |
288 self.assertGraphEqual(implied, N3(":new :stmt :here .")) | 287 self.assertGraphEqual(implied, N3(":new :stmt :here .")) |
289 | 288 |
290 @unittest.skip("still too slow") | |
291 def testList4(self): | 289 def testList4(self): |
292 inf = makeInferenceWithRules("{ :a :b (:e0 :e1 :e2 :e3) . } => { :new :stmt :here } .") | 290 inf = makeInferenceWithRules("{ :a :b (:e0 :e1 :e2 :e3) . } => { :new :stmt :here } .") |
293 implied = inf.infer(N3(":a :b (:e0 :e1 :e2 :e3) .")) | 291 implied = inf.infer(N3(":a :b (:e0 :e1 :e2 :e3) .")) |
294 self.assertGraphEqual(implied, N3(":new :stmt :here .")) | 292 self.assertGraphEqual(implied, N3(":new :stmt :here .")) |
295 | 293 |
309 l = Lhs(N3("?x :a :b .")) | 307 l = Lhs(N3("?x :a :b .")) |
310 ws = ReadOnlyGraphAggregate([N3("[] :a :b .")]) | 308 ws = ReadOnlyGraphAggregate([N3("[] :a :b .")]) |
311 cands = list(l.findCandidateBindings(ws, fakeStats())) | 309 cands = list(l.findCandidateBindings(ws, fakeStats())) |
312 self.assertEqual(len(cands), 1) | 310 self.assertEqual(len(cands), 1) |
313 | 311 |
314 @unittest.skip("still too slow") | |
315 def testListsOnlyMatchEachOther(self): | 312 def testListsOnlyMatchEachOther(self): |
316 l = Lhs(N3(":a :b (:e0 :e1) .")) | 313 l = Lhs(N3(":a :b (:e0 :e1) .")) |
317 ws = ReadOnlyGraphAggregate([N3(":a :b (:e0 :e1) .")]) | 314 ws = ReadOnlyGraphAggregate([N3(":a :b (:e0 :e1) .")]) |
318 stats = fakeStats() | 315 stats = fakeStats() |
319 cands = list(l.findCandidateBindings(ws, stats)) | 316 cands = list(l.findCandidateBindings(ws, stats)) |
320 self.assertLess(stats['permCountFailingVerify'], 20) | 317 self.assertLess(stats['permCountFailingVerify'], 20) |
321 self.fail(str(cands)) |