Mercurial > code > home > repos > homeauto
comparison service/reasoning/reasoning.py @ 283:0b0fb67b0b3a
fix input/output statement ambiguity problem by allowing quoted output statements
Ignore-this: 677a7f6bc1df1788c9b12d5fd87e841a
author | drewp@bigasterisk.com |
---|---|
date | Fri, 06 May 2016 18:38:18 -0700 |
parents | 0498634eba17 |
children | 95f72a22965d |
comparison
equal
deleted
inserted
replaced
282:0498634eba17 | 283:0b0fb67b0b3a |
---|---|
40 | 40 |
41 ROOM = Namespace("http://projects.bigasterisk.com/room/") | 41 ROOM = Namespace("http://projects.bigasterisk.com/room/") |
42 DEV = Namespace("http://projects.bigasterisk.com/device/") | 42 DEV = Namespace("http://projects.bigasterisk.com/device/") |
43 | 43 |
44 NS = {'': ROOM, 'dev': DEV} | 44 NS = {'': ROOM, 'dev': DEV} |
45 | 45 |
46 | |
47 def unquoteStatement(graph, stmt): | |
48 # todo: use the standard schema for this, or eliminate | |
49 # it in favor of n3 graph literals. | |
50 return (graph.value(stmt, ROOM['subj']), | |
51 graph.value(stmt, ROOM['pred']), | |
52 graph.value(stmt, ROOM['obj'])) | |
53 | |
54 | |
46 class Reasoning(object): | 55 class Reasoning(object): |
47 def __init__(self): | 56 def __init__(self): |
48 self.prevGraph = None | 57 self.prevGraph = None |
49 self.lastPollTime = 0 | 58 self.lastPollTime = 0 |
50 self.lastError = "" | 59 self.lastError = "" |
102 try: | 111 try: |
103 ruleStatStmts, ruleParseSec = self.updateRules() | 112 ruleStatStmts, ruleParseSec = self.updateRules() |
104 | 113 |
105 g = inputGraph.getGraph() | 114 g = inputGraph.getGraph() |
106 self.inferred = self._makeInferred(g) | 115 self.inferred = self._makeInferred(g) |
116 | |
117 for qs in self.inferred.objects(ROOM['output'], ROOM['statement']): | |
118 self.inferred.add(unquoteStatement(self.inferred, qs)) | |
119 | |
107 [self.inferred.add(s) for s in ruleStatStmts] | 120 [self.inferred.add(s) for s in ruleStatStmts] |
108 | 121 |
109 if oneShot: | 122 if oneShot: |
110 # unclear where this should go, but the oneshot'd | 123 # unclear where this should go, but the oneshot'd |
111 # statements should be just as usable as inferred | 124 # statements should be just as usable as inferred |