comparison service/mqtt_to_rdf/inference.py @ 1695:5c2565e63297

take out some misduided fixes
author drewp@bigasterisk.com
date Mon, 27 Sep 2021 22:55:32 -0700
parents 73abfd4cf5d0
children cdf706cf5f82
comparison
equal deleted inserted replaced
1694:73abfd4cf5d0 1695:5c2565e63297
198 if self.pastEnd(): 198 if self.pastEnd():
199 raise NoOptions() 199 raise NoOptions()
200 finally: 200 finally:
201 debug(ringlog, self.slog, f'{INDENT*7} ChunkLooper{self._shortId} restarts: pastEnd={self.pastEnd()}') 201 debug(ringlog, self.slog, f'{INDENT*7} ChunkLooper{self._shortId} restarts: pastEnd={self.pastEnd()}')
202 202
203 def prevMayHaveChanged(self):
204 pass
205 # self._advanceWithFunctions()
206 # This is a total patch for a test failure. This should be generalized
207 # to a Looper that can keep itself correct when prev changes.
208 # if self.pastEnd():
209 # self.restart()
210 # else:
211 # self.advance()
212 # if self._currentIsFromFunc:
213 # self._advanceWithFunctions()
214 # if self.pastEnd():
215 # self.restart()
216
217 203
218 @dataclass 204 @dataclass
219 class Lhs: 205 class Lhs:
220 graph: ChunkedGraph # our full LHS graph, as input. See below for the statements partitioned into groups. 206 graph: ChunkedGraph # our full LHS graph, as input. See below for the statements partitioned into groups.
221 207
223 209
224 self.myPreds = self.graph.allPredicatesExceptFunctions() 210 self.myPreds = self.graph.allPredicatesExceptFunctions()
225 211
226 def __repr__(self): 212 def __repr__(self):
227 return f"Lhs({self.graph!r})" 213 return f"Lhs({self.graph!r})"
214
228 def findCandidateBindings(self, knownTrue: ChunkedGraph, stats, slog: Optional[StructuredLog], 215 def findCandidateBindings(self, knownTrue: ChunkedGraph, stats, slog: Optional[StructuredLog],
229 ruleStatementsIterationLimit) -> Iterator['BoundLhs']: 216 ruleStatementsIterationLimit) -> Iterator['BoundLhs']:
230 """distinct bindings that fit the LHS of a rule, using statements from 217 """distinct bindings that fit the LHS of a rule, using statements from
231 workingSet and functions from LHS""" 218 workingSet and functions from LHS"""
232 if not self.graph: 219 if not self.graph:
360 perm = patternPart + funcPart 347 perm = patternPart + funcPart
361 yield perm 348 yield perm
362 349
363 def _advanceTheStack(self, looperRings: List[ChunkLooper]) -> bool: 350 def _advanceTheStack(self, looperRings: List[ChunkLooper]) -> bool:
364 351
365 def freshenRight(i):
366 for ring in looperRings[i + 1:]:
367 ring.prevMayHaveChanged()
368
369 carry = True # last elem always must advance 352 carry = True # last elem always must advance
370 for i, ring in reversed(list(enumerate(looperRings))): 353 for i, ring in reversed(list(enumerate(looperRings))):
371 # unlike normal odometer, advancing any earlier ring could invalidate later ones 354 # unlike normal odometer, advancing any earlier ring could invalidate later ones
372 if carry: 355 if carry:
373 odolog.debug(f'{INDENT*4} advanceAll [ring={i}] {ring} carry/advance') 356 odolog.debug(f'{INDENT*4} advanceAll [ring={i}] {ring} carry/advance')
374 ring.advance() 357 ring.advance()
375 freshenRight(i)
376 carry = False 358 carry = False
377 if ring.pastEnd(): 359 if ring.pastEnd():
378 if ring is looperRings[0]: 360 if ring is looperRings[0]:
379 allRingsDone = [r.pastEnd() for r in looperRings] 361 allRingsDone = [r.pastEnd() for r in looperRings]
380 odolog.debug(f'{INDENT*5} advanceAll [ring={i}] {ring} says we done {allRingsDone=}') 362 odolog.debug(f'{INDENT*5} advanceAll [ring={i}] {ring} says we done {allRingsDone=}')
381 return True 363 return True
382 odolog.debug(f'{INDENT*5} advanceAll [ring={i}] {ring} restart') 364 odolog.debug(f'{INDENT*5} advanceAll [ring={i}] {ring} restart')
383 ring.restart() 365 ring.restart()
384 freshenRight(i)
385 carry = True 366 carry = True
386 return False 367 return False
387 368
388 def _assertAllRingsAreValid(self, looperRings): 369 def _assertAllRingsAreValid(self, looperRings):
389 if any(ring.pastEnd() for ring in looperRings): # this is an unexpected debug assertion 370 if any(ring.pastEnd() for ring in looperRings): # this is an unexpected debug assertion