Mercurial > code > home > repos > homeauto
diff service/mqtt_to_rdf/candidate_binding.py @ 1664:1a7c1261302c
logic fix- some bindings were being returned 2+; some 0 times
author | drewp@bigasterisk.com |
---|---|
date | Mon, 20 Sep 2021 23:19:08 -0700 |
parents | 20474ad4968e |
children | a2347393b43e |
line wrap: on
line diff
--- a/service/mqtt_to_rdf/candidate_binding.py Mon Sep 20 23:15:29 2021 -0700 +++ b/service/mqtt_to_rdf/candidate_binding.py Mon Sep 20 23:19:08 2021 -0700 @@ -21,7 +21,7 @@ binding: Dict[BindableTerm, Node] def __repr__(self): - b = " ".join("%s=%s" % (k, v) for k, v in sorted(self.binding.items())) + b = " ".join("%r=%r" % (var, value) for var, value in sorted(self.binding.items())) return f'CandidateBinding({b})' def apply(self, g: Graph, returnBoundStatementsOnly=True) -> Iterator[Triple]: @@ -32,10 +32,12 @@ self.applyTerm(stmt[1], returnBoundStatementsOnly), # self.applyTerm(stmt[2], returnBoundStatementsOnly)) except BindingUnknown: - log.debug(f'{INDENT*7} CB.apply cant bind {stmt} using {self.binding}') + if log.isEnabledFor(logging.DEBUG): + log.debug(f'{INDENT*7} CB.apply cant bind {stmt} using {self.binding}') continue - log.debug(f'{INDENT*7} CB.apply took {stmt} to {bound}') + if log.isEnabledFor(logging.DEBUG): + log.debug(f'{INDENT*7} CB.apply took {stmt} to {bound}') yield bound @@ -54,6 +56,11 @@ raise BindingConflict(f'thought {k} would be {self.binding[k]} but another Evaluation said it should be {v}') self.binding[k] = v + def subtract(self, removeBindings: 'CandidateBinding'): + for k, v in removeBindings.binding.items(): + if k in self.binding: + del self.binding[k] + def copy(self): return CandidateBinding(self.binding.copy())