diff --git a/python/hyperon/exts/das_gate/dasgate.py b/python/hyperon/exts/das_gate/dasgate.py index e90d18f7a..5844a3a49 100644 --- a/python/hyperon/exts/das_gate/dasgate.py +++ b/python/hyperon/exts/das_gate/dasgate.py @@ -24,7 +24,9 @@ def __init__(self, remote=False, host='localhost', port='22', unwrap=True): # self.das = DistributedAtomSpace('ram_only') if remote: self.das = DistributedAtomSpace(query_engine='remote', host=host, port=port) + self.remote = True else: + self.remote = False self.das = DistributedAtomSpace() self.unwrap = unwrap @@ -116,11 +118,34 @@ def _handle2atom4(self, h): elif h['type']=='Expression': return E(*[self._handle2atom3(ch) for ch in h['targets']]) + def _query_temp_helper(self, answer, new_bindings_set): + for a in answer: + bindings = Bindings() + if a[0] is None: + bindings.add_var_binding("res", self._handle2atom3(a[1])) + else: + mapping = dict(ast.literal_eval(a[0])) + for var, val in mapping.items(): + # remove '$', because it is automatically added + bindings.add_var_binding(V(var[1:]), self._handle2atom4(val)) + new_bindings_set.push(bindings) + return new_bindings_set + + def _query_actual_helper(self, answer, new_bindings_set): + for a in answer: + bindings = Bindings() + for var, val in a.assignment.mapping.items(): + # remove '$', because it is automatically added + bindings.add_var_binding(V(var[1:]), self._handle2atom(val)) + new_bindings_set.push(bindings) + return new_bindings_set + + def query(self, query_atom): query = self._atom2dict_new(query_atom) query_params = { "toplevel_only": False, - "return_type": QueryOutputFormat.ATOM_INFO, + # "return_type": QueryOutputFormat.ATOM_INFO, # 'query_scope': 'local_only', "no_iterator": False, } @@ -131,18 +156,12 @@ def query(self, query_atom): if not answer: return new_bindings_set - for a in answer: - bindings = Bindings() - if a[0] is None: - bindings.add_var_binding("res", self._handle2atom3(a[1])) - else: - mapping = dict(ast.literal_eval(a[0])) - for var, val in mapping.items(): - # remove '$', because it is automatically added - bindings.add_var_binding(V(var[1:]), self._handle2atom4(val)) - new_bindings_set.push(bindings) + if self.remote: + return self._query_temp_helper(answer, new_bindings_set) + else: + return self._query_actual_helper(answer, new_bindings_set) - return new_bindings_set + # return new_bindings_set def query_old(self, query_atom): query = self._atom2query(query_atom)