def test_is_a(self): self.assertTrue(is_a(types.ConceptNode, types.Node)) self.assertTrue(is_a(types.ConceptNode, types.Atom)) self.assertTrue(is_a(types.ListLink, types.Link)) self.assertTrue(is_a(types.ListLink, types.Atom)) self.assertFalse(is_a(types.Link, types.Node))
def to_python(atom: Atom): """Return a Pythonic data representation of an atom""" if is_a(atom.type, AT.ListLink): # HACK: here I just turn lists into numpy arrays because MineRL expects that return np.array([to_python(a) for a in atom.out]) if is_a(atom.type, AT.NumberNode): return float(atom.name) return atom.name
def is_sequential_and(atom: Atom) -> bool: """Return True iff atom is a sequential and. Also for now we use BackSequentialAndLink. """ return is_a(atom.type, get_type("BackSequentialAndLink"))
def is_sequential_and(atom): """Return True iff atom is a sequential and. Also for now we use AltSequentialAndLink. """ return is_a(atom.type, get_type("AltSequentialAndLink"))
def is_virtual(clause: Atom) -> bool: """Return true iff the clause is virtual. For instance (GreaterThanLink (NumberNode "1") (NumberNode "2")) is virtual because it gets evaluated on the fly as opposed to be query against the atomspace. """ # TODO: can be simplified with clause.is_a return is_a(clause.type, types.VirtualLink)
def is_execution(atom: Atom) -> bool: """Return True iff the atom is an ExecutionLink.""" return is_a(atom.type, types.ExecutionLink)
def is_and(atom: Atom) -> bool: """Return True iff the atom is an and link.""" return is_a(atom.type, types.AndLink)
def is_predictive_implication_scope(atom: Atom) -> bool: """Return True iff the atom is a predictive implication scope link.""" return is_a(atom.type, get_type("BackPredictiveImplicationScopeLink"))
def is_scope(atom: Atom) -> bool: """Return True iff the atom is a scope link.""" return is_a(atom.type, types.ScopeLink)
def is_variable_set(atom: Atom) -> bool: """Return True iff the atom is a VariableSet.""" return is_a(atom.type, types.VariableSet)
def is_variable(atom: Atom) -> bool: """Return True iff the atom is a variable node.""" return is_a(atom.type, types.VariableNode)
def is_predictive_implication(atom): """Return True iff the atom is a predictive implication link.""" return is_a(atom.type, get_type("PredictiveImplicationLink"))
#! /usr/bin/env python # # is_a.py # """ A simple example of how to use the nameserver. """ from opencog.atomspace import AtomSpace from opencog.atomspace import get_type, is_a from opencog.atomspace import types from opencog.type_constructors import * a = AtomSpace() # Tell the type constructors which atomspace to use. set_default_atomspace(a) # Is a set unordered set_is_unordered = is_a(get_type("SetLink"), get_type("UnorderedLink")) print("Is a set unordered?", set_is_unordered) # Is A a concept or a predicate? A = ConceptNode("A") print("Is A a concept?", is_a(A.type, get_type("ConceptNode"))) print("Is A a predicate?", is_a(A.type, get_type("PredicateNode")))
def is_predictive_implication_scope(atom): """Return True iff the atom is a predictive implication scope link.""" return is_a(atom.type, types.PredictiveImplicationScopeLink)