Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
        private void _elaborateFromParamNode(ParamNode paramNode, string indent)
        {
            Console.WriteLine(indent + "Dialogue/PlanGraph _elaborateFromParamNode " + paramNode.Name);
            bool paramsRdy = this._parentParamsRdy(paramNode, indent + "  "); // check whether the previous params are ready

            Console.WriteLine(indent + "paramsRdy = " + paramsRdy);
            if (paramsRdy == false)
            {
                return;
            }

            if (paramNode.ParamState == ParamState.InPreparation)
            {
                if (paramNode.SubActions.Count > 0)
                {
                    int idx = this.RemoveFromAgenda(paramNode, indent + "  ");
                    foreach (ActionNode subAct in paramNode.SubActions)
                    {
                        idx = this.AddToAgenda(subAct, idx, indent + "  ");
                        idx++;
                    }
                    foreach (ActionNode subAct in paramNode.SubActions)
                    {
                        // as soon as the parameter is ready, stop the elaboration
                        if (paramNode.ParamState == ParamState.Ready && subAct.Optional == true)
                        {
                            this.RemoveFromAgenda(subAct, indent + "  ");
                        }
                        else
                        {
                            subAct.ActState = ActionState.Initiated;
                            this._elaborateFromActionNode(subAct, indent + "  ");
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 private bool _parseRecipeXML(string recipeXML, ActionNode actionNode)
 {
     XmlDocument doc = new XmlDocument();
     doc.LoadXml(recipeXML);
     XmlNodeList paramList = doc.GetElementsByTagName("PARA");
     foreach (XmlNode param in paramList)
     {
         string name = param.Attributes["Name"].Value;
         string paramType = param.Attributes["Type"].Value;
         bool multiple = true;
         if (param.Attributes["Multiple"] != null && param.Attributes["Multiple"].Value.ToLower() == "false")
         {
             multiple = false;
         }
         string description = "";
         if (param.Attributes["Description"] != null)
         {
             description = param.Attributes["Description"].Value;
         }
         ParamNode paramNode = new ParamNode(name, paramType, multiple, description, actionNode);
         foreach (XmlNode node in param.ChildNodes)
         {
             if (node.Name == "ID_PARAS")
             {
                 foreach (XmlNode subAct in node.ChildNodes)
                 {
                     if (subAct.Name == "ID_PARA")
                     {
                         Hashtable tempAct = this._kbase.SearchAction(subAct.Attributes["Name"].Value);
                         ActionNode subActNode = new ActionNode((string)tempAct["name"], (string)tempAct["act_type"], (string)tempAct["complexity"], (string)tempAct["description"], paramNode);
                         if (subAct.Attributes["Optional"] != null && subAct.Attributes["Optional"].Value.ToString().ToLower() == "true")
                         {
                             subActNode.Optional = true;
                         }
                         paramNode.SubActions.Add(subActNode);
                     }
                 }
             }
         }
         actionNode.Params.Add(paramNode);
     }
     XmlNodeList actionList = doc.GetElementsByTagName("SUBACT");
     foreach (XmlNode action in actionList)
     {
         Hashtable tempAct = this._kbase.SearchAction(action.Attributes["Name"].Value);
         ActionNode subActNode = new ActionNode((string)tempAct["name"], (string)tempAct["act_type"], (string)tempAct["complexity"], (string)tempAct["description"], actionNode);
         if (action.Attributes["Optional"] != null && action.Attributes["Optional"].Value.ToString().ToLower() == "true")
         {
             subActNode.Optional = true;
         }
         actionNode.SubActions.Add(subActNode);
     }
     return true;
 }
Ejemplo n.º 4
0
        private void _elaborateFromParamNode(ParamNode paramNode)
        {
            bool paramsRdy = this._parentParamsRdy(paramNode) ; // check whether the previous params are ready
            if (paramsRdy == false)
            {
                return;
            }

            if (paramNode.ParamState == ParamState.InPreparation)
            {
                if (paramNode.SubActions.Count > 0)
                {
                    int idx = this.RemoveFromAgenda(paramNode);
                    foreach (ActionNode subAct in paramNode.SubActions)
                    {
                        idx = this.AddToAgenda(subAct, idx);
                        idx++;
                    }                    
                    foreach (ActionNode subAct in paramNode.SubActions)
                    {
                        // as soon as the parameter is ready, stop the elaboration
                        if (paramNode.ParamState == ParamState.Ready && subAct.Optional == true)
                        {
                            this.RemoveFromAgenda(subAct);
                        }
                        else
                        {
                            subAct.ActState = ActionState.Initiated;
                            this._elaborateFromActionNode(subAct); 
                        }
                    }                    
                }
            }
        }
Ejemplo n.º 5
0
 private void _addValueToParam(ParamNode paramNode, object newValue)
 {
     if (newValue != null)
     {
         if (paramNode.Multiple == false)
         {
             paramNode.Values.Clear();
         }
         else
         {
             foreach (object value in paramNode.Values)
             {
                 // check whether the new value already exists
                 // only check string type at the moment
                 if (newValue is string)
                 {
                     if (newValue.ToString() == value.ToString())
                     {
                         return;
                     }
                 }
             }
         }
         paramNode.Values.Add(newValue);
         
     }
 }
Ejemplo n.º 6
0
 private object _parseValueFromSpeech(ParamNode paramNode, object speech)
 {
     if (paramNode.ParamType == "feature_class")
     {
         return speech.ToString();
     }
     else if (paramNode.ParamType == "data_source")
     {
         return speech.ToString();
     }
     else if (paramNode.ParamType == "region_type")
     {
         return speech.ToString();
     }
     else if (paramNode.ParamType == "geometry_polygon")
     {
         return speech.ToString();
     }
     else if (paramNode.ParamType == "data_field")
     {
         return speech.ToString();
     }
     else if (paramNode.ParamType == "statistics")
     {
         return speech.ToString();
     }
     else if (paramNode.ParamType == "length")
     {
         if (speech is SortedList)
         {
             Hashtable lengthInfo = new Hashtable();
         
             if (((SortedList)speech).ContainsKey("value"))
             {
                 lengthInfo.Add("value", ((SortedList)speech)["value"]);
             }
             if (((SortedList)speech).ContainsKey("unit"))
             {
                 lengthInfo.Add("unit", ((SortedList)speech)["unit"]);
             }
             return lengthInfo;
         }
     }
     else if (paramNode.ParamType == "boolean")
     {
         if (paramNode.Name == "partiality")
         {
             if (speech.ToString() == "partial")
             {
                 return true;
             }
             else
             {
                 return false;
             }
         }
     }
     return null;
 }
Ejemplo n.º 7
0
 private string _generateQuestionString(ParamNode paramNode)
 {
     string question = "";
     if (paramNode.ParamType == "feature_class")
     {
         question = "What ";
         if (paramNode.Description != "")
         {
             question += paramNode.Description;
         }
         else
         {
             question += String.Join(" ", paramNode.Name.Split('_'));
         }
         question += " are you working on?";
     }
     else if (paramNode.ParamType == "data_source")
     {
         question = "Which ";
         if (paramNode.Description != "")
         {
             question += paramNode.Description;
         }
         else
         {
             question += String.Join(" ", paramNode.Name.Split('_'));
         }
         question += " are you working on?";
     }
     else if (paramNode.ParamType == "region_type")
     {
         question = "What is ";
         if (paramNode.Description != "")
         {
             question += paramNode.Description;
         }
         else
         {
             question += String.Join(" ", paramNode.Name.Split('_'));
         }
         question += " you are interested in?";
     }
     else if (paramNode.ParamType == "data_field")
     {
         question = "Which ";
         if (paramNode.Description != "")
         {
             question += paramNode.Description;
         }
         else
         {
             question += String.Join(" ", paramNode.Name.Split('_'));
         }
         question += " do you want to use?";
     }
     else if (paramNode.ParamType == "boolean")
     {
         question = "Do you ";
         if (paramNode.Description != "")
         {
             question += paramNode.Description;
         }
         else
         {
             question += String.Join(" ", paramNode.Name.Split('_'));
         }
         question += "?";
     }
     else if (paramNode.ParamType == "length")
     {
         question = "What is the " + String.Join(" ", paramNode.Name.Split('_')) + "?";
     }
     return question;
 }
Ejemplo n.º 8
0
        /// <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 + "  ");
                }
            }
        }
Ejemplo n.º 9
0
        private bool _parseRecipeXML(string recipeXML, ActionNode actionNode, string indent)
        {
            Console.WriteLine(indent + "Dialogue/PlanGraph _parseRecipeXML " + actionNode.Name);
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(recipeXML);
            XmlNodeList paramList = doc.GetElementsByTagName("PARA");

            foreach (XmlNode param in paramList)
            {
                string name      = param.Attributes["Name"].Value;
                string paramType = param.Attributes["Type"].Value;
                bool   multiple  = true;
                if (param.Attributes["Multiple"] != null && param.Attributes["Multiple"].Value.ToLower() == "false")
                {
                    multiple = false;
                }
                string description = "";
                if (param.Attributes["Description"] != null)
                {
                    description = param.Attributes["Description"].Value;
                }
                ParamNode paramNode = new ParamNode(name, paramType, multiple, description, actionNode);

                bool hasParam = false;
                foreach (ParamNode tmpParam in actionNode.Params)
                {
                    //Console.WriteLine(indent + "tmpParam= " + tmpParam.Name + ",paramNode=" + paramNode.Name);
                    if (paramNode.Name == tmpParam.Name)
                    {
                        hasParam       = true;
                        paramNode.Flag = true;
                    }
                }
                if (!hasParam)
                {
                    foreach (XmlNode node in param.ChildNodes)
                    {
                        if (node.Name == "ID_PARAS")
                        {
                            foreach (XmlNode subAct in node.ChildNodes)
                            {
                                if (subAct.Name == "ID_PARA")
                                {
                                    Hashtable tempAct = this._kbase.SearchAction(subAct.Attributes["Name"].Value);
                                    Console.WriteLine("name=" + (string)tempAct["name"]);
                                    //Console.WriteLine("act_type=" + (string)tempAct["act_type"]);
                                    //Console.WriteLine("complexity=" + (string)tempAct["complexity"]);
                                    //Console.WriteLine("description=" + (string)tempAct["description"]);
                                    ActionNode subActNode = new ActionNode((string)tempAct["name"], (string)tempAct["act_type"], (string)tempAct["complexity"], (string)tempAct["description"], paramNode);
                                    if (subAct.Attributes["Optional"] != null && subAct.Attributes["Optional"].Value.ToString().ToLower() == "true")
                                    {
                                        subActNode.Optional = true;
                                    }
                                    paramNode.Flag = true;
                                    paramNode.SubActions.Add(subActNode);
                                }
                            }
                        }
                    }
                    actionNode.Params.Add(paramNode);
                }
            }

            for (int index = actionNode.Params.Count - 1; index >= 0; index--)
            {
                // Get the item.
                ParamNode tmpParam = (ParamNode)actionNode.Params[index];

                // Check to remove.
                if (tmpParam.Flag == false)
                {
                    Console.WriteLine("what deleted is " + tmpParam.Name);
                    // Remove.
                    actionNode.Params.RemoveAt(index);
                }
            }

            XmlNodeList actionList = doc.GetElementsByTagName("SUBACT");

            foreach (XmlNode action in actionList)
            {
                Hashtable  tempAct    = this._kbase.SearchAction(action.Attributes["Name"].Value);
                ActionNode subActNode = new ActionNode((string)tempAct["name"], (string)tempAct["act_type"], (string)tempAct["complexity"], (string)tempAct["description"], actionNode);
                if (action.Attributes["Optional"] != null && action.Attributes["Optional"].Value.ToString().ToLower() == "true")
                {
                    subActNode.Optional = true;
                }

                bool hasAction = false;
                foreach (ActionNode tmpActNode in actionNode.SubActions)
                {
                    Console.WriteLine("tmpActNode.Name=" + tmpActNode.Name + ",subActNode.Name" + subActNode.Name);
                    if (tmpActNode.Name == subActNode.Name)
                    {
                        hasAction = true;
                    }
                }
                if (!hasAction)
                {
                    actionNode.SubActions.Add(subActNode);
                }
            }
            return(true);
        }
Ejemplo n.º 10
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);
        }