comparison service/mqtt_to_rdf/inference.py @ 1697:88f6e9bf69d1

stats and non-debug mode speedups
author drewp@bigasterisk.com
date Tue, 28 Sep 2021 00:32:16 -0700
parents cdf706cf5f82
children
comparison
equal deleted inserted replaced
1696:cdf706cf5f82 1697:88f6e9bf69d1
162 162
163 def _testAndKeepNewBinding(self, newBinding: CandidateBinding, sourceChunk: Chunk): 163 def _testAndKeepNewBinding(self, newBinding: CandidateBinding, sourceChunk: Chunk):
164 fullBinding: CandidateBinding = self._prevBindings().copy() 164 fullBinding: CandidateBinding = self._prevBindings().copy()
165 fullBinding.addNewBindings(newBinding) 165 fullBinding.addNewBindings(newBinding)
166 isNew = fullBinding not in self._seenBindings 166 isNew = fullBinding not in self._seenBindings
167 ringlog.debug(f'{INDENT*7} {self} considering {newBinding=} to make {fullBinding}. {isNew=}') 167
168 if ringlog.isEnabledFor(logging.DEBUG):
169 ringlog.debug(f'{INDENT*7} {self} considering {newBinding=} to make {fullBinding}. {isNew=}')
168 # if self.slog: 170 # if self.slog:
169 # self.slog.looperConsider(self, newBinding, fullBinding, isNew) 171 # self.slog.looperConsider(self, newBinding, fullBinding, isNew)
170 172
171 if isNew: 173 if isNew:
172 self._seenBindings.append(fullBinding.copy()) 174 self._seenBindings.append(fullBinding.copy())
324 return looperRings 326 return looperRings
325 if permsTried > 50000: 327 if permsTried > 50000:
326 raise NotImplementedError(f'trying too many permutations {len(chunks)=}') 328 raise NotImplementedError(f'trying too many permutations {len(chunks)=}')
327 permsTried += 1 329 permsTried += 1
328 330
331 stats['permsTried'] += permsTried
329 odolog.debug(f'{INDENT*5} no perms worked- rule cannot match anything') 332 odolog.debug(f'{INDENT*5} no perms worked- rule cannot match anything')
330 raise NoOptions() 333 raise NoOptions()
331 334
332 def _unpartitionedGraphPermutations(self) -> Iterator[Tuple[Chunk, ...]]: 335 def _unpartitionedGraphPermutations(self) -> Iterator[Tuple[Chunk, ...]]:
333 for perm in itertools.permutations(sorted(list(self.graph.patternChunks.union(self.graph.chunksUsedByFuncs)))): 336 for perm in itertools.permutations(sorted(list(self.graph.patternChunks.union(self.graph.chunksUsedByFuncs)))):