本文整理汇总了Python中pln.chainers.Chainer._selectOne方法的典型用法代码示例。如果您正苦于以下问题:Python Chainer._selectOne方法的具体用法?Python Chainer._selectOne怎么用?Python Chainer._selectOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pln.chainers.Chainer
的用法示例。
在下文中一共展示了Chainer._selectOne方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BackwardChainerTest
# 需要导入模块: from pln.chainers import Chainer [as 别名]
# 或者: from pln.chainers.Chainer import _selectOne [as 别名]
class BackwardChainerTest(TestCase):
def setUp(self):
self.atomspace = AtomSpace()
self.chainer = Chainer(self.atomspace)
def tearDown(self):
del self.atomspace
del self.chainer
def _simple_atoms_1(self):
atoms = []
atoms.append( self.atomspace.add_node(types.ConceptNode, "animal") )
atoms.append( self.atomspace.add_node(types.ConceptNode, "breathe") )
atoms.append( self.atomspace.add_link(types.InheritanceLink, [atoms[0], atoms[1]]) )
return atoms
def test__selectOne(self):
atoms = self._simple_atoms_1()
atoms[0].av = {'sti': 1}
atom = self.chainer._selectOne(atoms)
self.assertNotEquals(atom, None)
self.assertEqual(atom, atoms[0])
atoms[1].av = {'sti': 1}
atoms[2].av = {'sti': 1}
atom = self.chainer._selectOne(atoms)
self.assertTrue(atom in atoms)
def test_get_attentional_focus(self):
atoms = self._simple_atoms_1()
atoms[2].av = {'sti': 1}
print atoms[2]
contents = get_attentional_focus(self.atomspace)
print contents
self.assertEqual( len(contents), 1 )
def test__select_one_matching(self):
atoms = self._simple_atoms_1()
atoms[2].av = {'sti': 1}
template = atoms[2]
result = self.chainer._select_one_matching(template)
self.assertEqual( result, atoms[2] )
atoms[0].av = {'sti': 1}
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 )
def test__find_inputs_recursive(self):
def apply(generic_inputs, generic_outputs):
inputs = []
outputs = []
empty_substitution = {}
status = self.chainer._find_inputs_recursive(inputs, outputs, generic_inputs, generic_outputs, empty_substitution)
return (inputs, outputs)
atoms = self._simple_atoms_1()
# test it on lots of simple made up rules that include the edge cases
# [] => []
generic_inputs = []
generic_outputs = []
(inputs, outputs) = apply(generic_inputs, generic_outputs)
self.assertEquals( inputs, [] )
self.assertEquals( outputs, [] )
# [animal] => []
atoms[0].av = {'sti': 1}
generic_inputs = [atoms[0]]
generic_outputs = []
(inputs, outputs) = apply(generic_inputs, generic_outputs)
self.assertEquals( inputs, [atoms[0]] )
self.assertEquals( outputs, [] )
v1 = self.atomspace.add_node(types.VariableNode, "$v1")
# [v1] => []
generic_inputs = [v1]
generic_outputs = []
(inputs, outputs) = apply(generic_inputs, generic_outputs)
self.assertEquals( len(inputs), 1 )
self.assertEquals( outputs, [] )
#from nose.tools import set_trace; set_trace()
# [v1] => [v1]
generic_inputs = [v1]
#.........这里部分代码省略.........