Skip to content

Commit

Permalink
hot temporary fix for dasgate.py
Browse files Browse the repository at this point in the history
  • Loading branch information
CICS-Oleg committed Mar 19, 2024
1 parent 9296781 commit 190a318
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions python/hyperon/exts/das_gate/dasgate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
}
Expand All @@ -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)
Expand Down

0 comments on commit 190a318

Please sign in to comment.