diff service/mqtt_to_rdf/candidate_binding.py @ 1635:22d481f0a924

refactor: use CandidateBinding throughout, not loose dicts
author drewp@bigasterisk.com
date Mon, 13 Sep 2021 00:06:00 -0700
parents ba59cfc3c747
children 0ba1625037ae
line wrap: on
line diff
--- a/service/mqtt_to_rdf/candidate_binding.py	Sun Sep 12 23:48:43 2021 -0700
+++ b/service/mqtt_to_rdf/candidate_binding.py	Mon Sep 13 00:06:00 2021 -0700
@@ -22,9 +22,9 @@
         for stmt in g:
             try:
                 bound = (
-                    self._applyTerm(stmt[0], returnBoundStatementsOnly), 
-                    self._applyTerm(stmt[1], returnBoundStatementsOnly), 
-                    self._applyTerm(stmt[2], returnBoundStatementsOnly))
+                    self.applyTerm(stmt[0], returnBoundStatementsOnly), 
+                    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}')
 
@@ -33,7 +33,7 @@
 
             yield bound
 
-    def _applyTerm(self, term: Node, failUnbound=True):
+    def applyTerm(self, term: Node, failUnbound=True):
         if isinstance(term, (Variable, BNode)):
             if term in self.binding:
                 return self.binding[term]
@@ -47,3 +47,9 @@
             if k in self.binding and self.binding[k] != v:
                 raise ValueError(f'conflict- thought {k} would be {self.binding[k]} but another Evaluation said it should be {v}')
             self.binding[k] = v
+
+    def copy(self):
+        return CandidateBinding(self.binding.copy())
+
+    def contains(self, term: BindableTerm):
+        return term in self.binding
\ No newline at end of file