Skip to content

Commit

Permalink
Merge pull request #542 from CICS-Oleg/main
Browse files Browse the repository at this point in the history
Add remote das support to dasgate.py
  • Loading branch information
Necr0x0Der authored Jan 25, 2024
2 parents edd23aa + 75585d0 commit 279d550
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
26 changes: 23 additions & 3 deletions python/sandbox/das_gate/dasgate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from hyperon_das import DistributedAtomSpace
from hyperon_das.utils import QueryOutputFormat
import time

from hyperon_das.pattern_matcher import (
Link,
Expand All @@ -17,10 +18,13 @@

class DASpace(AbstractSpace):

def __init__(self, unwrap=True):
def __init__(self, remote=False, host='localhost', port='22', unwrap=True):
super().__init__()
# self.das = DistributedAtomSpace('ram_only')
self.das = DistributedAtomSpace()
if remote:
self.das = DistributedAtomSpace(query_engine='remote', host=host, port=port)
else:
self.das = DistributedAtomSpace()
self.unwrap = unwrap

def _atom2dict(self, atom):
Expand Down Expand Up @@ -90,8 +94,13 @@ def _handle2atom2(self, h):
def query(self, query_atom):
query = self._atom2dict_new(query_atom)

query_params = {
"toplevel_only": False,
"return_type": QueryOutputFormat.ATOM_INFO,
'query_scope': 'local_only'
}
answer = self.das.query(query,
{'return_type': QueryOutputFormat.HANDLE, 'toplevel_only': True})
query_params)
new_bindings_set = BindingsSet.empty()
if not answer:
return new_bindings_set
Expand Down Expand Up @@ -141,6 +150,17 @@ def add(self, atom):
#def atoms_iter(self):
# return iter(self.atoms_list)



def create_new_space(host, port):
return [G(SpaceRef(DASpace(remote=True, host=host.__repr__(), port=port.__repr__())))]

@register_atoms(pass_metta=True)
def my_glob_atoms(metta):
return {
r"new-remote-das": OperationAtom("new-remote-das", create_new_space, unwrap=False),
}

@register_atoms(pass_metta=True)
def das_atoms(metta):
newDASpaceAtom = OperationAtom('new-das', lambda: [G(SpaceRef(DASpace()))], unwrap=False)
Expand Down
3 changes: 2 additions & 1 deletion python/sandbox/das_gate/test_das.metta
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
!(extend-py! dasgate)

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

!(add-atom &das (Test (Test 2)))
!(add-atom &das (Best (Test 2)))
Expand Down

0 comments on commit 279d550

Please sign in to comment.