예제 #1
0
파일: PlanGraph.cs 프로젝트: Rosyyou/CAGA
        public int AddToAgenda(PlanNode planNode, int index, string indent)
        {
            Console.WriteLine(indent + "Dialogue.PlanGraph  AddToAgenda  " + planNode.Name);
            int currIdx = this._agenda.IndexOf(planNode);

            if (currIdx >= 0)
            {
                if (index > currIdx)
                {
                    this._agenda.RemoveAt(currIdx);
                    this._agenda.Insert(index - 1, planNode);
                    return(index - 1);
                }
                else if (index < currIdx)
                {
                    this._agenda.RemoveAt(currIdx);
                    this._agenda.Insert(index, planNode);
                    return(index);
                }
                else
                {
                    return(index);
                }
            }
            else
            {
                this._agenda.Insert(index, planNode);
                return(index);
            }
        }
예제 #2
0
파일: PlanGraph.cs 프로젝트: Rosyyou/CAGA
        private bool _explainAnswer(PlanNode planNode, DialogueAct dlgAct, string indent)
        {
            Console.WriteLine(indent + "Dialogue.PlanGraph  _explainAnswer  " + planNode.Name);
            if (planNode is ActionNode)
            {
                ActionNode actNode = (ActionNode)planNode;
                if (actNode.ActType == "ID")
                {
                    foreach (string phrase in dlgAct.SpeechContext.Keys)
                    {
                        Console.WriteLine("phrase=" + phrase);
                        Console.WriteLine("(ParamNode)actNode=" + actNode.Name);
                        Console.WriteLine("(ParamNode)actNode.Parent=" + ((ParamNode)actNode.Parent).Name);

                        if (phrase.ToLower() == ((ParamNode)actNode.Parent).Name.ToLower())
                        {
                            return(true);
                        }
                        if (phrase.ToLower() == ((ParamNode)actNode.Parent).ParamType.ToLower())
                        {
                            return(true);
                        }
                    }
                }
            }

            Console.WriteLine(indent + "false");
            return(false);
        }
예제 #3
0
파일: ParamNode.cs 프로젝트: cdbean/CAGA
 public ParamNode(string name, string paramType, bool multiple, string description="", PlanNode parent=null) : base(name, description, parent)
 {
     this._paramType = paramType;
     this._multiple = multiple;
     this._paramState = ParamState.Unknown;
     this._subActions = new ArrayList();
     this._values = new ArrayList();
 }
예제 #4
0
파일: PlanGraph.cs 프로젝트: Rosyyou/CAGA
 public void ElaborateFromNode(PlanNode planNode, string indent)
 {
     if (planNode is ActionNode)
     {
         this._elaborateFromActionNode((ActionNode)planNode, indent + "  ");
     }
     else if (planNode is ParamNode)
     {
         this._elaborateFromParamNode((ParamNode)planNode, indent + "  ");
     }
 }
예제 #5
0
파일: ActionNode.cs 프로젝트: cdbean/CAGA
 public ActionNode(string name, string actType, string complexity, string description="", PlanNode parent=null) : base(name, description, parent)
 {
     this._actType = actType;
     this._complexity = complexity;
     this._recipeId = -1;
     this._actState = ActionState.Unknown;
     this._agents = new ArrayList();
     this._params = new ArrayList();
     this._subActions = new ArrayList();
     this._optional = false;
 }
예제 #6
0
파일: PlanGraph.cs 프로젝트: Rosyyou/CAGA
        public int RemoveFromAgenda(PlanNode planNode, string indent)
        {
            Console.WriteLine(indent + "Dialogue.PlanGraph  RemoveFromAgenda  " + planNode.Name);
            int index = this._agenda.IndexOf(planNode);

            if (index >= 0)
            {
                this._agenda.RemoveAt(index);
                this._history.Add(planNode);
            }
            return(index);
        }
예제 #7
0
파일: PlanGraph.cs 프로젝트: Rosyyou/CAGA
        private bool _parentParamsRdy(PlanNode planNode, string indent)
        {
            Console.WriteLine(indent + "Dialogue/PlanGraph _parentParamsRdy " + planNode.Name);
            bool       paramsRdy  = true; // check whether the previous params are ready
            ActionNode actionNode = planNode.Parent as ActionNode;

            if (actionNode != null)
            {
                Console.WriteLine(indent + "Parent: " + actionNode.Name);
                foreach (ParamNode param in actionNode.Params)
                {
                    Console.WriteLine(indent + "param: " + param.Name);
                    if (param.Name != planNode.Name)
                    {
                        Console.WriteLine(indent + "param:" + param.Name + " ParamState:" + param.ParamState);
                        if (param.ParamState != ParamState.Ready)
                        {
                            paramsRdy = false;
                        }
                        foreach (ActionNode subAct in param.SubActions)
                        {
                            Console.WriteLine(indent + "subAct:" + subAct.Name + " ActState:" + subAct.ActState);
                            if (subAct.ActState == ActionState.Executing)
                            {
                                paramsRdy = false;
                                break;
                            }
                        }
                        if (paramsRdy == false)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                Console.WriteLine(indent + "Parent: is NULL");
            }
            return(paramsRdy);
        }
예제 #8
0
파일: PlanGraph.cs 프로젝트: Rosyyou/CAGA
 private bool _explainFeedback(PlanNode planNode, DialogueAct dlgAct, string indent)
 {
     Console.WriteLine(indent + "Dialogue.PlanGraph  _explainFeedback  " + planNode.Name);
     if (planNode is ActionNode)
     {
         ActionNode actNode = (ActionNode)planNode;
         if (actNode.ActState == ActionState.Executing)
         {
             foreach (string phrase in dlgAct.SpeechContext.Keys)
             {
                 if (phrase.ToLower() == actNode.Name.ToLower())
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
예제 #9
0
파일: PlanGraph.cs 프로젝트: Rosyyou/CAGA
 private bool _explainAffOrNeg(PlanNode planNode, DialogueAct dlgAct, string indent)
 {
     Console.WriteLine(indent + "Dialogue.PlanGraph  _explainAffOrNeg  " + planNode.Name);
     if (planNode is ActionNode)
     {
         ActionNode actNode = (ActionNode)planNode;
         if (actNode.ActType == "ID" && actNode.ActState == ActionState.Executing)
         {
             if (actNode.Parent != null && actNode.Parent is ParamNode)
             {
                 ParamNode paramNode = actNode.Parent as ParamNode;
                 if (paramNode.ParamType == "boolean")
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
예제 #10
0
파일: PlanGraph.cs 프로젝트: cdbean/CAGA
 public int RemoveFromAgenda(PlanNode planNode)
 {
     int index = this._agenda.IndexOf(planNode);
     if (index >= 0)
     {
         this._agenda.RemoveAt(index);
         this._history.Add(planNode);
     }
     return index;
 }
예제 #11
0
파일: PlanGraph.cs 프로젝트: cdbean/CAGA
 public int AddToAgenda(PlanNode planNode, int index)
 {
     int currIdx = this._agenda.IndexOf(planNode);
     if (currIdx >= 0)
     {
         if (index > currIdx)
         {
             this._agenda.RemoveAt(currIdx);
             this._agenda.Insert(index - 1, planNode);
             return (index - 1);
         }
         else if (index < currIdx)
         {
             this._agenda.RemoveAt(currIdx);
             this._agenda.Insert(index, planNode);
             return index;
         }
         else
         {
             return index;
         }
     }
     else 
     {
         this._agenda.Insert(index, planNode);
         return index;
     }
 }
예제 #12
0
파일: PlanGraph.cs 프로젝트: cdbean/CAGA
        private ActionNode _explainActionFromNode(PlanNode planNode, Hashtable tempAct, DialogueAct dlgAct)
        {
            if (planNode is ActionNode)
            {
                ActionNode actionNode = (ActionNode)planNode;
                if (actionNode.Name.ToLower() == tempAct["name"].ToString().ToLower())
                {
                    // If the action has not been initiated, initiate it and add the agent
                    if (actionNode.ActState == ActionState.Unknown)
                    {
                        actionNode.ActState = ActionState.Initiated;
                    }
                    if (actionNode.SearchAgent(dlgAct.Agent) == null)
                    {
                        actionNode.Agents.Add(dlgAct.Agent);
                    }
                    // If the action has been completed, or failed, start a new one, attached it to the same parent
                    if (actionNode.ActState == ActionState.Complete || actionNode.ActState == ActionState.Failed)
                    {
                        ActionNode newAction = new ActionNode((string)tempAct["name"], (string)tempAct["act_type"], (string)tempAct["complexity"], (string)tempAct["description"], actionNode.Parent);
                        newAction.Agents.Add(dlgAct.Agent);
                        newAction.ActState = ActionState.Initiated;
                        if (actionNode.Parent != null)
                        {
                            if (actionNode.Parent is ActionNode)
                            {
                                ((ActionNode)(actionNode.Parent)).SubActions.Add(newAction);
                            }
                            else if (actionNode.Parent is ParamNode)
                            {
                                ((ParamNode)(actionNode.Parent)).SubActions.Add(newAction);
                            }
                        }
                        return newAction;
                    }
                    return actionNode;
                }

                // search the params and subactions
                foreach (ParamNode paramNode in actionNode.Params)
                {
                    ActionNode actNode = this._explainActionFromNode(paramNode, tempAct, dlgAct);
                    if (actNode != null)
                    {
                        return actNode;
                    }
                }
                foreach (ActionNode subActNode in actionNode.SubActions)
                {
                    ActionNode actNode = this._explainActionFromNode(subActNode, tempAct, dlgAct);
                    if (actNode != null)
                    {
                        return actNode;
                    }
                }
                
            }
            else if (planNode is ParamNode)
            {
                ParamNode paramNode = (ParamNode)planNode;
                foreach (ActionNode subActNode in paramNode.SubActions)
                {
                    ActionNode actNode = this._explainActionFromNode(subActNode, tempAct, dlgAct);
                    if (actNode != null)
                    {
                        return actNode;
                    }
                }   
            }

            return null;
        }
예제 #13
0
파일: PlanGraph.cs 프로젝트: cdbean/CAGA
 private bool _explainFeedback(PlanNode planNode, DialogueAct dlgAct)
 {
     if (planNode is ActionNode)
     {
         ActionNode actNode = (ActionNode)planNode;
         if (actNode.ActState == ActionState.Executing)
         {
             foreach (string phrase in dlgAct.SpeechContext.Keys)
             {
                 if (phrase.ToLower() == actNode.Name.ToLower())
                 {
                     return true;
                 }
             }
         }
     }
     return false;
 }
예제 #14
0
파일: PlanGraph.cs 프로젝트: cdbean/CAGA
 private bool _explainAffOrNeg(PlanNode planNode, DialogueAct dlgAct)
 {
     if (planNode is ActionNode)
     {
         ActionNode actNode = (ActionNode)planNode;
         if (actNode.ActType == "ID" && actNode.ActState == ActionState.Executing)
         {
             if (actNode.Parent != null && actNode.Parent is ParamNode)
             {
                 ParamNode paramNode = actNode.Parent as ParamNode;
                 if (paramNode.ParamType == "boolean")
                 {
                     return true;
                 }
             }
         }
     }
     return false;
 }
예제 #15
0
파일: ActionNode.cs 프로젝트: Rosyyou/CAGA
 public ActionNode(string name, string actType, string complexity, string description = "", PlanNode parent = null) : base(name, description, parent)
 {
     this._actType    = actType;
     this._complexity = complexity;
     this._recipeId   = -1;
     this._actState   = ActionState.Unknown;
     this._agents     = new ArrayList();
     this._params     = new ArrayList();
     this._subActions = new ArrayList();
     this._optional   = false;
 }
예제 #16
0
파일: PlanGraph.cs 프로젝트: cdbean/CAGA
        private bool _parentParamsRdy(PlanNode planNode)
        {
            bool paramsRdy = true; // check whether the previous params are ready
            ActionNode actionNode = planNode.Parent as ActionNode;
            if (actionNode != null)
            {
                foreach (ParamNode param in actionNode.Params)
                {
                    if (param.Name != planNode.Name)
                    {
                        if (param.ParamState != ParamState.Ready)
                        {
                            paramsRdy = false;
                        }
                        foreach (ActionNode subAct in param.SubActions)
                        {
                            if (subAct.ActState == ActionState.Executing)
                            {
                                paramsRdy = false;
                                break;
                            }
                        }
                        if (paramsRdy == false)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return paramsRdy;
        }
예제 #17
0
파일: PlanGraph.cs 프로젝트: cdbean/CAGA
 public int GetIndexInAgenda(PlanNode planNode)
 {
     return this._agenda.IndexOf(planNode);
 }
예제 #18
0
파일: PlanGraph.cs 프로젝트: Rosyyou/CAGA
        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);
        }
예제 #19
0
파일: PlanGraph.cs 프로젝트: Rosyyou/CAGA
 public int GetIndexInAgenda(PlanNode planNode)
 {
     return(this._agenda.IndexOf(planNode));
 }
예제 #20
0
파일: PlanGraph.cs 프로젝트: cdbean/CAGA
 public void ElaborateFromNode(PlanNode planNode)
 {
     if (planNode is ActionNode)
     {
         this._elaborateFromActionNode((ActionNode)planNode);
     }
     else if (planNode is ParamNode)
     {
         this._elaborateFromParamNode((ParamNode)planNode);
     }
 }
예제 #21
0
파일: PlanGraph.cs 프로젝트: Rosyyou/CAGA
        /// <summary>
        /// When Completed, Update Parent recursively
        /// </summary>
        /// <param name="planNode"></param>
        /// <param name="indent"></param>
        private void _updateParentState(PlanNode planNode, string indent)
        {
            Console.WriteLine(indent + "Dialogue.PlanGraph _updateParentState " + planNode.Name);
            if (planNode.Parent != null)
            {
                Console.WriteLine(indent + "Parent: " + planNode.Parent.Name);
                if (planNode.Parent is ActionNode)
                {
                    ActionNode parent = (ActionNode)planNode.Parent;
                    foreach (ParamNode param in parent.Params)
                    {
                        if (param.ParamState != ParamState.Ready)
                        {
                            Console.WriteLine(indent + "ActionNode Parent not Completed becasue of param " + param.Name + " " + param.ParamState.ToString());
                            return;
                        }
                    }
                    foreach (ActionNode subAct in parent.SubActions)
                    {
                        if (subAct.Optional == false && subAct.ActState != ActionState.Complete)
                        {
                            Console.WriteLine(indent + "ActionNode Parent not Completed becasue of subAct " + subAct.Name + " " + subAct.ActState.ToString() + " Optional=false");
                            return;
                        }
                        if (subAct.Optional == true && subAct.ActState != ActionState.Complete && subAct.ActState != ActionState.Unknown)
                        {
                            Console.WriteLine(indent + "ActionNode Parent not Completed becasue of subAct " + subAct.Name + " " + subAct.ActState.ToString() + " Optional=ture");
                            return;
                        }
                    }
                    parent.ActState = ActionState.Complete;
                    Console.WriteLine(indent + "ActionNode Parent Completed");
                    this._updateParentState(parent, indent + "  ");
                }
                else if (planNode.Parent is ParamNode)
                {
                    ParamNode parent = (ParamNode)planNode.Parent;
                    if (parent.Values.Count == 0)
                    {
                        Console.WriteLine(indent + "ParamNode Parent notReady becasue of 0 value");
                        return;
                    }
                    else
                    {
                        foreach (object obj in parent.Values)
                        {
                            if (obj is string)
                            {
                                Console.WriteLine(indent + "******string******");
                                Console.WriteLine(indent + "obj=" + obj);
                            }
                            else if (obj is Hashtable)
                            {
                                Console.WriteLine(indent + "******hashtable******");
                                foreach (DictionaryEntry item in (Hashtable)obj)
                                {
                                    Console.WriteLine(indent + "key=" + item.Key + ",value=" + item.Value);
                                }
                            }
                        }
                    }

                    // assume the parameter is ready as long as it has values
                    // it might be extended to consider the conditions on the parameter
                    parent.ParamState = ParamState.Ready;
                    this._updateParentState(parent, indent + "  ");
                }
            }
        }
예제 #22
0
파일: PlanGraph.cs 프로젝트: cdbean/CAGA
        private void _updateParentState(PlanNode planNode)
        {
            if (planNode.Parent != null)
            {
                if (planNode.Parent is ActionNode)
                {
                    ActionNode parent = (ActionNode)planNode.Parent;
                    foreach (ParamNode param in parent.Params)
                    {
                        if (param.ParamState != ParamState.Ready)
                        {
                            return;
                        }
                    }
                    foreach (ActionNode subAct in parent.SubActions)
                    {
                        if (subAct.Optional == false && subAct.ActState != ActionState.Complete)
                        {
                            return;
                        }
                        if (subAct.Optional == true && subAct.ActState != ActionState.Complete && subAct.ActState != ActionState.Unknown)
                        {
                            return;
                        }
                    }
                    parent.ActState = ActionState.Complete;
                    this._updateParentState(parent);
                }
                else if (planNode.Parent is ParamNode)
                {
                    ParamNode parent = (ParamNode)planNode.Parent;
                    if (parent.Values.Count == 0)
                    {
                        return;
                    }
                    // assume the parameter is ready as long as it has values
                    // it might be extended to consider the conditions on the parameter
                    parent.ParamState = ParamState.Ready;
                    this._updateParentState(parent);
                }

            }
        }
예제 #23
0
파일: Executor.cs 프로젝트: cdbean/CAGA
 private ArrayList _searchValueFromAncestor(PlanNode planNode, string paramName)
 {
     ArrayList matchedValues = new ArrayList();
     if (planNode == null)
         return matchedValues;
     PlanNode parent = planNode.Parent;
     while (parent != null)
     {
         if (parent is ParamNode)
         {
             ParamNode ancestorParam = parent as ParamNode;
             if (parent.Name.ToLower() == paramName.ToLower() && ancestorParam.ParamState == ParamState.Ready)
             {
                 matchedValues.AddRange(ancestorParam.Values);
                 break;
             }
         }
         else if (parent is ActionNode)
         {
             ActionNode ancestorAction = parent as ActionNode;
             foreach (ParamNode param in ancestorAction.Params)
             {
                 if (param.Name.ToLower() == paramName.ToLower() && param.ParamState == ParamState.Ready)
                 {
                     matchedValues.AddRange(param.Values);
                     break;
                 }
             }
         }
         parent = parent.Parent;
     }
     return matchedValues;
 }
예제 #24
0
 public ParamNode(string name, string paramType, bool multiple, string description = "", PlanNode parent = null) : base(name, description, parent)
 {
     this._paramType  = paramType;
     this._multiple   = multiple;
     this._paramState = ParamState.Unknown;
     this._subActions = new ArrayList();
     this._values     = new ArrayList();
 }
예제 #25
0
파일: PlanGraph.cs 프로젝트: cdbean/CAGA
 private bool _explainAnswer(PlanNode planNode, DialogueAct dlgAct)
 {
     if (planNode is ActionNode)
     {
         ActionNode actNode = (ActionNode)planNode;
         if (actNode.ActType == "ID")
         {
             foreach (string phrase in dlgAct.SpeechContext.Keys)
             {
                 if (phrase.ToLower() == ((ParamNode)actNode.Parent).Name.ToLower())
                 {
                     return true;
                 }
             }
         }
     }
     return false;
 }
예제 #26
0
 public PlanNode(string name, string description = "", PlanNode parent = null)
 {
     this._name        = name;
     this._description = description;
     this._parent      = parent;
 }
예제 #27
0
파일: PlanNode.cs 프로젝트: cdbean/CAGA
 public PlanNode(string name, string description="", PlanNode parent=null)
 {
     this._name = name;
     this._description = description;
     this._parent = parent;
 }