# HG changeset patch # User drewp@bigasterisk.com # Date 1631151552 25200 # Node ID e24058ae48069357bfc0d61bfbcc51d587020a84 # Parent e105032b0e3d26bffe688aeba93a92a5b7df71f0 support CB.apply(returnBoundStatementsOnly) diff -r e105032b0e3d -r e24058ae4806 service/mqtt_to_rdf/candidate_binding.py --- a/service/mqtt_to_rdf/candidate_binding.py Mon Sep 06 23:26:07 2021 -0700 +++ b/service/mqtt_to_rdf/candidate_binding.py Wed Sep 08 18:39:12 2021 -0700 @@ -16,20 +16,24 @@ b = " ".join("%s=%s" % (k, v) for k, v in sorted(self.binding.items())) return f'CandidateBinding({b})' - def apply(self, g: Union[Graph, Iterable[Triple]]) -> Iterator[Triple]: + def apply(self, g: Union[Graph, Iterable[Triple]], returnBoundStatementsOnly=True) -> Iterator[Triple]: for stmt in g: try: - bound = (self._applyTerm(stmt[0]), self._applyTerm(stmt[1]), self._applyTerm(stmt[2])) + bound = ( + self._applyTerm(stmt[0], returnBoundStatementsOnly), + self._applyTerm(stmt[1], returnBoundStatementsOnly), + self._applyTerm(stmt[2], returnBoundStatementsOnly)) except BindingUnknown: continue yield bound - def _applyTerm(self, term: Node): + def _applyTerm(self, term: Node, failUnbound=True): if isinstance(term, (Variable, BNode)): if term in self.binding: return self.binding[term] else: - raise BindingUnknown() + if failUnbound: + raise BindingUnknown() return term def addNewBindings(self, newBindings: 'CandidateBinding'):