class BackwardInferenceAgent(MindAgent): def __init__(self): self.chainer = None def create_chainer(self, atomspace): self.chainer = Chainer(atomspace, stimulateAtoms=False, agent=self) deduction_link_types = [types.InheritanceLink] # types.SubsetLink, types.IntensionalInheritanceLink] for link_type in deduction_link_types: self.chainer.add_rule(rules.InversionRule(self.chainer, link_type)) self.chainer.add_rule(rules.DeductionRule(self.chainer, link_type)) # self.chainer.add_rule(rules.NotCreationRule(self.chainer)) # self.chainer.add_rule(rules.NotEliminationRule(self.chainer)) # for rule in rules.create_and_or_rules(self.chainer, 1, 5): # self.chainer.add_rule(rule) # self.chainer.add_rule(EvaluationToMemberRule(self.chainer)) # self.chainer.add_rule(MemberToInheritanceRule(self.chainer)) 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'
class BackwardInferenceAgent(MindAgent): def __init__(self): self.chainer = None def create_chainer(self, atomspace): self.chainer = Chainer(atomspace, stimulateAtoms = False, agent = self) deduction_link_types = [types.InheritanceLink] # types.SubsetLink, types.IntensionalInheritanceLink] for link_type in deduction_link_types: self.chainer.add_rule(rules.InversionRule(self.chainer, link_type)) self.chainer.add_rule(rules.DeductionRule(self.chainer, link_type)) # self.chainer.add_rule(rules.NotCreationRule(self.chainer)) # self.chainer.add_rule(rules.NotEliminationRule(self.chainer)) # for rule in rules.create_and_or_rules(self.chainer, 1, 5): # self.chainer.add_rule(rule) # self.chainer.add_rule(EvaluationToMemberRule(self.chainer)) # self.chainer.add_rule(MemberToInheritanceRule(self.chainer)) 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'