コード例 #1
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))
コード例 #2
0
 def test_satisfying_set(self):
     atom = satisfying_set(self.atomspace, self.getlink_atom)
     self._check_result_setlink(atom, 3)
コード例 #3
0
 def test_satisfying_set(self):
     atom = satisfying_set(self.atomspace, self.getlink_atom)
     self._check_result_setlink(atom, 3)
コード例 #4
0
from opencog.atomspace import AtomSpace, types

a = AtomSpace()
cat = a.add_node(types.ConceptNode, "Cat")
animal = a.add_node(types.ConceptNode, "Animal")
a.add_link(types.InheritanceLink, [cat, animal])

for atom in a:
    print (atom)

from opencog.utilities import initialize_opencog
from opencog.type_constructors import *
from opencog.bindlink import satisfying_set

initialize_opencog(a)

a.clear()

color = ConceptNode("Color")

InheritanceLink(ConceptNode("Red"), color)
InheritanceLink(ConceptNode("Green"), color)
InheritanceLink(ConceptNode("Blue"), color)

# Create a pattern to look for color nodes
varlink = TypedVariableLink(VariableNode("$xcol"), TypeNode("ConceptNode"))
pattern = InheritanceLink(VariableNode("$xcol"), color)
colornodes = GetLink(varlink, pattern)

print(satisfying_set(a, colornodes))