Skip to content

Commit

Permalink
fetch support added to dasgate.py
Browse files Browse the repository at this point in the history
  • Loading branch information
CICS-Oleg committed Jun 17, 2024
1 parent aff2b9f commit 8475277
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
29 changes: 21 additions & 8 deletions python/hyperon/exts/das_gate/dasgate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class DASpace(AbstractSpace):

def __init__(self, remote=False, host='localhost', port='22', unwrap=True):
super().__init__()
# self.das = DistributedAtomSpace('ram_only')
# self.das = DistributedAtomSpace
self.fetch_flag = False
if remote:
self.das = DistributedAtomSpace(query_engine='remote', host=host, port=port)
self.remote = True
Expand Down Expand Up @@ -163,6 +164,14 @@ def _query_actual_helper_no_iter(self, answer, new_bindings_set):
new_bindings_set.push(bindings)
return new_bindings_set

def _query_fetch_helper(self, answer, new_bindings_set):
for mapping, subgraph in answer:
bindings = Bindings()
for var, val in mapping.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)
Expand All @@ -177,15 +186,19 @@ def query(self, query_atom):
new_bindings_set = BindingsSet.empty()

if not answer:
return new_bindings_set
return

if self.remote:
return self._query_actual_helper(answer, new_bindings_set)
# return self._query_actual_helper_no_iter(answer, new_bindings_set)
# return self._query_temp_helper(answer, new_bindings_set)
if self.fetch_flag:
self.das.fetch()
return self._query_fetch_helper(answer, new_bindings_set)
else:
#return self._query_actual_helper_no_iter(answer, new_bindings_set)
return self._query_actual_helper(answer, new_bindings_set)
if self.remote:
return self._query_actual_helper(answer, new_bindings_set)
# return self._query_actual_helper_no_iter(answer, new_bindings_set)
# return self._query_temp_helper(answer, new_bindings_set)
else:
#return self._query_actual_helper_no_iter(answer, new_bindings_set)
return self._query_actual_helper(answer, new_bindings_set)

# return new_bindings_set

Expand Down
5 changes: 1 addition & 4 deletions python/integration/test_bio_das.metta
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@

;!(match &das ($t MYBPP) ($t MYBPP))
!(match &das ($t MYBPP) ($t MYBPP))
!(match &das (translation_of (protein "O43264") (transcript "ENST00000200135")) OK)
;!(match &das (translation_of (protein "O43264") (transcript "ENST00000200135")) OK)

!(assertEqualToResult
(match &das (translation_of (protein "O43264") (transcript "ENST00000200135")) OK)
())

!(match &das (translation_of (protein O43264) (transcript ENST00000200135)) OK)

Expand Down

0 comments on commit 8475277

Please sign in to comment.