Mercurial > code > home > repos > homeauto
comparison service/mqtt_to_rdf/stmt_chunk.py @ 1694:73abfd4cf5d0
new html log and other refactoring as i work on the advanceTheStack problems
https://bigasterisk.com/post/inference/2021-09-27_11-11.png
author | drewp@bigasterisk.com |
---|---|
date | Mon, 27 Sep 2021 11:22:09 -0700 |
parents | aa35ae7a1acc |
children | 88f6e9bf69d1 |
comparison
equal
deleted
inserted
replaced
1693:0455a1e18e4f | 1694:73abfd4cf5d0 |
---|---|
55 def matches(self) -> bool: | 55 def matches(self) -> bool: |
56 """could this rule, with its BindableTerm wildcards, match workingSetChunk?""" | 56 """could this rule, with its BindableTerm wildcards, match workingSetChunk?""" |
57 for selfTerm, otherTerm in zip(self.ruleChunk._allTerms(), self.workingSetChunk._allTerms()): | 57 for selfTerm, otherTerm in zip(self.ruleChunk._allTerms(), self.workingSetChunk._allTerms()): |
58 if not isinstance(selfTerm, (Variable, RuleUnboundBnode)) and selfTerm != otherTerm: | 58 if not isinstance(selfTerm, (Variable, RuleUnboundBnode)) and selfTerm != otherTerm: |
59 return False | 59 return False |
60 | |
60 return True | 61 return True |
61 | 62 |
62 | 63 |
63 @dataclass | 64 @dataclass |
64 class Chunk: # rename this | 65 class Chunk: # rename this |
144 | 145 |
145 def _termIsStatic(term: Optional[Node]) -> bool: | 146 def _termIsStatic(term: Optional[Node]) -> bool: |
146 return isinstance(term, (URIRef, Literal)) or term is None | 147 return isinstance(term, (URIRef, Literal)) or term is None |
147 | 148 |
148 | 149 |
149 def applyChunky(cb: CandidateBinding, | 150 def applyChunky(cb: CandidateBinding, g: Iterable[AlignedRuleChunk]) -> Iterator[AlignedRuleChunk]: |
150 g: Iterable[AlignedRuleChunk]) -> Iterator[AlignedRuleChunk]: | |
151 for aligned in g: | 151 for aligned in g: |
152 bound = aligned.ruleChunk.apply(cb) | 152 bound = aligned.ruleChunk.apply(cb) |
153 try: | 153 try: |
154 yield AlignedRuleChunk(bound, aligned.workingSetChunk) | 154 yield AlignedRuleChunk(bound, aligned.workingSetChunk) |
155 except Inconsistent: | 155 except Inconsistent: |
197 s = None | 197 s = None |
198 if o in firstNodes: | 198 if o in firstNodes: |
199 objList = gatherList(o) | 199 objList = gatherList(o) |
200 o = None | 200 o = None |
201 from rdflib import BNode | 201 from rdflib import BNode |
202 if isinstance(s, BNode): s = bnodeType(s) | 202 if isinstance(s, BNode): |
203 if isinstance(p, BNode): p = bnodeType(p) | 203 s = bnodeType(s) |
204 if isinstance(o, BNode): o = bnodeType(o) | 204 if isinstance(p, BNode): |
205 p = bnodeType(p) | |
206 if isinstance(o, BNode): | |
207 o = bnodeType(o) | |
205 | 208 |
206 c = Chunk((s, p, o), subjList=subjList, objList=objList) | 209 c = Chunk((s, p, o), subjList=subjList, objList=objList) |
207 | 210 |
208 if c.isFunctionCall(functionsFor): | 211 if c.isFunctionCall(functionsFor): |
209 self.chunksUsedByFuncs.add(c) | 212 self.chunksUsedByFuncs.add(c) |