/// <summary> /// Given a request containing user input, produces a result from the bot /// </summary> /// <param name="request">the request from the user</param> /// <returns>the result to be output to the user</returns> public Result Chat(Request request) { Result result = new Result(request.User, this, request); if (isAcceptingUserInput) { // Normalize the input AIMLLoader loader = new AIMLLoader(this); Normalize.SplitIntoSentences splitter = new Normalize.SplitIntoSentences(this); string[] rawSentences = splitter.Transform(request.RawInput); foreach (string sentence in rawSentences) { result.InputSentences.Add(sentence); string path = loader.GeneratePath(sentence, request.User.getLastBotOutput(), request.User.Topic, true); result.NormalizedPaths.Add(path); } // grab the templates for the various sentences from the graphmaster foreach (string path in result.NormalizedPaths) { SubQuery query = new SubQuery(path); query.Template = Graphmaster.Evaluate(path, query, request, MatchState.UserInput, new StringBuilder()); result.SubQueries.Add(query); } // process the templates into appropriate output foreach (SubQuery query in result.SubQueries) { if (query.Template.Length > 0) { try { XmlNode templateNode = AIMLTagHandler.GetNode(query.Template); string outputSentence = ProcessNode(templateNode, query, request, result, request.User); if (outputSentence.Length > 0) { result.OutputSentences.Add(outputSentence); } } catch (Exception e) { WriteToLog("WARNING! A problem was encountered when trying to process the input: " + request.RawInput + " with the template: \"" + query.Template + "\""); } } } } else { result.OutputSentences.Add(NotAcceptingUserInputMessage); } // populate the Result object result.Duration = DateTime.Now - request.StartedOn; request.User.AddResult(result); return(result); }
/// <summary> /// Given a request containing user input, produces a result from the bot /// </summary> /// <param name="request">the request from the user</param> /// <returns>the result to be output to the user</returns> public Result Chat(Request request) { Result result = new Result(request.User, this, request); // Normalize the input AIMLLoader loader = new AIMLLoader(this); AimlStandard.Normalize.SplitIntoSentences splitter = new AimlStandard.Normalize.SplitIntoSentences(this); string[] rawSentences = splitter.Transform(request.RawInput); foreach (string sentence in rawSentences) { result.InputSentences.Add(sentence); string path = loader.GeneratePath(sentence, request.User.GetLastBotOutput(), request.User.Topic, true); result.NormalizedPaths.Add(path); } // grab the templates for the various sentences from the graphmaster foreach (string path in result.NormalizedPaths) { string template = this.Graphmaster.Evaluate(path, request, MatchState.UserInput, new StringBuilder()); result.Templates.Add(template); } // process the templates into appropriate output foreach (string template in result.Templates) { if (template.Length > 0) { try { XmlNode templateNode = AIMLTagHandler.GetNode(template); string outputSentence = this.ProcessNode(templateNode, request, result, request.User); if (outputSentence.Length > 0) { result.OutputSentences.Add(outputSentence); } } catch (Exception e) { if (this.WillCallHome) { this.PhoneHome(e.Message, request); } this.WriteToLog("WARNING! A mal-formed template was encountered when trying to process the input: " + request.RawInput); } } } // populate the Result object result.Duration = DateTime.Now - request.StartedOn; request.User.AddResult(result); return(result); }