I want to traverse the whole atomspace loaded using Python API. So far I have tried this:
from opencog.atomspace import types
links = atomspace.get_atoms_by_type(types.Link)
#nodes = atomspace.get_atoms_by_type(types.Node)
def traverse_atomspace(lns):
for link in lns:
link_arr = []
traverse_atomspace_helper(link, link_arr)
def traverse_atomspace_helper(link, container):
if len(link.out) == 0:
return
for atom in link.out:
if len(atom.out) != 0: # it is a link by itself
traverse_atomspace_helper(atom, container)
else:
print(atom)
traverse_atomspace(links)
This prints the all the atoms as it traverses through each link. But I was wondering if there is a better way to do it? Can we use pattern matcher functions “natively”? i.e without going through scheme_eval
madness?
atomspace.get_atoms_by_type(types.Atom)
traverse_atomspace_helper`
traverse_atomspace_helper
--
You received this message because you are subscribed to the Google Groups "opencog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to opencog+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/opencog/CA%2B0j2108ZrGFwqrdZcuLAMwy0FDAbE18_ic67dk1WVgRmTiyxA%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ope...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/opencog/CA%2B0j2108ZrGFwqrdZcuLAMwy0FDAbE18_ic67dk1WVgRmTiyxA%40mail.gmail.com.