Ejemplo n.º 1
0
 def actions(proofnode):            
     target = proofnode.op
     if isinstance(target, rules.Rule):
         return []
     #elif target.op == 'EvaluationLink':
     #    tr = target.args[0]
     #    if tr.op.name == 'agent_location':
     #        def get_position(position_name):
     #            return tuple(float(s[Var(i)].op.name) for i in [1,2,3])
     #        
     #        pos_str = target.args[1].args[0].op.name
     #        (x,y, _) = get_position(pos_str)
     #        return [T('ExecutionLink', self.space.add('goto_obj'),
     #                    T('ListLink',
     #                        "%{x} %{y}" % locals()
     #                        )
     #                 )
     #               ]
     #    else:
     #        return []
     #elif target.op in ['ExecutionLink',  'SequentialAndLink']:
     #    return [target]
     elif rules.actionDone_template(self.space).unifies(target):
         action = target.args[1].args[0]
         print 'action found in trail:',action
         return [action]
     else:
         return []
Ejemplo n.º 2
0
 def actions(proofnode):
     target = proofnode.op
     if isinstance(target, rules.Rule):
         return []
     #elif target.op == 'EvaluationLink':
     #    tr = target.args[0]
     #    if tr.op.name == 'agent_location':
     #        def get_position(position_name):
     #            return tuple(float(s[Var(i)].op.name) for i in [1,2,3])
     #
     #        pos_str = target.args[1].args[0].op.name
     #        (x,y, _) = get_position(pos_str)
     #        return [T('ExecutionLink', self.space.add('goto_obj'),
     #                    T('ListLink',
     #                        "%{x} %{y}" % locals()
     #                        )
     #                 )
     #               ]
     #    else:
     #        return []
     #elif target.op in ['ExecutionLink',  'SequentialAndLink']:
     #    return [target]
     elif rules.actionDone_template(self.space).unifies(target):
         action = target.args[1].args[0]
         print 'action found in trail:', action
         return [action]
     else:
         return []
Ejemplo n.º 3
0
 def actions(proofnode):            
     target = proofnode.op
     if isinstance(target, rules.Rule):
         return []
     elif target.op == 'EvaluationLink':
         tr = target.args[0]
         if tr.op.name == 'agent_location':
             def get_position(position_name):
                 return tuple(float(s[Var(i)].op.name) for i in [1,2,3])
             
             pos_str = target.args[1].args[0].op.name
             (x,y, _) = get_position(pos_str)
             return [T('ExecutionLink', self.space.add('goto_obj'),
                         T('ListLink',
                             "%{x} %{y}" % locals()
                             )
                      )
                    ]
         else:
             return []
     #elif target.op in ['ExecutionLink',  'SequentialAndLink']:
     #    return [target]
     elif rules.actionDone_template(self.space).unifies(target):
         return target
     else:
         return []
Ejemplo n.º 4
0
def new_rule(atomspace, action_str, pre_str, post_str):
    action_l = action_str.split()
    action = actions[action_l[0]]

    vars = {}
    for v_str in action_l[1:]:
        vars[v_str] = atomspace.add(t.VariableNode, v_str)

    preconditions = parse_conditions_list(vars, pre_str)
    preconditions.append(actionDone_template(atomspace, action_template(action, parse_params(vars, action_l))))

    postconditions = parse_conditions_list(vars, post_str)

    pil = T('PredictiveImplicationLink',
        T('SimultaneousAndLink',
            preconditions
        ),
        T('SimultaneousAndLink',
            postconditions
        )
    )
    atom_from_tree(pil, atomspace).tv = TruthValue(1, TruthValue().confidence_to_count(1))

    print pil
    return pil
Ejemplo n.º 5
0
        def actions(proofnode):
            target = proofnode.op
            if isinstance(target, rules.Rule):
                return []
            elif target.op == 'EvaluationLink':
                tr = target.args[0]
                if tr.op.name == 'agent_location':

                    def get_position(position_name):
                        return tuple(
                            float(s[Var(i)].op.name) for i in [1, 2, 3])

                    pos_str = target.args[1].args[0].op.name
                    (x, y, _) = get_position(pos_str)
                    return [
                        T('ExecutionLink', self.space.add('goto_obj'),
                          T('ListLink', "%{x} %{y}" % locals()))
                    ]
                else:
                    return []
            #elif target.op in ['ExecutionLink',  'SequentialAndLink']:
            #    return [target]
            elif rules.actionDone_template(self.space).unifies(target):
                return target
            else:
                return []
Ejemplo n.º 6
0
def new_rule(atomspace, action_str, pre_str, post_str):
    action_l = action_str.split()
    action = actions[action_l[0]]

    vars = {}
    for v_str in action_l[1:]:
        vars[v_str] = atomspace.add(t.VariableNode, v_str)

    preconditions = parse_conditions_list(vars, pre_str)
    preconditions.append(
        actionDone_template(
            atomspace, action_template(action, parse_params(vars, action_l))))

    postconditions = parse_conditions_list(vars, post_str)

    pil = T('PredictiveImplicationLink', T('SimultaneousAndLink',
                                           preconditions),
            T('SimultaneousAndLink', postconditions))
    atom_from_tree(pil, atomspace).tv = TruthValue(1, confidence_to_count(1))

    print pil
    return pil