comparison 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
comparison
equal deleted inserted replaced
1614:97b2c3cfdb83 1615:bcfa368e5498
45 self.lhsBnodes.update(x for x in varsAndBnodesInStmt if isinstance(x, BNode)) 45 self.lhsBnodes.update(x for x in varsAndBnodesInStmt if isinstance(x, BNode))
46 if not varsAndBnodesInStmt: 46 if not varsAndBnodesInStmt:
47 self.staticRuleStmts.add(ruleStmt) 47 self.staticRuleStmts.add(ruleStmt)
48 else: 48 else:
49 self.nonStaticRuleStmts.add(ruleStmt) 49 self.nonStaticRuleStmts.add(ruleStmt)
50
51 self.nonStaticRuleStmtsSet = set(self.nonStaticRuleStmts)
50 52
51 self.evaluations = list(Evaluation.findEvals(self.graph)) 53 self.evaluations = list(Evaluation.findEvals(self.graph))
52 54
53 def __repr__(self): 55 def __repr__(self):
54 return f"Lhs({graphDump(self.graph)})" 56 return f"Lhs({graphDump(self.graph)})"
192 log.debug(f'{INDENT*4} eval rules made {delta} new bindings') 194 log.debug(f'{INDENT*4} eval rules made {delta} new bindings')
193 return delta 195 return delta
194 196
195 def verify(self, workingSet: ReadOnlyWorkingSet) -> bool: 197 def verify(self, workingSet: ReadOnlyWorkingSet) -> bool:
196 """Can this bound lhs be true all at once in workingSet?""" 198 """Can this bound lhs be true all at once in workingSet?"""
197 boundLhs = self.binding.apply(self.lhs.nonStaticRuleStmts - self.usedByFuncs) 199 rem = cast(Set[Triple], self.lhs.nonStaticRuleStmtsSet.difference(self.usedByFuncs))
200 boundLhs = self.binding.apply(rem)
198 201
199 if log.isEnabledFor(logging.DEBUG): 202 if log.isEnabledFor(logging.DEBUG):
200 boundLhs = list(boundLhs) 203 boundLhs = list(boundLhs)
201 self._logVerifyBanner(boundLhs, workingSet) 204 self._logVerifyBanner(boundLhs, workingSet)
202 205