comparison service/mqtt_to_rdf/inference.py @ 1598:9e6a593180b6

Evaluation doesn't have to depend on Lhs class
author drewp@bigasterisk.com
date Sun, 05 Sep 2021 22:40:50 -0700
parents 387a9cb66517
children abbf0eb0e640
comparison
equal deleted inserted replaced
1597:387a9cb66517 1598:9e6a593180b6
61 return usedByFuncs 61 return usedByFuncs
62 62
63 def _applyFunctionsIteration(self, lhs, usedByFuncs: Graph): 63 def _applyFunctionsIteration(self, lhs, usedByFuncs: Graph):
64 before = len(self.binding) 64 before = len(self.binding)
65 delta = 0 65 delta = 0
66 for ev in Evaluation.findEvals(lhs): 66 for ev in Evaluation.findEvals(lhs.graph):
67 log.debug(f'{INDENT*3} found Evaluation') 67 log.debug(f'{INDENT*3} found Evaluation')
68 68
69 newBindings, usedGraph = ev.resultBindings(self.binding) 69 newBindings, usedGraph = ev.resultBindings(self.binding)
70 usedByFuncs += usedGraph 70 usedByFuncs += usedGraph
71 self._addNewBindings(newBindings) 71 self._addNewBindings(newBindings)
238 238
239 One Evaluation instance is for one function call. 239 One Evaluation instance is for one function call.
240 """ 240 """
241 241
242 @staticmethod 242 @staticmethod
243 def findEvals(lhs: Lhs) -> Iterator['Evaluation']: 243 def findEvals(graph: Graph) -> Iterator['Evaluation']:
244 for stmt in lhs.graph.triples((None, MATH['sum'], None)): 244 for stmt in graph.triples((None, MATH['sum'], None)):
245 operands, operandsStmts = parseList(lhs.graph, stmt[0]) 245 operands, operandsStmts = parseList(graph, stmt[0])
246 yield Evaluation(operands, stmt, operandsStmts) 246 yield Evaluation(operands, stmt, operandsStmts)
247 247
248 for stmt in lhs.graph.triples((None, MATH['greaterThan'], None)): 248 for stmt in graph.triples((None, MATH['greaterThan'], None)):
249 yield Evaluation([stmt[0], stmt[2]], stmt, []) 249 yield Evaluation([stmt[0], stmt[2]], stmt, [])
250 250
251 for stmt in lhs.graph.triples((None, ROOM['asFarenheit'], None)): 251 for stmt in graph.triples((None, ROOM['asFarenheit'], None)):
252 yield Evaluation([stmt[0]], stmt, []) 252 yield Evaluation([stmt[0]], stmt, [])
253 253
254 # internal, use findEvals 254 # internal, use findEvals
255 def __init__(self, operands: List[Node], mainStmt: Triple, otherStmts: Iterable[Triple]) -> None: 255 def __init__(self, operands: List[Node], mainStmt: Triple, otherStmts: Iterable[Triple]) -> None:
256 self.operands = operands 256 self.operands = operands