コード例 #1
0
ファイル: logic.py プロジェクト: DingjieWang/opencog-python
 def extract_plan(self, trail):
     # The list of actions in a PredictiveImplicationLink. Sometimes there are none,
     # sometimes one; if there is a SequentialAndLink then it can be more than one.
     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 []
     # Extract all the targets in best-first order
     proofnodes = trail.flatten()
     proofnodes.reverse()
     actions = concat_lists([actions(pn) for pn in proofnodes])
     return actions
コード例 #2
0
    def recurse_app(self, app_pdn):
        #print 'recurse_app', app_pdn
        # You should try to produce every goal for an app.
        # Let's say for simplicity, that you just expand one descendant
        # of every goal (i.e. for every goal, you put in one step of effort)
        # for proving it.

        # If we've gone down to an axiom, give up. The axiom PDNs are added
        # when an app is expanded by bc_step.
        if len(app_pdn.op.goals) == 0:
            return []

        ## If some of the goals have no children currently, let's assume it hasn't
        ## been expanded yet.
        #if any(len(expr_pdn.args) == 0 for expr_pdn in app_pdn.args):
        if app_pdn.bc_expanded == False:
            app_pdn.bc_expanded = True
            assert app_pdn.op in self.bc_later
            return [app_pdn]

        # Use a set because sometimes a goal will be used by more than one proof path.
        return set(
            concat_lists(
                list(self.recurse_expr(expr_pdn))
                for expr_pdn in app_pdn.args))
コード例 #3
0
    def extract_plan(self, trail):
        # The list of actions in a PredictiveImplicationLink. Sometimes there are none,
        # sometimes one; if there is a SequentialAndLink then it can be more than one.
        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 []

        # Extract all the targets in best-first order
        proofnodes = trail.flatten()
        proofnodes.reverse()
        actions = concat_lists([actions(pn) for pn in proofnodes])
        return actions
コード例 #4
0
ファイル: logic.py プロジェクト: 4fingers/opencog
    def recurse_app(self, app_pdn):
        #print 'recurse_app', app_pdn
        # You should try to produce every goal for an app.
        # Let's say for simplicity, that you just expand one descendant
        # of every goal (i.e. for every goal, you put in one step of effort)
        # for proving it.

        # If we've gone down to an axiom, give up. The axiom PDNs are added
        # when an app is expanded by bc_step.
        if len(app_pdn.op.goals) == 0:
            return []

        ## If some of the goals have no children currently, let's assume it hasn't
        ## been expanded yet.
        #if any(len(expr_pdn.args) == 0 for expr_pdn in app_pdn.args):
        if app_pdn.bc_expanded == False:
            app_pdn.bc_expanded = True
            assert app_pdn.op in self.bc_later
            return [app_pdn]

        # Use a set because sometimes a goal will be used by more than one proof path.
        return set(concat_lists(list(self.recurse_expr(expr_pdn)) for expr_pdn in app_pdn.args))