# HG changeset patch # User drewp@bigasterisk.com # Date 1462585098 25200 # Node ID 0b0fb67b0b3a11d6d230358e1608cadb5ea70616 # Parent 0498634eba17d5349b54b7aa1dc27c4a8bfddb1f fix input/output statement ambiguity problem by allowing quoted output statements Ignore-this: 677a7f6bc1df1788c9b12d5fd87e841a diff -r 0498634eba17 -r 0b0fb67b0b3a service/reasoning/reasoning.py --- 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: diff -r 0498634eba17 -r 0b0fb67b0b3a service/reasoning/rules.n3 --- 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: .