Mercurial > code > home > repos > homeauto
diff service/mqtt_to_rdf/inference.py @ 1616:3a6ed545357f
optimization: stream stmts instead of building a Graph
author | drewp@bigasterisk.com |
---|---|
date | Mon, 06 Sep 2021 23:23:43 -0700 |
parents | bcfa368e5498 |
children | 48bf62008c82 92f8deb59735 |
line wrap: on
line diff
--- a/service/mqtt_to_rdf/inference.py Mon Sep 06 23:20:23 2021 -0700 +++ b/service/mqtt_to_rdf/inference.py Mon Sep 06 23:23:43 2021 -0700 @@ -174,7 +174,11 @@ self.usedByFuncs = Graph() self._applyFunctions() - self.graphWithoutEvals = self.lhs.graph - self.usedByFuncs + def lhsStmtsWithoutEvals(self): + for stmt in self.lhs.graph: + if stmt in self.usedByFuncs: + continue + yield stmt def _applyFunctions(self): """may grow the binding with some results""" @@ -235,7 +239,7 @@ for bound in self.lhs.findCandidateBindings(ReadOnlyGraphAggregate([workingSet]), stats): log.debug(f'{INDENT*3} rule has a working binding:') - for lhsBoundStmt in bound.binding.apply(bound.graphWithoutEvals): + for lhsBoundStmt in bound.binding.apply(bound.lhsStmtsWithoutEvals()): log.debug(f'{INDENT*5} adding {lhsBoundStmt=}') workingSet.add(lhsBoundStmt) for newStmt in bound.binding.apply(self.rhsGraph):