diff service/mqtt_to_rdf/inference_test.py @ 1599:abbf0eb0e640

fix a bug with a slightly moer complicated set of rules
author drewp@bigasterisk.com
date Sun, 05 Sep 2021 22:43:13 -0700
parents 413a280828bf
children 89a50242cb5e
line wrap: on
line diff
--- a/service/mqtt_to_rdf/inference_test.py	Sun Sep 05 22:40:50 2021 -0700
+++ b/service/mqtt_to_rdf/inference_test.py	Sun Sep 05 22:43:13 2021 -0700
@@ -198,3 +198,38 @@
             (bn, RDF.first, Literal(0)),
             (bn, RDF.rest, RDF.nil),
         ])
+
+
+class TestUseCases(WithGraphEqual):
+
+    def testSimpleTopic(self):
+        inf = makeInferenceWithRules('''
+{ ?msg :body "online" . } => { ?msg :onlineTerm :Online . } .
+ { ?msg :body "offline" . } => { ?msg :onlineTerm :Offline . } .
+
+{
+  ?msg a :MqttMessage ;
+     :topic :foo;
+     :onlineTerm ?onlineness . } => {
+  :frontDoorLockStatus :connectedStatus ?onlineness .
+} .
+        ''')
+
+        out = inf.infer(N3('[] a :MqttMessage ; :body "online" ; :topic :foo .'))
+        self.assertIn((EX['frontDoorLockStatus'], EX['connectedStatus'], EX['Online']), out)
+
+    def testTopicIsListhg(self):
+        inf = makeInferenceWithRules('''
+{ ?msg :body "online" . } => { ?msg :onlineTerm :Online . } .
+{ ?msg :body "offline" . } => { ?msg :onlineTerm :Offline . } .
+
+{
+  ?msg a :MqttMessage ;
+     :topic ( "frontdoorlock" "status" );
+     :onlineTerm ?onlineness . } => {
+  :frontDoorLockStatus :connectedStatus ?onlineness .
+} .
+        ''')
+
+        out = inf.infer(N3('[] a :MqttMessage ; :body "online" ; :topic ( "frontdoorlock" "status" ) .'))
+        self.assertIn((EX['frontDoorLockStatus'], EX['connectedStatus'], EX['Online']), out)