Ejemplo n.º 1
0
def test_add_nodes_scheme(atomspace, prep_handle):
    """Add n nodes in atomspace using scheme"""
    n = 10000
    for i in xrange(n):
        scheme = "cog-new-node 'ConceptNode \"" + str(i) + '" (cog-new-stv 0.5 0.5)'
        scheme_eval_h(atomspace, scheme)
    return n
Ejemplo n.º 2
0
def test_add_nodes_sugar(atomspace, prep_atom):
    """Add n nodes in atomspace using scheme with syntactic sugar"""
    n = 10000
    for i in xrange(n):
        scheme = '\'ConceptNode "' + str(i) + '" (cog-new-stv 0.5 0.5)'
        scheme_eval_h(atomspace, scheme)
    return n
Ejemplo n.º 3
0
def test_add_nodes_sugar(atomspace, prep_atom):
    """Add n nodes in atomspace using scheme with syntactic sugar"""
    n = 10000
    for i in xrange(n):
        scheme = '\'ConceptNode "' + str(i) + '" (cog-new-stv 0.5 0.5)'
        scheme_eval_h(atomspace, scheme)
    return n
Ejemplo n.º 4
0
def prep_predicates(atomspace):
    for scheme_file in scheme_preload:
        load_scm(atomspace, scheme_file)

    # Define dogs relationships
    scheme_dog_predicates = \
        '''
        (EvaluationLink
            (PredicateNode "IsA")
            (ListLink
                (ConceptNode "dog")
                (ConceptNode "mammal")
            )
        )
        (EvaluationLink
            (PredicateNode "IsA")
            (ListLink
                (ConceptNode "dog")
                (ConceptNode "animal")
            )
        )
        (EvaluationLink
            (PredicateNode "Loves")
            (ListLink
                (ConceptNode "dog")
                (ConceptNode "biscuits")
            )
        )
        '''
    scheme_eval_h(atomspace, scheme_dog_predicates)
    dog = atomspace.add_node(types.ConceptNode, "dog")
    isA = atomspace.add_node(types.PredicateNode, "IsA")
    return dog, isA
Ejemplo n.º 5
0
def prep_predicates(atomspace):
    for scheme_file in scheme_preload:
        load_scm(atomspace, scheme_file)

    # Define dogs relationships
    scheme_dog_predicates = \
        '''
        (EvaluationLink
            (PredicateNode "IsA")
            (ListLink
                (ConceptNode "dog")
                (ConceptNode "mammal")
            )
        )
        (EvaluationLink
            (PredicateNode "IsA")
            (ListLink
                (ConceptNode "dog")
                (ConceptNode "animal")
            )
        )
        (EvaluationLink
            (PredicateNode "Loves")
            (ListLink
                (ConceptNode "dog")
                (ConceptNode "biscuits")
            )
        )
        '''
    scheme_eval_h(atomspace, scheme_dog_predicates)
    dog = atomspace.add_node(types.ConceptNode, "dog")
    isA = atomspace.add_node(types.PredicateNode, "IsA")
    return dog, isA
Ejemplo n.º 6
0
    def setUp(self):
        self.atomspace = AtomSpace()
        scheme.__init__(self.atomspace)
        for scheme_file in scheme_preload:
            load_scm(self.atomspace, scheme_file)
        
        # Define several animals and something of a different type as well
        scheme_animals = \
            '''
            (InheritanceLink (ConceptNode "Frog") (ConceptNode "animal"))
            (InheritanceLink (ConceptNode "Zebra") (ConceptNode "animal"))
            (InheritanceLink (ConceptNode "Deer") (ConceptNode "animal"))
            (InheritanceLink (ConceptNode "Spaceship") (ConceptNode "machine"))
            '''
        scheme_eval_h(self.atomspace, scheme_animals)

        # Define a graph search query
        bind_link_query = \
            '''
            (BindLink
                ;; The variable to be grounded
                (VariableNode "$var")
                (ImplicationLink
                    ;; The pattern to be grounded
                    (InheritanceLink
                        (VariableNode "$var")
                        (ConceptNode "animal")
                    )
                    ;; The grounding to be returned.
                    (VariableNode "$var")
                )
            )
            '''
        self.bindlink_handle = scheme_eval_h(self.atomspace, bind_link_query)
Ejemplo n.º 7
0
    def setUp(self):
        self.atomspace = AtomSpace()
        scheme.__init__(self.atomspace)
        for scheme_file in scheme_preload:
            load_scm(self.atomspace, scheme_file)

        # Define several animals and something of a different type as well
        scheme_animals = \
            '''
            (InheritanceLink (ConceptNode "Frog") (ConceptNode "animal"))
            (InheritanceLink (ConceptNode "Zebra") (ConceptNode "animal"))
            (InheritanceLink (ConceptNode "Deer") (ConceptNode "animal"))
            (InheritanceLink (ConceptNode "Spaceship") (ConceptNode "machine"))
            '''
        scheme_eval_h(self.atomspace, scheme_animals)

        # Define a graph search query
        bind_link_query = \
            '''
            (BindLink
                ;; The variable to be bound
                (VariableNode "$var")
                (ImplicationLink
                    ;; The pattern to be searched for
                    (InheritanceLink
                        (VariableNode "$var")
                        (ConceptNode "animal")
                    )
                    ;; The value to be returned.
                    (VariableNode "$var")
                )
            )
            '''
        self.bindlink_handle = scheme_eval_h(self.atomspace, bind_link_query)
Ejemplo n.º 8
0
def test_add_nodes_scheme(atomspace, prep_atom):
    """Add n nodes in atomspace using scheme"""
    n = 10000
    for i in xrange(n):
        scheme = 'cog-new-node \'ConceptNode "' + str(i) + \
                '" (cog-new-stv 0.5 0.5)'
        scheme_eval_h(atomspace, scheme)
    return n
Ejemplo n.º 9
0
    def test_unifier(self):

        scheme_eval(self.space, "(use-modules (opencog exec))")
        question = scheme_eval_h(self.space, "find-animals")
        self.assertTrue(question)
        print ("\nThe question is:", question)

        answer = scheme_eval_h(self.space, "(cog-execute! find-animals)")
        self.assertTrue(answer)
        print ("\nThe answer is:", answer)
        self.assertEqual(answer.type, types.SetLink)
        self.assertEqual(answer.arity, 3)
Ejemplo n.º 10
0
    def test_unifier(self):

        scheme_eval(self.space, "(use-modules (opencog exec))")
        question = scheme_eval_h(self.space, "find-animals")
        self.assertTrue(question)
        print("\nThe question is:", question)

        answer = scheme_eval_h(self.space, "(cog-execute! find-animals)")
        self.assertTrue(answer)
        print("\nThe answer is:", answer)
        self.assertEqual(answer.type, types.SetLink)
        self.assertEqual(answer.arity, 3)
Ejemplo n.º 11
0
def prep_bind(atomspace):
    scheme.__init__(atomspace)
    for scheme_file in scheme_preload:
        load_scm(atomspace, scheme_file)

    # Define several animals and something of a different type as well
    scheme_animals = """
        (InheritanceLink (ConceptNode "Frog") (ConceptNode "animal"))
        (InheritanceLink (ConceptNode "Zebra") (ConceptNode "animal"))
        (InheritanceLink (ConceptNode "Deer") (ConceptNode "animal"))
        (InheritanceLink (ConceptNode "Spaceship") (ConceptNode "machine"))
        """
    scheme_eval_h(atomspace, scheme_animals)
Ejemplo n.º 12
0
def prep_bind(atomspace):
    for scheme_file in scheme_preload:
        load_scm(atomspace, scheme_file)

    # Define several animals and something of a different type as well
    scheme_animals = \
        '''
        (InheritanceLink (ConceptNode "Frog") (ConceptNode "animal"))
        (InheritanceLink (ConceptNode "Zebra") (ConceptNode "animal"))
        (InheritanceLink (ConceptNode "Deer") (ConceptNode "animal"))
        (InheritanceLink (ConceptNode "Spaceship") (ConceptNode "machine"))
        '''
    scheme_eval_h(atomspace, scheme_animals)
Ejemplo n.º 13
0
    def test_unifier(self):

        scheme_eval(self.space, "(use-modules (opencog query))")
        question = scheme_eval_h(self.space, "find-animals")
        self.assertTrue(question)
        print "\nThe question is:"
        print question

        answer = scheme_eval_h(self.space, "(cog-bind find-animals)")
        self.assertTrue(answer)
        print "\nThe answer is:"
        print answer
        self.assertEqual(answer.type, types.SetLink)
        self.assertEqual(answer.arity, 3)
Ejemplo n.º 14
0
    def test_unifier(self):

        scheme_eval(self.space, "(use-modules (opencog query))")
        question = scheme_eval_h(self.space, "find-animals")
        self.assertTrue(question)
        print "\nThe question is:"
        print question

        answer = scheme_eval_h(self.space, "(cog-bind find-animals)")
        self.assertTrue(answer)
        print "\nThe answer is:"
        print answer
        self.assertEqual(answer.type, types.SetLink)
        self.assertEqual(answer.arity, 3)
Ejemplo n.º 15
0
def prep_bind(atomspace):
    for scheme_file in scheme_preload:
        load_scm(atomspace, scheme_file)
    scheme_eval(atomspace, "(use-modules (opencog))")
    scheme_eval(atomspace, "(use-modules (opencog query))")

    # Define several animals and something of a different type as well
    scheme_animals = \
        '''
        (InheritanceLink (ConceptNode "Frog") (ConceptNode "animal"))
        (InheritanceLink (ConceptNode "Zebra") (ConceptNode "animal"))
        (InheritanceLink (ConceptNode "Deer") (ConceptNode "animal"))
        (InheritanceLink (ConceptNode "Spaceship") (ConceptNode "machine"))
        '''
    scheme_eval_h(atomspace, scheme_animals)
Ejemplo n.º 16
0
    def test_unifier(self):
        h = scheme_eval_h(self.space, "cap-deduce")
        self.assertTrue(h)
        print "\nThe question is:"
        print h
        question = Atom(h, self.space)
        print question

        h = scheme_eval_h(self.space, "(cog-bind cap-deduce)")
        self.assertTrue(h)
        print h
        answer = Atom(h, self.space)
        print "\nThe answer is:"
        print answer
        self.assertEqual(answer.type, types.ListLink)
        self.assertEqual(answer.arity, 2)
Ejemplo n.º 17
0
 def test_create_node(self): #params as (self,type) , to test each and every kind of Atoms
   #creating a node 
   self.node_hello = self.atsp.add_node(types.ConceptNode,"HelloWorld")
   #testing if node is created 
   self.test_node_hello =scheme_eval_h(self.atsp, "(ConceptNode \"HelloWorld\")")
   self.assertEqual(self.test_node_hello,self.node_hello)
   self.assertIsInstance(node,Atom)
Ejemplo n.º 18
0
    def create_chainer(self, atomspace, stimulate_atoms=True):
        """
        Creates the chainer for the "smokes" example. Optionally, you can
         define the target query before calling this method, by defining a
         Scheme expression named "query". For example, you can issue the
         Scheme expression "(define query hasCancer)" in reference to the
         predicate defined in smokes.scm before loading this agent. Once
         defined, the target query will receive stimulus at every time step.
         Stimulus requires the agent to be running in a CogServer.
         For a complete example that incorporates this behavior, see
         example.py here:
           https://github.com/opencog/external-tools/tree/master/attention
        """
        self.chainer = Chainer(atomspace,
                               agent=self,
                               stimulateAtoms=stimulate_atoms,
                               allow_output_with_variables=False,
                               preferAttentionalFocus=True,
                               delete_temporary_variables=True)

        # ModusPonens:
        # Implication smokes(x) cancer(X)
        # smokes(Anna)
        # |= cancer(Anna)
        self.chainer.add_rule(
            ModusPonensRule(self.chainer, types.ImplicationLink))

        # stimulateAtoms is only enabled when the agent is ran inside the
        # CogServer, since the functionality requires a CogServer and
        # attention allocation
        if self.chainer._stimulateAtoms:
            self.query = scheme_eval_h(atomspace, "query")
Ejemplo n.º 19
0
    def get_members_of_old(self, geneset):
        """
        deprecated: using python instead of pattern matcher now b/c it's faster
        """
        # cache members of geneset
        if geneset not in self.set_members_dict:
            bindlink_query = \
                '''
                (BindLink
                    (VariableNode "$member")
                    (ImplicationLink
                        (MemberLink
                            (VariableNode "$member")
                            (ConceptNode {0}))
                        (VariableNode "$member")))
            '''.format('"' + geneset.name.strip() + '"')
            bindlink_h = scheme_eval_h(self.atomspace, bindlink_query)
            results_h = bindlink(self.a, bindlink_h)
            genes = self.set_members_dict[geneset] \
                = set(atoms_in_listlink_h(self.a, results_h))

            # or, using scheme (cog-bind) method
            # self.set_members_dict[geneset] = set(scheme_eval_list(
            #     self.a,'(get_members_of "' + geneset.name + '")'))
        else:
            genes = self.set_members_dict[geneset]
        return genes
Ejemplo n.º 20
0
    def get_members_of_old(self, geneset):
        """
        deprecated: using python instead of pattern matcher now b/c it's faster
        """
        # cache members of geneset
        if geneset not in self.set_members_dict:
            bindlink_query = \
                '''
                (BindLink
                    (VariableNode "$member")
                    (ImplicationLink
                        (MemberLink
                            (VariableNode "$member")
                            (ConceptNode {0}))
                        (VariableNode "$member")))
            '''.format('"' + geneset.name.strip() + '"')
            bindlink_h = scheme_eval_h(self.atomspace, bindlink_query)
            results_h = bindlink(self.a, bindlink_h)
            genes = self.set_members_dict[geneset] \
                = set(atoms_in_listlink_h(self.a, results_h))

            # or, using scheme (cog-bind) method
            # self.set_members_dict[geneset] = set(scheme_eval_list(
            #     self.a,'(get_members_of "' + geneset.name + '")'))
        else:
            genes = self.set_members_dict[geneset]
        return genes
Ejemplo n.º 21
0
    def create_chainer(self, atomspace, stimulate_atoms=True):
        """
        Creates the chainer for the "smokes" example. Optionally, you can
         define the target query before calling this method, by defining a
         Scheme expression named "query". For example, you can issue the
         Scheme expression "(define query hasCancer)" in reference to the
         predicate defined in smokes.scm before loading this agent. Once
         defined, the target query will receive stimulus at every time step.
         Stimulus requires the agent to be running in a CogServer.
         For a complete example that incorporates this behavior, see
         example.py here:
           https://github.com/opencog/external-tools/tree/master/attention
        """
        self.chainer = Chainer(
            atomspace,
            agent=self,
            stimulateAtoms=stimulate_atoms,
            allow_output_with_variables=False,
            preferAttentionalFocus=True,
            delete_temporary_variables=True,
        )

        # ModusPonens:
        # Implication smokes(x) cancer(X)
        # smokes(Anna)
        # |= cancer(Anna)
        self.chainer.add_rule(ModusPonensRule(self.chainer, types.ImplicationLink))

        # stimulateAtoms is only enabled when the agent is ran inside the
        # CogServer, since the functionality requires a CogServer and
        # attention allocation
        if self.chainer._stimulateAtoms:
            self.query = scheme_eval_h(atomspace, "query")
Ejemplo n.º 22
0
    def test_unifier(self):
        h = scheme_eval_h(self.space, "cap-deduce")
        self.assertTrue(h)
        print "\nThe question is:"
        print h
        question = Atom(h, self.space)
        print question

        h = scheme_eval_h(self.space, "(cog-bind cap-deduce)")
        self.assertTrue(h)
        print h
        answer = Atom(h, self.space)
        print "\nThe answer is:"
        print answer
        self.assertEqual(answer.type, types.SetLink)
        self.assertEqual(answer.arity, 2)
Ejemplo n.º 23
0
 def get_nearest_neighbors(self, longitude, latitude, distance):
     longitude = float(longitude.name)
     latitude = float(latitude.name)
     distance = float(distance.name)
     result = self.db.get_nearest_neighbors(longitude, latitude, distance)
     nearest = list(map(lambda r: scheme_eval_h(self.space, r.atom),
                        result))
     return SetLink(*nearest)
Ejemplo n.º 24
0
 def get_location_by_time(self, time):
     time = float(time.name)
     result = self.db.get_location(time)
     atom = scheme_eval_h(self.space, result[0].atom)
     r = EvaluationLink(
         PredicateNode("locatedAt"),
         ListLink(atom, NumberNode(str(result[1])),
                  NumberNode(str(result[2]))))
     return r
Ejemplo n.º 25
0
    def test_c_eval(self):
        basic = scheme_eval_h(self.space,
                              "(ConceptNode \"whatever\" (stv 0.5 0.5))")

        a1 = self.space.add_node(types.ConceptNode, "whatever")
        self.assertTrue(a1)

        # Make sure the truth value is what's in the SCM file.
        expected = TruthValue(0.5, 0.5)
        self.assertEquals(a1.tv, expected)

        # Actually, the atoms overall should compare.
        self.assertEquals(a1, basic)

        # Do it again, from a define in the scm file.
        again = scheme_eval_h(self.space, "wobbly")
        a2 = self.space.add_node(types.ConceptNode, "wobbly")
        self.assertTrue(a2)
        self.assertEquals(a2, again)
Ejemplo n.º 26
0
    def test_c_eval(self):
        basic = scheme_eval_h(self.space,
            "(ConceptNode \"whatever\" (stv 0.5 0.5))")

        a1 = self.space.add_node(types.ConceptNode, "whatever")
        self.assertTrue(a1)

        # Make sure the truth value is what's in the SCM file.
        expected = TruthValue(0.5, 0.5)
        self.assertEquals(a1.tv, expected)

        # Actually, the atoms overall should compare.
        self.assertEquals(a1, basic)

        # Do it again, from a define in the scm file.
        again = scheme_eval_h(self.space, "wobbly")
        a2 = self.space.add_node(types.ConceptNode, "wobbly")
        self.assertTrue(a2)
        self.assertEquals(a2, again)
Ejemplo n.º 27
0
    def test_pattern_matching(self):

        #test pattern maching between difetent types of nodes
        initialize_opencog(self.atsp)
        self.scheme_animals = \
        '''
        (InheritanceLink (ConceptNode "Red") (ConceptNode "color"))
        (InheritanceLink (ConceptNode "Green") (ConceptNode "color"))
        (InheritanceLink (ConceptNode "Blue") (ConceptNode "color"))
        (InheritanceLink (ConceptNode "Spaceship") (ConceptNode "machine"))
        '''
        # create amodule or function in scheme
        self.scheme_query = \
        '''
        (define find-colors
        (BindLink
            ;; The variable to be bound
            (VariableNode "$xcol")

            ;; The pattern to be searched for
            (InheritanceLink
            (VariableNode "$xcol")
            (ConceptNode "color")
            )
            ;; The value to be returned.
            (VariableNode "$xcol")
        )
        )
        '''
        #use scheme module
        scheme_eval(self.atsp, "(use-modules (opencog))")
        scheme_eval(self.atsp, "(use-modules (opencog query))")
        scheme_eval_h(self.atsp, self.scheme_animals)
        scheme_eval_h(self.atsp, self.scheme_query)
        self.result = scheme_eval_h(self.atsp, '(cog-bind find-colors)')
        self.varlink = TypedVariableLink(VariableNode("$xcol"),
                                         TypeNode("ConceptNode"))
        self.pattern = InheritanceLink(VariableNode("$xcol"), self.test_color)
        self.colornodes = SatisfactionLink(self.varlink, self.pattern)
        self.assertEqual(self.result, satisfying_set(self.atsp,
                                                     self.colornodes))
Ejemplo n.º 28
0
def prep_bind_scheme(atomspace):
    prep_bind(atomspace)

    # Define a graph search query
    scheme_query = """
        (define find-animals
          (BindLink
            ;; The variable to be bound
            (VariableNode "$var")
            ;; The pattern to be searched for
            (InheritanceLink
               (VariableNode "$var")
               (ConceptNode "animal")
            )

            ;; The value to be returned.
            (VariableNode "$var")
          )
        )
        """
    scheme_eval_h(atomspace, scheme_query)
Ejemplo n.º 29
0
    def test_unifier(self):

        status = load_scm(self.space, "opencog/scm/opencog/query.scm")
        self.assertTrue(status)

        scheme_eval(self.space, "(use-modules (opencog query))")
        h = scheme_eval_h(self.space, "find-animals")
        self.assertTrue(h)
        print "\nThe question is:"
        print h
        question = Atom(h, self.space)
        print question

        h = scheme_eval_h(self.space, "(cog-bind find-animals)")
        self.assertTrue(h)
        print h
        answer = Atom(h, self.space)
        print "\nThe answer is:"
        print answer
        self.assertEqual(answer.type, types.SetLink)
        self.assertEqual(answer.arity, 3)
Ejemplo n.º 30
0
    def test_unifier(self):

        status = load_scm(self.space, "opencog/scm/opencog/query.scm")
        self.assertTrue(status)

        scheme_eval(self.space, "(use-modules (opencog query))")
        h = scheme_eval_h(self.space, "find-animals")
        self.assertTrue(h)
        print "\nThe question is:"
        print h
        question = Atom(h, self.space)
        print question

        h = scheme_eval_h(self.space, "(cog-bind find-animals)")
        self.assertTrue(h)
        print h
        answer = Atom(h, self.space)
        print "\nThe answer is:"
        print answer
        self.assertEqual(answer.type, types.SetLink)
        self.assertEqual(answer.arity, 3)
Ejemplo n.º 31
0
def main():
    path_query = 'query.scm'
    path_data = 'data.scm'
    atomspace = AtomSpace()
    initialize_opencog(atomspace)
    storage = Storage()
    index = Index(storage)
    with tmp_atomspace() as tmp:
        imp = ImplicationLink(VariableNode("C"), VariableNode("B"))
        # GetLink returns only bindings for variables
        pat = BindLink(imp, imp)
        index.add_pattern(pat)

    with tmp_atomspace() as tmp:
        base = open(path_data).read()
        data = scheme_eval_h(tmp, base)
        index.add_data(data)
        query = open(path_query).read()
        q = scheme_eval_h(tmp, query)
        result = index.query(tmp, q)
        print(result)
Ejemplo n.º 32
0
    def execution(self):
        '''
        First binds the "anchorNode" with the "target" if "anchorNode" exists, then executes scheme command "command"
        '''

        if self.anchorNode != None and self.target != None:
            self.tmpLink = self.atomspace.add_link(
                types.ListLink, [self.anchorNode, self.target],
                TruthValue(1.0, 100))
        else:
            self.tmpLink = None
        self.response = scheme_eval_h(self.atomspace, self.command)
        d = 3
Ejemplo n.º 33
0
def prep_bind_scheme(atomspace):
    prep_bind(atomspace)

    # Define a graph search query
    scheme_query = \
        '''
        (define find-animals
          (BindLink
            ;; The variable to be bound
            (VariableNode "$var")
            ;; The pattern to be searched for
            (InheritanceLink
               (VariableNode "$var")
               (ConceptNode "animal")
            )

            ;; The value to be returned.
            (VariableNode "$var")
          )
        )
        '''
    scheme_eval_h(atomspace, scheme_query)
Ejemplo n.º 34
0
    def run(self, atomspace):
        if self.chainer is None:
            self.create_chainer(atomspace)
            print "PLN Chainer created."
            return

        print "PLN continuing."

        target = atomspace[scheme_eval_h(atomspace, "query")]

        if not check_result(atomspace):
            result = self.chainer.forward_step()
            self.chainer._give_stimulus(target, TARGET_STIMULUS)

            return result
Ejemplo n.º 35
0
    def run(self, atomspace):
        if self.chainer is None:
            self.create_chainer(atomspace)
            print "PLN Chainer created."
            return

        print "PLN continuing."

        target = atomspace[scheme_eval_h(atomspace, "query")]

        if not check_result(atomspace):
            result = self.chainer.forward_step()
            self.chainer._give_stimulus(target, TARGET_STIMULUS)

            return result
Ejemplo n.º 36
0
 def query(self, result_atomspace, query):
     res_set = self.intersect(query)
     # add all possible results to tmp atomspace and run query
     # what is called filter step in graph indexing literature
     tmp = AtomSpace()
     atom_str = self._storage.get_atoms(res_set)
     for item in atom_str:
         tmp.add_atom(scheme_eval_h(tmp, item))
     # pack query in BindLink
     q = tmp.add_link(types.BindLink, [query, query])
     results = execute_atom(tmp, q)
     result_atoms = set()
     for atom in results.out:
         result_atoms.add(result_atomspace.add_atom(atom))
     return result_atoms
Ejemplo n.º 37
0
def prep_bind_python(atomspace):
    prep_bind(atomspace)

    # Define a graph search query
    bind_link_query = \
        '''
        (BindLink
            ;; The variable to be bound
            (VariableNode "$var")
            ;; The pattern to be searched for
            (InheritanceLink
                (VariableNode "$var")
                (ConceptNode "animal")
            )
            ;; The value to be returned.
            (VariableNode "$var")
        )
        '''
    return scheme_eval_h(atomspace, bind_link_query)
Ejemplo n.º 38
0
def prep_bind_python(atomspace):
    prep_bind(atomspace)

    # Define a graph search query
    bind_link_query = \
        '''
        (BindLink
            ;; The variable to be bound
            (VariableNode "$var")
            (ImplicationLink
                ;; The pattern to be searched for
                (InheritanceLink
                    (VariableNode "$var")
                    (ConceptNode "animal")
                )
                ;; The value to be returned.
                (VariableNode "$var")
            )
        )
        '''
    return scheme_eval_h(atomspace, bind_link_query)
Ejemplo n.º 39
0
__init__(atomspace)

data = ["opencog/atomspace/core_types.scm", "opencog/scm/utilities.scm"]

for item in data:
    load_scm(atomspace, item)

# Define several animals and something of a different type as well
scheme_animals = \
    '''
    (InheritanceLink (ConceptNode "Frog") (ConceptNode "animal"))
    (InheritanceLink (ConceptNode "Zebra") (ConceptNode "animal"))
    (InheritanceLink (ConceptNode "Deer") (ConceptNode "animal"))
    (InheritanceLink (ConceptNode "Spaceship") (ConceptNode "machine"))
    '''
scheme_eval_h(atomspace, scheme_animals)

# Define a graph search query
scheme_query = \
    '''
    (define find-animals
      (BindLink
        ;; The variable to be bound
        (VariableNode "$var")
        (ImplicationLink
          ;; The pattern to be searched for
          (InheritanceLink
             (VariableNode "$var")
             (ConceptNode "animal")
          )
Ejemplo n.º 40
0
	def affect_negative(self):
		scheme_eval_h(self.atomspace, "(State chat-affect chat-negative)")
Ejemplo n.º 41
0
	def affect_happy(self):
		scheme_eval_h(self.atomspace, "(State chat-affect chat-happy)")
Ejemplo n.º 42
0
	def listening_ended(self):
		scheme_eval_h(self.atomspace, "(State chat-state chat-listen-stop)")
Ejemplo n.º 43
0
	def listening_started(self):
		scheme_eval_h(self.atomspace, "(State chat-state chat-listen-start)")
Ejemplo n.º 44
0
	def vocalization_ended(self):
		scheme_eval_h(self.atomspace, "(State chat-state chat-stop)")
Ejemplo n.º 45
0
	def vocalization_started(self):
		scheme_eval_h(self.atomspace, "(State chat-state chat-start)")
Ejemplo n.º 46
0
def test_scheme_eval(atomspace, prep_atom):
    n = 10000
    for i in xrange(n):
        result = scheme_eval_h(atomspace, '(+ 2 2)')
    return n
Ejemplo n.º 47
0
def test_get_predicates_scheme(atomspace, prep_result):
    scheme = '(cog-get-pred (ConceptNode "dog") \'PredicateNode)'
    n = 1000
    for i in xrange(n):
        scheme_eval_h(atomspace, scheme)
    return n
Ejemplo n.º 48
0
# Add to scheme's %load-path directory to serach for opencog guile modules
scheme_eval(atomspace, "(add-to-load-path \"/usr/local/share/opencog/scm\")")

# Import opencog modules required for using `cog-execute!` in scheme_eval
scheme_eval(atomspace, "(use-modules (opencog))")
scheme_eval(atomspace, "(use-modules (opencog exec))")

# Define several animals and something of a different type as well
scheme_animals = \
    '''
    (InheritanceLink (ConceptNode "Frog") (ConceptNode "animal"))
    (InheritanceLink (ConceptNode "Zebra") (ConceptNode "animal"))
    (InheritanceLink (ConceptNode "Deer") (ConceptNode "animal"))
    (InheritanceLink (ConceptNode "Spaceship") (ConceptNode "machine"))
    '''
scheme_eval_h(atomspace, scheme_animals)
# Define a graph search query
scheme_query = \
    '''
    (define find-animals
      (BindLink
        ;; The variable to be bound
        (VariableNode "$var")

        ;; The pattern to be searched for
        (InheritanceLink
           (VariableNode "$var")
           (ConceptNode "animal")
        )

        ;; The value to be returned.
Ejemplo n.º 49
0
	def btree_run(self):
		scheme_eval_h(self.atomspace, "(run)")
Ejemplo n.º 50
0
def test_operation():
    for i in range(NUMBER_OF_ITERATIONS):
        # scheme_eval(atomspace, '(+ 2 2)')
        scheme_eval_h(atomspace, '(Concept "foo")')
Ejemplo n.º 51
0
	def chatbot_speech_stop(self):
		scheme_eval_h(self.atomspace, "(State chat-state chat-listen)")
Ejemplo n.º 52
0
def test_get_predicates_scheme(atomspace, prep_result):
    scheme = '(cog-get-pred (ConceptNode "dog") \'PredicateNode)'
    n = 1000
    for i in xrange(n):
        scheme_eval_h(atomspace, scheme)
    return n
Ejemplo n.º 53
0
def test_bind_scheme(atomspace, prep_atom):
    n = 10000
    for i in xrange(n):
        result = scheme_eval_h(atomspace, '(cog-bind find-animals)')
    return n
Ejemplo n.º 54
0
	def btree_stop(self):
		scheme_eval_h(self.atomspace, "(halt)")