Пример #1
0
        /// <summary>
        /// Given a cCategory, returns the same object but with the template section processed and changed appropriately
        /// </summary>
        /// <param name="InputCat">the cCategory whose AIML template section is to be processed</param>
        /// <param name="myBot">the botID of the bot whose Graphmaster is being interrogated</param>
        /// <param name="sUserID">the userID of the person who requires a reply</param>
        /// <returns>the Ccategory to return whose sTemplate is the final reply sentence for the given input</returns>
        public static cCategory process(cCategory InputCat, cBot myBot, string sUserID)
        {
            // get the XML for processing
            string      sContent = InputCat.ToString();
            XmlDocument Template = new XmlDocument();

            Template.LoadXml(sContent);
            if (Template.HasChildNodes)
            {
                // get the child nodes found within the template.
                XmlNodeList TemplateChildren = Template.DocumentElement.ChildNodes;

                // the cCategory to return
                cCategory outputCategory = new cCategory(InputCat);

                // replace the output part of the cCategory with a blank (to be filled in
                // by the following processes)
                outputCategory.sTemplate = "";

                // process each of the child nodes that have been found in the template
                foreach (XmlNode thisNode in TemplateChildren)
                {
                    // go to a method that is basically a bit switch statement
                    outputCategory.sTemplate += cProcessor.processtag(thisNode, InputCat, myBot, sUserID);
                }

                // do some simple normalization on the template
                outputCategory.checktext();
                return(outputCategory);
            }
            else
            {
                // if no child nodes are found then the template must already contain a raw
                // string so just return it
                return(InputCat);
            }
        }
Пример #2
0
        /// <summary>
        /// Searches for a cCategory within the Graphmaster structure given a certain input
        /// </summary>
        /// <param name="sInput">Normalised input concatenated with "that" and "topic" parameters - i.e. the PATH</param>
        /// <param name="sBotID">the botID of the bot whose GraphMaster structure this is</param>
        /// <param name="sUserID">the userID of the person who requires a reply</param>
        /// <returns>a string representing the bot's response</returns>
        public string[] evaluate(string sInput, cBot myBot, string sUserID)
        {
            // to hold the raw output
            string[] sRawOutput = { "", "" };

            // deal with void input
            if (sInput.Length == 0)
            {
                return(sRawOutput);
            }

            // create a category to represent the returned category
            cCategory cat = rootNodeMapper.evaluate(sInput, 0, "");

            // if we've found something then process it and return a string
            if (cat != null)
            {
                cCategory procCat = cProcessor.process(cat, myBot, sUserID);
                sRawOutput[0] = cat.filename;
                sRawOutput[1] = procCat.ToString().Trim();
                return(sRawOutput);
            }

            // this shouldn't happen but is here just in case :-)
            else
            {
                if (cGlobals.isDebug)
                {
                    sRawOutput[1] = "No match found for input path: " + sInput;
                }
                else
                {
                    sRawOutput[1] = "I'm afraid I don't understand. Perhaps some of my AIML files are missing. You can download them from http://www.alicebot.org/ and place them in the following directory: " + cGlobals.AIMLPATH;
                }
                return(sRawOutput);
            }
        }
Пример #3
0
		/// <summary>
		/// Given a cCategory, returns the same object but with the template section processed and changed appropriately 
		/// </summary>
		/// <param name="InputCat">the cCategory whose AIML template section is to be processed</param>
		/// <param name="myBot">the botID of the bot whose Graphmaster is being interrogated</param>
		/// <param name="sUserID">the userID of the person who requires a reply</param>
		/// <returns>the Ccategory to return whose sTemplate is the final reply sentence for the given input</returns>
		public static cCategory process(cCategory InputCat, cBot myBot, string sUserID)
		{
			// get the XML for processing
			string sContent=InputCat.ToString();
			XmlDocument Template=new XmlDocument();
			Template.LoadXml(sContent);
			if(Template.HasChildNodes)
			{

				// get the child nodes found within the template.
				XmlNodeList TemplateChildren=Template.DocumentElement.ChildNodes;

				// the cCategory to return
				cCategory outputCategory=new cCategory(InputCat);
			
				// replace the output part of the cCategory with a blank (to be filled in 
				// by the following processes)
				outputCategory.sTemplate="";

				// process each of the child nodes that have been found in the template
				foreach(XmlNode thisNode in TemplateChildren)
				{
					// go to a method that is basically a bit switch statement
					outputCategory.sTemplate+=cProcessor.processtag(thisNode,InputCat,myBot,sUserID);
				}

				// do some simple normalization on the template
				outputCategory.checktext();
				return outputCategory;
			}
			else

				// if no child nodes are found then the template must already contain a raw
				// string so just return it
				return InputCat;
		}