changeset 1088:0f6128740000

fix input/output statement ambiguity problem by allowing quoted output statements Ignore-this: 677a7f6bc1df1788c9b12d5fd87e841a darcs-hash:1cbae17740cecff867c9bd54d9b9f0f96e58b462
author drewp <drewp@bigasterisk.com>
date Fri, 06 May 2016 18:38:18 -0700
parents 806d2f633775
children cb7fa2f30df9
files service/reasoning/reasoning.py service/reasoning/rules.n3
diffstat 2 files changed, 19 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/service/reasoning/reasoning.py	Fri May 06 17:34:54 2016 -0700
+++ b/service/reasoning/reasoning.py	Fri May 06 18:38:18 2016 -0700
@@ -42,7 +42,16 @@
 DEV = Namespace("http://projects.bigasterisk.com/device/")
 
 NS = {'': ROOM, 'dev': DEV}
-        
+
+
+def unquoteStatement(graph, stmt):
+    # todo: use the standard schema for this, or eliminate
+    # it in favor of n3 graph literals.
+    return (graph.value(stmt, ROOM['subj']),
+            graph.value(stmt, ROOM['pred']),
+            graph.value(stmt, ROOM['obj']))
+
+
 class Reasoning(object):
     def __init__(self):
         self.prevGraph = None
@@ -104,6 +113,10 @@
             
             g = inputGraph.getGraph()
             self.inferred = self._makeInferred(g)
+
+            for qs in self.inferred.objects(ROOM['output'], ROOM['statement']):
+                self.inferred.add(unquoteStatement(self.inferred, qs))
+            
             [self.inferred.add(s) for s in ruleStatStmts]
 
             if oneShot:
--- a/service/reasoning/rules.n3	Fri May 06 17:34:54 2016 -0700
+++ b/service/reasoning/rules.n3	Fri May 06 18:38:18 2016 -0700
@@ -141,11 +141,14 @@
 } .
 
 { bed:redButton :buttonState :press . :headboardWhite :brightness 0.0 . } => {
-  :headboardWhite :brightness 0.2 .
+  # Desired:
+  #   :output :subgraph { :headboardWhite :brightness 0.2 }
+  # but I haven't been able to extract the inner graph triples yet.
+  :output :statement [ :subj :headboardWhite; :pred :brightness; :obj 0.2 ] . 
 } .
 
 { bed:redButton :buttonState :press . :headboardWhite :brightness 0.2 . } => {
-  :headboardWhite :brightness 1 .
+  :output :statement [ :subj :headboardWhite; :pred :brightness; :obj 1 ] .
 } .
 
 @prefix sensor:   <http://bigasterisk.com/homeauto/sensor/> .