comparison service/mqtt_to_rdf/inference.py @ 1693:0455a1e18e4f

really rough fix to a broken test. hopefully this gets redone
author drewp@bigasterisk.com
date Sat, 25 Sep 2021 22:20:42 -0700
parents 2883da14847c
children 73abfd4cf5d0
comparison
equal deleted inserted replaced
1692:2883da14847c 1693:0455a1e18e4f
83 last restart), or go into pastEnd mode. Note that _current is just our 83 last restart), or go into pastEnd mode. Note that _current is just our
84 contribution, but returned valid bindings include all prev rings.""" 84 contribution, but returned valid bindings include all prev rings."""
85 if self._pastEnd: 85 if self._pastEnd:
86 raise NotImplementedError('need restart') 86 raise NotImplementedError('need restart')
87 ringlog.debug('') 87 ringlog.debug('')
88 self._currentIsFromFunc = None
88 augmentedWorkingSet: List[AlignedRuleChunk] = [] 89 augmentedWorkingSet: List[AlignedRuleChunk] = []
89 if self.prev is None: 90 if self.prev is None:
90 augmentedWorkingSet = self._alignedMatches 91 augmentedWorkingSet = self._alignedMatches
91 else: 92 else:
92 augmentedWorkingSet = list(applyChunky(self.prev.currentBinding(), self._alignedMatches)) 93 augmentedWorkingSet = list(applyChunky(self.prev.currentBinding(), self._alignedMatches))
137 log.debug(f'...makes {newBinding=}') 138 log.debug(f'...makes {newBinding=}')
138 except BindingUnknown: 139 except BindingUnknown:
139 pass 140 pass
140 else: 141 else:
141 if newBinding is not None: 142 if newBinding is not None:
143 self._currentIsFromFunc = fn
142 if self._testAndKeepNewBinding(newBinding): 144 if self._testAndKeepNewBinding(newBinding):
143 return True 145 return True
144 146
145 return False 147 return False
146 148
180 self._pastEnd = False 182 self._pastEnd = False
181 self._seenBindings = [] 183 self._seenBindings = []
182 self.advance() 184 self.advance()
183 if self.pastEnd(): 185 if self.pastEnd():
184 raise NoOptions() 186 raise NoOptions()
187
188 def prevMayHaveChanged(self):
189 # This is a total patch for a test failure. This should be generalized
190 # to a Looper that can keep itself correct when prev changes.
191 if self._currentIsFromFunc:
192 self._advanceWithFunctions()
193 if self.pastEnd():
194 self.restart()
185 195
186 196
187 @dataclass 197 @dataclass
188 class Lhs: 198 class Lhs:
189 graph: ChunkedGraph # our full LHS graph, as input. See below for the statements partitioned into groups. 199 graph: ChunkedGraph # our full LHS graph, as input. See below for the statements partitioned into groups.
322 for funcPart in itertools.permutations(funcs) if funcs else [tupleOfNoChunks]: 332 for funcPart in itertools.permutations(funcs) if funcs else [tupleOfNoChunks]:
323 perm = patternPart + funcPart 333 perm = patternPart + funcPart
324 yield perm 334 yield perm
325 335
326 def _advanceTheStack(self, looperRings: List[ChunkLooper]) -> bool: 336 def _advanceTheStack(self, looperRings: List[ChunkLooper]) -> bool:
337
338 def freshenRight(i):
339 for ring in looperRings[i + 1:]:
340 ring.prevMayHaveChanged()
341
327 carry = True # last elem always must advance 342 carry = True # last elem always must advance
328 for i, ring in reversed(list(enumerate(looperRings))): 343 for i, ring in reversed(list(enumerate(looperRings))):
329 # unlike normal odometer, advancing any earlier ring could invalidate later ones 344 # unlike normal odometer, advancing any earlier ring could invalidate later ones
330 if carry: 345 if carry:
331 odolog.debug(f'{INDENT*4} advanceAll [ring={i}] {ring} carry/advance') 346 odolog.debug(f'{INDENT*4} advanceAll [ring={i}] {ring} carry/advance')
332 ring.advance() 347 ring.advance()
348 freshenRight(i)
333 carry = False 349 carry = False
334 if ring.pastEnd(): 350 if ring.pastEnd():
335 if ring is looperRings[0]: 351 if ring is looperRings[0]:
336 allRingsDone = [r.pastEnd() for r in looperRings] 352 allRingsDone = [r.pastEnd() for r in looperRings]
337 odolog.debug(f'{INDENT*5} advanceAll [ring={i}] {ring} says we done {allRingsDone=}') 353 odolog.debug(f'{INDENT*5} advanceAll [ring={i}] {ring} says we done {allRingsDone=}')
338 return True 354 return True
339 odolog.debug(f'{INDENT*5} advanceAll [ring={i}] {ring} restart') 355 odolog.debug(f'{INDENT*5} advanceAll [ring={i}] {ring} restart')
340 ring.restart() 356 ring.restart()
357 freshenRight(i)
341 carry = True 358 carry = True
342 return False 359 return False
343 360
344 def _assertAllRingsAreValid(self, looperRings): 361 def _assertAllRingsAreValid(self, looperRings):
345 if any(ring.pastEnd() for ring in looperRings): # this is an unexpected debug assertion 362 if any(ring.pastEnd() for ring in looperRings): # this is an unexpected debug assertion