/// <summary> /// deals with the "srai" tag /// </summary> /// <param name="thisNode">the "srai" node in question</param> /// <param name="thisCat">the current category</param> /// <param name="myBot">the bot whose graphmaster returned the "template"</param> /// <param name="sUserID">the user who requires a reply</param> /// <returns>the string that results in the processing of this node</returns> private static string srai(XmlNode thisNode, cCategory thisCat, cBot myBot, string sUserID) { string sNode = thisNode.InnerText; cResponse myReply = myBot.chat(sNode, sUserID); string sReply = ""; foreach (string sSentence in myReply.alOutput) { sReply += sSentence + " "; } return(sReply); }
/// <summary> /// Takes the user's raw input and returns a cResponse object for this bot /// </summary> /// <param name="sRawInput">the user's raw input</param> /// <param name="sUserID">the user's id</param> /// <returns>the cResponse object containing information about the reply from the bot</returns> public cResponse chat(string sRawInput, string sUserID) { // process the user cUser myUser; if (cUsers.users.ContainsKey(sUserID)) { myUser = (cUser)cUsers.users[sUserID]; } else { myUser = new cUser(sUserID); cUsers.users.Add(sUserID, myUser); } // get the "that" and "topic" fields string sNewThat = cNormalizer.substitute(cGlobals.getSubstitutions(), myUser.getThat()); string sThat = cNormalizer.patternfit(sNewThat); if (sThat.Length == 0) { sThat = "*"; } string sTopic = myUser.sTopic; // do some normalisation on the raw input string sSubstitutedInput = cNormalizer.substitute(Substitutions, sRawInput); ArrayList sSplitInput = cNormalizer.sentencesplit(Splitters, sSubstitutedInput); // to hold the bot's reply string[] sRawOutput = { "", "" }; ArrayList alReply = new ArrayList(); for (int i = 0; i < sSplitInput.Count; i++) { string sFullInput = cNormalizer.patternfit((string)sSplitInput[i]) + " <that> " + sThat + " <topic> " + sTopic; sRawOutput = GraphMaster.evaluate(sFullInput, this, sUserID); string sReply = (string)sRawOutput[1]; // make sure everything is spaced out properly string[] sWords = sReply.Split(" \r\n\t".ToCharArray()); sReply = ""; foreach (string sThisWord in sWords) { string sWord = sThisWord.Trim(); if ((sWord == ".") || (sWord == ",") || (sWord == "!") || (sWord == "?")) { sReply += sWord; } else if (sWord == "") { } else { sReply += " " + sWord; } } string sProcessedReply = sReply.Trim(); alReply.Add(sProcessedReply); } // The following should never happen if you have your AIML sorted out properly! // Hint: try having a '*' pattern to catch all unknown input with responses like "Huh?", // "I'm sorry I didn't understand that..." or "I'm afraid I don't understand" if (alReply.Count == 0) { if (cGlobals.isDebug) { alReply.Add("WARNING! No reply generated by Graphmaster algorithm. Please contact the administrator of this software."); cGlobals.writeLog("WARNING! The Graphmaster algorithm failed to generate a reply under the following conditions.\r\nRawInput: " + sRawInput + "\r\n'that': " + sThat + "\r\n'topic': " + sTopic + "\r\n'UserID': " + sUserID + "\r\nPlease check your AIML files to make sure this input can be processed."); } else { alReply.Add("Hmmm, I'm not sure I understand what you mean. I think parts of my brain are missing. Please make sure I have access to a large set of AIML files. See http://www.alicebot.org/ for more information."); } } // Create the response object that is to be returned cResponse ReplyObject = new cResponse(sRawInput, sThat, sTopic, sUserID, "Default", alReply, sRawOutput[0]); // store the new <that> setting myUser.alThat.Insert(0, ReplyObject.getThat()); // store the user's input into the "Input" arraylist myUser.alInput.Insert(0, cNormalizer.sentencesplit(this.Splitters, ReplyObject.sInput)); return(ReplyObject); }
/// <summary> /// Takes the user's raw input and returns a cResponse object for this bot /// </summary> /// <param name="sRawInput">the user's raw input</param> /// <param name="sUserID">the user's id</param> /// <returns>the cResponse object containing information about the reply from the bot</returns> public cResponse chat(string sRawInput, string sUserID) { // process the user cUser myUser; if(cUsers.users.ContainsKey(sUserID)) { myUser=(cUser)cUsers.users[sUserID]; } else { myUser=new cUser(sUserID); cUsers.users.Add(sUserID,myUser); } // get the "that" and "topic" fields string sNewThat=cNormalizer.substitute(cGlobals.getSubstitutions(), myUser.getThat()); string sThat=cNormalizer.patternfit(sNewThat); if (sThat.Length==0) sThat="*"; string sTopic=myUser.sTopic; // do some normalisation on the raw input string sSubstitutedInput = cNormalizer.substitute(Substitutions,sRawInput); ArrayList sSplitInput = cNormalizer.sentencesplit(Splitters,sSubstitutedInput); // to hold the bot's reply string[] sRawOutput={"",""}; ArrayList alReply=new ArrayList(); for (int i=0; i<sSplitInput.Count; i++) { string sFullInput=cNormalizer.patternfit((string)sSplitInput[i])+" <that> "+sThat+" <topic> "+sTopic; sRawOutput = GraphMaster.evaluate(sFullInput,this, sUserID); string sReply = (string)sRawOutput[1]; // make sure everything is spaced out properly string[] sWords=sReply.Split(" \r\n\t".ToCharArray()); sReply=""; foreach(string sThisWord in sWords) { string sWord=sThisWord.Trim(); if((sWord==".")||(sWord==",")||(sWord=="!")||(sWord=="?")) { sReply+=sWord; } else if (sWord=="") { } else { sReply+=" "+sWord; } } string sProcessedReply=sReply.Trim(); alReply.Add(sProcessedReply); } // The following should never happen if you have your AIML sorted out properly! // Hint: try having a '*' pattern to catch all unknown input with responses like "Huh?", // "I'm sorry I didn't understand that..." or "I'm afraid I don't understand" if (alReply.Count==0) { if(cGlobals.isDebug) { alReply.Add("WARNING! No reply generated by Graphmaster algorithm. Please contact the administrator of this software."); cGlobals.writeLog("WARNING! The Graphmaster algorithm failed to generate a reply under the following conditions.\r\nRawInput: "+sRawInput+"\r\n'that': "+sThat+"\r\n'topic': "+sTopic+"\r\n'UserID': "+sUserID+"\r\nPlease check your AIML files to make sure this input can be processed."); } else { alReply.Add("Hmmm, I'm not sure I understand what you mean. I think parts of my brain are missing. Please make sure I have access to a large set of AIML files. See http://www.alicebot.org/ for more information."); } } // Create the response object that is to be returned cResponse ReplyObject = new cResponse ( sRawInput,sThat,sTopic, sUserID, "Default", alReply, sRawOutput[0]); // store the new <that> setting myUser.alThat.Insert(0,ReplyObject.getThat()); // store the user's input into the "Input" arraylist myUser.alInput.Insert(0,cNormalizer.sentencesplit(this.Splitters,ReplyObject.sInput)); return ReplyObject; }