diff service/mqtt_to_rdf/inference.py @ 1615:bcfa368e5498

change a Graph.__sub__ to Set.difference in verify() for a big speedup
author drewp@bigasterisk.com
date Mon, 06 Sep 2021 23:20:23 -0700
parents 97b2c3cfdb83
children 3a6ed545357f
line wrap: on
line diff
--- a/service/mqtt_to_rdf/inference.py	Mon Sep 06 23:04:34 2021 -0700
+++ b/service/mqtt_to_rdf/inference.py	Mon Sep 06 23:20:23 2021 -0700
@@ -48,6 +48,8 @@
             else:
                 self.nonStaticRuleStmts.add(ruleStmt)
 
+        self.nonStaticRuleStmtsSet = set(self.nonStaticRuleStmts)
+
         self.evaluations = list(Evaluation.findEvals(self.graph))
 
     def __repr__(self):
@@ -194,7 +196,8 @@
 
     def verify(self, workingSet: ReadOnlyWorkingSet) -> bool:
         """Can this bound lhs be true all at once in workingSet?"""
-        boundLhs = self.binding.apply(self.lhs.nonStaticRuleStmts - self.usedByFuncs)
+        rem = cast(Set[Triple], self.lhs.nonStaticRuleStmtsSet.difference(self.usedByFuncs))
+        boundLhs = self.binding.apply(rem)
 
         if log.isEnabledFor(logging.DEBUG):
             boundLhs = list(boundLhs)