comparison 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
comparison
equal deleted inserted replaced
1598:9e6a593180b6 1599:abbf0eb0e640
196 used = sorted(used) 196 used = sorted(used)
197 self.assertEqual(used, [ 197 self.assertEqual(used, [
198 (bn, RDF.first, Literal(0)), 198 (bn, RDF.first, Literal(0)),
199 (bn, RDF.rest, RDF.nil), 199 (bn, RDF.rest, RDF.nil),
200 ]) 200 ])
201
202
203 class TestUseCases(WithGraphEqual):
204
205 def testSimpleTopic(self):
206 inf = makeInferenceWithRules('''
207 { ?msg :body "online" . } => { ?msg :onlineTerm :Online . } .
208 { ?msg :body "offline" . } => { ?msg :onlineTerm :Offline . } .
209
210 {
211 ?msg a :MqttMessage ;
212 :topic :foo;
213 :onlineTerm ?onlineness . } => {
214 :frontDoorLockStatus :connectedStatus ?onlineness .
215 } .
216 ''')
217
218 out = inf.infer(N3('[] a :MqttMessage ; :body "online" ; :topic :foo .'))
219 self.assertIn((EX['frontDoorLockStatus'], EX['connectedStatus'], EX['Online']), out)
220
221 def testTopicIsListhg(self):
222 inf = makeInferenceWithRules('''
223 { ?msg :body "online" . } => { ?msg :onlineTerm :Online . } .
224 { ?msg :body "offline" . } => { ?msg :onlineTerm :Offline . } .
225
226 {
227 ?msg a :MqttMessage ;
228 :topic ( "frontdoorlock" "status" );
229 :onlineTerm ?onlineness . } => {
230 :frontDoorLockStatus :connectedStatus ?onlineness .
231 } .
232 ''')
233
234 out = inf.infer(N3('[] a :MqttMessage ; :body "online" ; :topic ( "frontdoorlock" "status" ) .'))
235 self.assertIn((EX['frontDoorLockStatus'], EX['connectedStatus'], EX['Online']), out)