Mercurial > code > home > repos > homeauto
comparison service/mqtt_to_rdf/inference_test.py @ 1640:4bb6f593ebf3
speedups: abort some rules faster
author | drewp@bigasterisk.com |
---|---|
date | Wed, 15 Sep 2021 23:56:02 -0700 |
parents | ba59cfc3c747 |
children | af136cf6dd26 |
comparison
equal
deleted
inserted
replaced
1639:ae5ca4ba8954 | 1640:4bb6f593ebf3 |
---|---|
227 ''') | 227 ''') |
228 | 228 |
229 out = inf.infer(N3('[] a :MqttMessage ; :body "online" ; :topic :foo .')) | 229 out = inf.infer(N3('[] a :MqttMessage ; :body "online" ; :topic :foo .')) |
230 self.assertIn((EX['frontDoorLockStatus'], EX['connectedStatus'], EX['Online']), out) | 230 self.assertIn((EX['frontDoorLockStatus'], EX['connectedStatus'], EX['Online']), out) |
231 | 231 |
232 # def testTopicIsList(self): | 232 def testTopicIsList(self): |
233 # inf = makeInferenceWithRules(''' | 233 inf = makeInferenceWithRules(''' |
234 # { ?msg :body "online" . } => { ?msg :onlineTerm :Online . } . | 234 { ?msg :body "online" . } => { ?msg :onlineTerm :Online . } . |
235 # { ?msg :body "offline" . } => { ?msg :onlineTerm :Offline . } . | 235 { ?msg :body "offline" . } => { ?msg :onlineTerm :Offline . } . |
236 | 236 |
237 # { | 237 { |
238 # ?msg a :MqttMessage ; | 238 ?msg a :MqttMessage ; |
239 # :topic ( "frontdoorlock" "status" ); | 239 :topic ( "frontdoorlock" "status" ); |
240 # :onlineTerm ?onlineness . } => { | 240 :onlineTerm ?onlineness . } => { |
241 # :frontDoorLockStatus :connectedStatus ?onlineness . | 241 :frontDoorLockStatus :connectedStatus ?onlineness . |
242 # } . | 242 } . |
243 # ''') | 243 ''') |
244 | 244 |
245 # out = inf.infer(N3('[] a :MqttMessage ; :body "online" ; :topic ( "frontdoorlock" "status" ) .')) | 245 out = inf.infer(N3('[] a :MqttMessage ; :body "online" ; :topic ( "frontdoorlock" "status" ) .')) |
246 # self.assertIn((EX['frontDoorLockStatus'], EX['connectedStatus'], EX['Online']), out) | 246 self.assertIn((EX['frontDoorLockStatus'], EX['connectedStatus'], EX['Online']), out) |
247 | 247 |
248 def testPerformance0(self): | 248 def testPerformance0(self): |
249 inf = makeInferenceWithRules(''' | 249 inf = makeInferenceWithRules(''' |
250 { | 250 { |
251 ?msg a :MqttMessage; | 251 ?msg a :MqttMessage; |
267 | 267 |
268 vlit = cast(Literal, out.value(EX['airQualityIndoorTemperature'], EX['temperatureF'])) | 268 vlit = cast(Literal, out.value(EX['airQualityIndoorTemperature'], EX['temperatureF'])) |
269 valueF = cast(Decimal, vlit.toPython()) | 269 valueF = cast(Decimal, vlit.toPython()) |
270 self.assertAlmostEqual(float(valueF), 75.02) | 270 self.assertAlmostEqual(float(valueF), 75.02) |
271 | 271 |
272 # def testPerformance1(self): | 272 def testPerformance1(self): |
273 # inf = makeInferenceWithRules(''' | 273 inf = makeInferenceWithRules(''' |
274 # { | 274 { |
275 # ?msg a :MqttMessage; | 275 ?msg a :MqttMessage; |
276 # :topic ( "air_quality_indoor" "sensor" "bme280_temperature" "state" ); | 276 :topic ( "air_quality_indoor" "sensor" "bme280_temperature" "state" ); |
277 # :bodyFloat ?valueC . | 277 :bodyFloat ?valueC . |
278 # ?valueC math:greaterThan -999 . | 278 ?valueC math:greaterThan -999 . |
279 # ?valueC room:asFarenheit ?valueF . | 279 ?valueC room:asFarenheit ?valueF . |
280 # } => { | 280 } => { |
281 # :airQualityIndoorTemperature :temperatureF ?valueF . | 281 :airQualityIndoorTemperature :temperatureF ?valueF . |
282 # } . | 282 } . |
283 # ''') | 283 ''') |
284 # out = inf.infer( | 284 out = inf.infer( |
285 # N3(''' | 285 N3(''' |
286 # <urn:uuid:c6e1d92c-0ee1-11ec-bdbd-2a42c4691e9a> a :MqttMessage ; | 286 <urn:uuid:c6e1d92c-0ee1-11ec-bdbd-2a42c4691e9a> a :MqttMessage ; |
287 # :body "23.9" ; | 287 :body "23.9" ; |
288 # :bodyFloat 2.39e+01 ; | 288 :bodyFloat 2.39e+01 ; |
289 # :topic ( "air_quality_indoor" "sensor" "bme280_temperature" "state" ) . | 289 :topic ( "air_quality_indoor" "sensor" "bme280_temperature" "state" ) . |
290 # ''')) | 290 ''')) |
291 # vlit = cast(Literal, out.value(EX['airQualityIndoorTemperature'], EX['temperatureF'])) | 291 vlit = cast(Literal, out.value(EX['airQualityIndoorTemperature'], EX['temperatureF'])) |
292 # valueF = cast(Decimal, vlit.toPython()) | 292 valueF = cast(Decimal, vlit.toPython()) |
293 # self.assertAlmostEqual(float(valueF), 75.02) | 293 self.assertAlmostEqual(float(valueF), 75.02) |
294 | 294 |
295 def testEmitBnodes(self): | 295 def testEmitBnodes(self): |
296 inf = makeInferenceWithRules(''' | 296 inf = makeInferenceWithRules(''' |
297 { ?s a :AirQualitySensor; :label ?name . } => { | 297 { ?s a :AirQualitySensor; :label ?name . } => { |
298 [ a :MqttStatementSource; | 298 [ a :MqttStatementSource; |
300 } . | 300 } . |
301 ''') | 301 ''') |
302 out = inf.infer(N3(''' | 302 out = inf.infer(N3(''' |
303 :airQualityOutdoor a :AirQualitySensor; :label "air_quality_outdoor" . | 303 :airQualityOutdoor a :AirQualitySensor; :label "air_quality_outdoor" . |
304 ''')) | 304 ''')) |
305 self.assertEqual(out.serialize(format='n3'), b'''@prefix ns1: <http://example.com/> . | 305 out.bind('', ROOM) |
306 out.bind('ex', EX) | |
307 self.assertEqual(out.serialize(format='n3'), b'''@prefix : <http://projects.bigasterisk.com/room/> . | |
308 @prefix ex: <http://example.com/> . | |
306 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . | 309 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . |
307 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | 310 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . |
308 @prefix xml: <http://www.w3.org/XML/1998/namespace> . | 311 @prefix xml: <http://www.w3.org/XML/1998/namespace> . |
309 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | 312 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . |
310 | 313 |
311 [] a ns1:MqttStatementSource ; | 314 [] a ex:MqttStatementSource ; |
312 ns1:mqttTopic ( "air_quality_outdoor" "sensor" "bme280_temperature" "state" ) . | 315 ex:mqttTopic ( "air_quality_outdoor" "sensor" "bme280_temperature" "state" ) . |
313 | 316 |
314 ''') | 317 ''') |
315 | 318 |
316 | 319 |
317 class TestListPerformance(WithGraphEqual): | 320 class TestListPerformance(WithGraphEqual): |