changeset 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 e105032b0e3d
files service/mqtt_to_rdf/inference.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
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):