Beispiel #1
0
        private ActionNode _explainActionFromNode(PlanNode planNode, Hashtable tempAct, DialogueAct dlgAct, string indent)
        {
            Console.WriteLine(indent + "Dialogue.PlanGraph  _explainActionFromNode  " + planNode.Name);
            ActionNode pNode     = (ActionNode)planNode;
            ActionNode newAction = new ActionNode((string)tempAct["name"], (string)tempAct["act_type"], (string)tempAct["complexity"], (string)tempAct["description"]);

            if (planNode is ActionNode)
            {
                Console.WriteLine(indent + "IsActionNode  actionNode:" + planNode.Name.ToLower() + "  tempAct" + tempAct["name"].ToString());
                //               ActionNode actionNode = (ActionNode)planNode;
                switch (newAction.ActType)
                {
                case "ACT":
                {
                    if (pNode.Name.ToLower() == tempAct["name"].ToString().ToLower())
                    {
                        // If the action has not been initiated, initiate it and add the agent
                        if (pNode.ActState == ActionState.Unknown)
                        {
                            pNode.ActState = ActionState.Initiated;
                        }
                        if (pNode.SearchAgent(dlgAct.Agent) == null)
                        {
                            pNode.Agents.Add(dlgAct.Agent);
                        }
                        // If the action has been completed, or failed, start a new one, attached it to the same parent
                        if (pNode.ActState == ActionState.Complete || pNode.ActState == ActionState.Failed)
                        {
                            //                       ActionNode newAction = new ActionNode((string)tempAct["name"], (string)tempAct["act_type"], (string)tempAct["complexity"], (string)tempAct["description"], actionNode.Parent);
                            newAction.Parent = pNode.Parent;
                            newAction.Agents.Add(dlgAct.Agent);
                            newAction.ActState = ActionState.Initiated;
                            if (pNode.Parent != null)
                            {
                                if (pNode.Parent is ActionNode)
                                {
                                    //There seems to be a logical error, because the newAction is now added as a subaction of pNode.Parent.  This is equivalent to modifying the recipe for pNode.Parent action.  The correct way to handle this should be:
                                    // if the tempAct matches with one of the subactions that has not been initiated (potential intention), then replace that subact with newAction
                                    ActionNode pParent = (ActionNode)(pNode.Parent);
                                    foreach (ActionNode subact in pParent.SubActions)
                                    {
                                        if ((subact.Name == newAction.Name) & (subact.ActState == CAGA.Dialogue.ActionState.Unknown))
                                        {
                                            ((ActionNode)(pNode.Parent)).SubActions.Add(newAction);
                                            newAction.Parent = pParent;
                                            ((ActionNode)(pNode.Parent)).SubActions.Remove(subact);
                                        }
                                    }
                                }
                                else if (pNode.Parent is ParamNode)
                                {
                                    ((ParamNode)(pNode.Parent)).SubActions.Add(newAction);
                                }
                            }
                            return(newAction);
                        }
                        return(pNode);
                    }

                    // search the params and subactions
                    foreach (ParamNode paramNode in pNode.Params)
                    {
                        ActionNode actNode = this._explainActionFromNode(paramNode, tempAct, dlgAct, indent + "  ");
                        if (actNode != null)
                        {
                            return(actNode);
                        }
                    }
                    foreach (ActionNode subActNode in pNode.SubActions)
                    {
                        ActionNode actNode = this._explainActionFromNode(subActNode, tempAct, dlgAct, indent + "  ");
                        if (actNode != null)
                        {
                            return(actNode);
                        }
                    }
                    return(null);
                }

                case "REF":
                    // If the parent is a Action node and the new act is a reference, try to explain it as a parameter of its subaction
                {
                    //
                    return(null);
                }
                }
                return(null);
            }
            else if (planNode is ParamNode)
            {
                switch (newAction.ActType)
                {
                case "ACT":
                {
                    ParamNode paramNode = (ParamNode)planNode;
                    foreach (ActionNode subActNode in paramNode.SubActions)
                    {
                        ActionNode actNode = this._explainActionFromNode(subActNode, tempAct, dlgAct, indent + "  ");
                        if (actNode != null)
                        {
                            return(actNode);
                        }
                    }
                    return(null);
                }

                case "REF":
                {
                    // explain the REF for potential match with the parameter, if the parent still expecting a parameter (paraStatus=unknown)
                    //retrieval the REF type, if it matches with the Parameter type, move forward
                    // Create a RefNode based on the newAction
                    // RefNode has a parant of planNode
                    // RefNode.execute to calculate the referenced entities and set the parameter of the planNode
                    RefNode newRef = new RefNode(newAction);
                    newRef.parent = (ParamNode)planNode;
                    newRef.execute();
                    return(null);
                }
                }
                return(null);
            }
            return(null);
        }