Exemplo n.º 1
0
    def test__select_one_matching(self):
        atoms = self._simple_atoms_1()

        template = atoms[2]

        result = self.chainer._select_one_matching(template)
        self.assertEqual( result, atoms[2] )

        print get_attentional_focus(self.atomspace)

        template = self.atomspace.add_node(types.VariableNode, "$v1")
        result = self.chainer._select_one_matching(template)
        self.assertNotEqual( result, None )
Exemplo n.º 2
0
    def test__select_one_matching(self):
        atoms = self._simple_atoms_1()

        template = atoms[2]

        result = self.chainer._select_one_matching(template)
        self.assertEqual(result, atoms[2])

        print get_attentional_focus(self.atomspace)

        template = self.atomspace.add_node(types.VariableNode, "$v1")
        result = self.chainer._select_one_matching(template)
        self.assertNotEqual(result, None)
Exemplo n.º 3
0
    def run(self, atomspace):
        # incredibly exciting futuristic display!
        #import os
        #os.system('cls' if os.name=='nt' else 'clear')

        #        try:
        if self.chainer is None:
            self.create_chainer(atomspace)

        result = self.chainer.backward_step()
        if result:
            (outputs, inputs) = result

            if False:
                print '==== Inference ===='
                print show_atoms(outputs), '<=', show_atoms(inputs)

                print
                print '==== Attentional Focus ===='
                for atom in get_attentional_focus(atomspace)[0:30]:
                    print str(atom), atom.av

                #print '==== Result ===='
                #print output
                #print '==== Trail ===='
                #print_atoms( self.chainer.trails[output] )

            if self.chainer._all_nonzero_tvs(inputs):
                raw_input()

        else:
            print 'Invalid inference attempted'
Exemplo n.º 4
0
    def run(self, atomspace):
        # incredibly exciting futuristic display!
        #import os
        #os.system('cls' if os.name=='nt' else 'clear')

#        try:
        if self.chainer is None:
            self.create_chainer(atomspace)

        result = self.chainer.backward_step()
        if result:
            (outputs, inputs) = result

            if False:
                print '==== Inference ===='
                print show_atoms(outputs), '<=', show_atoms(inputs)

                print
                print '==== Attentional Focus ===='
                for atom in get_attentional_focus(atomspace)[0:30]:
                    print str(atom), atom.av

                #print '==== Result ===='
                #print output
                #print '==== Trail ===='
                #print_atoms( self.chainer.trails[output] )

            if self.chainer._all_nonzero_tvs(inputs):
                raw_input()

        else:
            print 'Invalid inference attempted'
Exemplo n.º 5
0
    def run(self, atomspace):
        if self.chainer is None:
            self.chainer = Chainer(atomspace, stimulateAtoms = True, agent = self)

            self.chainer.add_rule(rules.InversionRule(self.chainer))
            self.chainer.add_rule(rules.DeductionRule(self.chainer))

        # incredibly exciting futuristic display!
        #import os
        #os.system('cls' if os.name=='nt' else 'clear')

        try:
            result = self.chainer.forward_step()
            if result:
                (output, inputs) = result

                print '==== Inference ===='
                print output,str(output.av),'<=',' '.join(str(i)+str(output.av) for i in inputs)

                print
                print '==== Attentional Focus ===='
                for atom in get_attentional_focus(atomspace)[0:30]:
                    print str(atom), atom.av

                #print '==== Result ===='
                #print output
                #print '==== Trail ===='
                #print_atoms( self.chainer.trails[output] )
            else:
                print 'Invalid inference attempted'
        except Exception, e:
            print e
Exemplo n.º 6
0
    def run(self, atomspace):
        # incredibly exciting futuristic display!
        #import os
        #os.system('cls' if os.name=='nt' else 'clear')

        def show_atoms(atoms):
            return ' '.join(str(atom) + str(atom.av) for atom in atoms)

        if self.chainer is None:
            self.create_chainer(atomspace)

        import pdb
        pdb.set_trace()

        result = self.chainer.forward_step()
        if result:
            (rule, inputs, outputs) = result

            print '==== Inference ===='
            print rule.name, show_atoms(outputs), '<=', show_atoms(inputs)

            print
            print '==== Attentional Focus ===='
            for atom in get_attentional_focus(atomspace)[0:30]:
                print str(atom), atom.av

            #print '==== Result ===='
            #print output
            #print '==== Trail ===='
            #print_atoms( self.chainer.trails[output] )
        else:
            print 'Invalid inference attempted'

        try:
            pass
        except AssertionError:
            import sys, traceback
            _, _, tb = sys.exc_info()
            traceback.print_tb(tb)  # Fixed format

            tbInfo = traceback.extract_tb(tb)
            filename, line, func, text = tbInfo[-1]
            print('An error occurred on line ' + str(line) + ' in statement ' +
                  text)
            exit(1)
        except Exception, e:
            print e
            print e.args
            e.print_traceback()

            import sys, traceback
            _, _, tb = sys.exc_info()
            traceback.print_tb(tb)  # Fixed format

            tbInfo = traceback.extract_tb(tb)
            filename, line, func, text = tbInfo[-1]
            print('An error occurred on line ' + str(line) + ' in statement ' +
                  text)
            exit(1)
Exemplo n.º 7
0
    def test_get_attentional_focus(self):
        atoms = self._simple_atoms_1()

        print atoms[2]

        contents = get_attentional_focus(self.atomspace)
        print contents
        self.assertEqual(len(contents), 1)
Exemplo n.º 8
0
    def test_get_attentional_focus(self):
        atoms = self._simple_atoms_1()

        print atoms[2]

        contents = get_attentional_focus(self.atomspace)
        print contents
        self.assertEqual( len(contents), 1 )
Exemplo n.º 9
0
    def run(self, atomspace):
        # incredibly exciting futuristic display!
        #import os
        #os.system('cls' if os.name=='nt' else 'clear')

        def show_atoms(atoms):
            return ' '.join(str(atom)+str(atom.av) for atom in atoms)

        if self.chainer is None:
            self.create_chainer(atomspace)

        import pdb; pdb.set_trace()

        result = self.chainer.forward_step()
        if result:
            (rule, inputs, outputs) = result

            print '==== Inference ===='
            print rule.name, show_atoms(outputs), '<=', show_atoms(inputs)

            print
            print '==== Attentional Focus ===='
            for atom in get_attentional_focus(atomspace)[0:30]:
                print str(atom), atom.av

            #print '==== Result ===='
            #print output
            #print '==== Trail ===='
            #print_atoms( self.chainer.trails[output] )
        else:
            print 'Invalid inference attempted'

        try:
            pass
        except AssertionError:
            import sys,traceback
            _,_,tb = sys.exc_info()
            traceback.print_tb(tb) # Fixed format

            tbInfo = traceback.extract_tb(tb)
            filename,line,func,text = tbInfo[-1]
            print ('An error occurred on line ' + str(line) + ' in statement ' + text)
            exit(1)
        except Exception, e:
            print e
            print e.args
            e.print_traceback()

            import sys,traceback
            _,_,tb = sys.exc_info()
            traceback.print_tb(tb) # Fixed format

            tbInfo = traceback.extract_tb(tb)
            filename,line,func,text = tbInfo[-1]
            print ('An error occurred on line ' + str(line) + ' in statement ' + text)
            exit(1)