Mercurial > code > home > repos > homeauto
comparison service/mqtt_to_rdf/inference.py @ 1638:0ba1625037ae
don't crash, just skip the rule if there's a BindingConflict (no clear test case yet)
author | drewp@bigasterisk.com |
---|---|
date | Mon, 13 Sep 2021 01:53:32 -0700 |
parents | ec3f98d0c1d8 |
children | ae5ca4ba8954 |
comparison
equal
deleted
inserted
replaced
1637:ec3f98d0c1d8 | 1638:0ba1625037ae |
---|---|
12 from prometheus_client import Histogram, Summary | 12 from prometheus_client import Histogram, Summary |
13 from rdflib import RDF, BNode, Graph, Namespace | 13 from rdflib import RDF, BNode, Graph, Namespace |
14 from rdflib.graph import ConjunctiveGraph, ReadOnlyGraphAggregate | 14 from rdflib.graph import ConjunctiveGraph, ReadOnlyGraphAggregate |
15 from rdflib.term import Node, Variable | 15 from rdflib.term import Node, Variable |
16 | 16 |
17 from candidate_binding import CandidateBinding | 17 from candidate_binding import BindingConflict, CandidateBinding |
18 from inference_types import BindingUnknown, ReadOnlyWorkingSet, Triple | 18 from inference_types import BindingUnknown, ReadOnlyWorkingSet, Triple |
19 from lhs_evaluation import functionsFor, lhsStmtsUsedByFuncs | 19 from lhs_evaluation import functionsFor, lhsStmtsUsedByFuncs |
20 | 20 |
21 log = logging.getLogger('infer') | 21 log = logging.getLogger('infer') |
22 INDENT = ' ' | 22 INDENT = ' ' |
337 for b in existingRhsBnodes: | 337 for b in existingRhsBnodes: |
338 | 338 |
339 key = tuple(sorted(bound.binding.binding.items())), b | 339 key = tuple(sorted(bound.binding.binding.items())), b |
340 self.rhsBnodeMap.setdefault(key, BNode()) | 340 self.rhsBnodeMap.setdefault(key, BNode()) |
341 | 341 |
342 bound.binding.addNewBindings(CandidateBinding({b: self.rhsBnodeMap[key]})) | 342 try: |
343 bound.binding.addNewBindings(CandidateBinding({b: self.rhsBnodeMap[key]})) | |
344 except BindingConflict: | |
345 continue | |
343 | 346 |
344 # for lhsBoundStmt in bound.binding.apply(bound.lhsStmtsWithoutEvals()): | 347 # for lhsBoundStmt in bound.binding.apply(bound.lhsStmtsWithoutEvals()): |
345 # log.debug(f'{INDENT*6} adding to workingSet {lhsBoundStmt=}') | 348 # log.debug(f'{INDENT*6} adding to workingSet {lhsBoundStmt=}') |
346 # workingSet.add(lhsBoundStmt) | 349 # workingSet.add(lhsBoundStmt) |
347 # log.debug(f'{INDENT*6} rhsGraph is good: {list(self.rhsGraph)}') | 350 # log.debug(f'{INDENT*6} rhsGraph is good: {list(self.rhsGraph)}') |