Skip to content

Commit

Permalink
Merge pull request #626 from CICS-Oleg/main
Browse files Browse the repository at this point in the history
dasgate.py updated and test_bio_das.metta added
  • Loading branch information
Necr0x0Der authored Mar 18, 2024
2 parents 0e876e4 + 1878e80 commit 9296781
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
27 changes: 23 additions & 4 deletions python/hyperon/exts/das_gate/dasgate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from hyperon_das import DistributedAtomSpace
from hyperon_das.constants import QueryOutputFormat
import time
import ast

from hyperon_das.pattern_matcher import (
Link,
Expand Down Expand Up @@ -108,19 +109,37 @@ def _handle2atom3(self, h):
elif h['type']=='Expression':
return E(*[self._handle2atom3(ch) for ch in h['targets']])

def _handle2atom4(self, h):
h = self.das.get_atom(h)
if h['type']=='Symbol':
return S(h['name'])
elif h['type']=='Expression':
return E(*[self._handle2atom3(ch) for ch in h['targets']])

def query(self, query_atom):
query = self._atom2dict_new(query_atom)
answer = [query_answer for query_answer in self.das.query(query)]
query_params = {
"toplevel_only": False,
"return_type": QueryOutputFormat.ATOM_INFO,
# 'query_scope': 'local_only',
"no_iterator": False,
}

answer = [query_answer for query_answer in self.das.query(query, query_params)]
new_bindings_set = BindingsSet.empty()

if not answer:
return 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))
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
Expand Down
9 changes: 9 additions & 0 deletions python/integration/test_bio_das.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!(import! &self das_gate)

;!(bind! &das (new-das))
!(bind! &das (new-remote-das (Error "Put your IP here" ()) (Error "Put port number here" ())))


;!(match &das ($t MYBPP) ($t MYBPP))
!(match &das ($t MYBPP) ($t MYBPP))
;!(match &das (protein MYBPP) res)

0 comments on commit 9296781

Please sign in to comment.