Mercurial > code > home > repos > homeauto
comparison service/mqtt_to_rdf/inference.py @ 1621:da235054caa0
rename workingSet, sometimes
author | drewp@bigasterisk.com |
---|---|
date | Wed, 08 Sep 2021 18:51:18 -0700 |
parents | 92f8deb59735 |
children | 38bd8ef9ef67 |
comparison
equal
deleted
inserted
replaced
1620:92f8deb59735 | 1621:da235054caa0 |
---|---|
53 self.evaluations = list(Evaluation.findEvals(self.graph)) | 53 self.evaluations = list(Evaluation.findEvals(self.graph)) |
54 | 54 |
55 def __repr__(self): | 55 def __repr__(self): |
56 return f"Lhs({graphDump(self.graph)})" | 56 return f"Lhs({graphDump(self.graph)})" |
57 | 57 |
58 def findCandidateBindings(self, workingSet: ReadOnlyWorkingSet, stats) -> Iterator['BoundLhs']: | 58 def findCandidateBindings(self, knownTrue: ReadOnlyWorkingSet, stats) -> Iterator['BoundLhs']: |
59 """bindings that fit the LHS of a rule, using statements from workingSet and functions | 59 """bindings that fit the LHS of a rule, using statements from workingSet and functions |
60 from LHS""" | 60 from LHS""" |
61 log.debug(f'{INDENT*3} nodesToBind: {self.lhsBindables}') | 61 log.debug(f'{INDENT*3} nodesToBind: {self.lhsBindables}') |
62 stats['findCandidateBindingsCalls'] += 1 | 62 stats['findCandidateBindingsCalls'] += 1 |
63 | 63 |
64 if not self._allStaticStatementsMatch(workingSet): | 64 if not self._allStaticStatementsMatch(knownTrue): |
65 stats['findCandidateBindingEarlyExits'] += 1 | 65 stats['findCandidateBindingEarlyExits'] += 1 |
66 return | 66 return |
67 | 67 |
68 for binding in self._possibleBindings(workingSet, stats): | 68 for binding in self._possibleBindings(knownTrue, stats): |
69 log.debug('') | 69 log.debug('') |
70 log.debug(f'{INDENT*4}*trying {binding.binding}') | 70 log.debug(f'{INDENT*4}*trying {binding.binding}') |
71 | 71 |
72 if not binding.verify(workingSet): | 72 if not binding.verify(knownTrue): |
73 log.debug(f'{INDENT*4} this binding did not verify') | 73 log.debug(f'{INDENT*4} this binding did not verify') |
74 stats['permCountFailingVerify'] += 1 | 74 stats['permCountFailingVerify'] += 1 |
75 continue | 75 continue |
76 | 76 |
77 stats['permCountSucceeding'] += 1 | 77 stats['permCountSucceeding'] += 1 |
78 yield binding | 78 yield binding |
79 | 79 |
80 def _allStaticStatementsMatch(self, workingSet: ReadOnlyWorkingSet) -> bool: | 80 def _allStaticStatementsMatch(self, knownTrue: ReadOnlyWorkingSet) -> bool: |
81 # bug: see TestSelfFulfillingRule.test3 for a case where this rule's | 81 # bug: see TestSelfFulfillingRule.test3 for a case where this rule's |
82 # static stmt is matched by a non-static stmt in the rule itself | 82 # static stmt is matched by a non-static stmt in the rule itself |
83 for ruleStmt in self.staticRuleStmts: | 83 for ruleStmt in self.staticRuleStmts: |
84 if ruleStmt not in workingSet: | 84 if ruleStmt not in knownTrue: |
85 log.debug(f'{INDENT*3} {ruleStmt} not in working set- skip rule') | 85 log.debug(f'{INDENT*3} {ruleStmt} not in working set- skip rule') |
86 return False | 86 return False |
87 return True | 87 return True |
88 | 88 |
89 def _possibleBindings(self, workingSet, stats) -> Iterator['BoundLhs']: | 89 def _possibleBindings(self, workingSet, stats) -> Iterator['BoundLhs']: |