Mercurial > code > home > repos > homeauto
changeset 1653:e7d594c065d4
minor refactoring
author | drewp@bigasterisk.com |
---|---|
date | Sun, 19 Sep 2021 13:20:39 -0700 |
parents | dddfa09ea0b9 |
children | d47832373b34 |
files | service/mqtt_to_rdf/inference.py service/mqtt_to_rdf/stmt_chunk.py |
diffstat | 2 files changed, 11 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/service/mqtt_to_rdf/inference.py Sun Sep 19 13:19:20 2021 -0700 +++ b/service/mqtt_to_rdf/inference.py Sun Sep 19 13:20:39 2021 -0700 @@ -252,9 +252,10 @@ """make ChunkLooper for each stmt in our LHS graph, but do it in a way that they all start out valid (or else raise NoOptions). static chunks have already been confirmed.""" - log.info(f'{INDENT*2} stats={dict(stats)}') - log.info(f'{INDENT*2} taking permutations of {len(self.graph.patternChunks)=}') - for i, perm in enumerate(itertools.permutations(self.graph.patternChunks)): + log.info(f' {INDENT*4} stats={dict(stats)}') + chunks = self.graph.patternChunks.union(self.graph.chunksUsedByFuncs) + log.info(f' {INDENT*4} taking permutations of {len(chunks)=}') + for i, perm in enumerate(itertools.permutations(chunks)): stmtStack: List[ChunkLooper] = [] prev: Optional[ChunkLooper] = None if log.isEnabledFor(logging.DEBUG):
--- a/service/mqtt_to_rdf/stmt_chunk.py Sun Sep 19 13:19:20 2021 -0700 +++ b/service/mqtt_to_rdf/stmt_chunk.py Sun Sep 19 13:20:39 2021 -0700 @@ -27,8 +27,8 @@ """ # all immutable primary: Triple - subjList: Optional[List[Node]] - objList: Optional[List[Node]] + subjList: Optional[List[Node]] = None + objList: Optional[List[Node]] = None def __post_init__(self): self.predicate = self.primary[1] @@ -80,15 +80,15 @@ return bool(list(functionsFor(cast(URIRef, self.predicate)))) def isStatic(self) -> bool: - return (stmtIsStatic(self.primary) and all(termIsStatic(s) for s in (self.subjList or [])) and - all(termIsStatic(s) for s in (self.objList or []))) + return (_stmtIsStatic(self.primary) and all(_termIsStatic(s) for s in (self.subjList or [])) and + all(_termIsStatic(s) for s in (self.objList or []))) -def stmtIsStatic(stmt: Triple) -> bool: - return all(termIsStatic(t) for t in stmt) +def _stmtIsStatic(stmt: Triple) -> bool: + return all(_termIsStatic(t) for t in stmt) -def termIsStatic(term: Node) -> bool: +def _termIsStatic(term: Node) -> bool: return isinstance(term, (URIRef, Literal))