/// <summary> /// Adds the latest result from the bot to the Results collection /// </summary> /// <param name="latestResult">the latest result from the bot</param> public void AddResult(Result latestResult) { _results.Add(latestResult.Duration.Milliseconds, latestResult.HasTimedOut, latestResult.RawOutput, latestResult.RequestId, latestResult.UserId); }
/// <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); if (_config.isAcceptingUserInput) { // Normalize the input ReniBot.AimlEngine.Normalize.SplitIntoSentences splitter = new ReniBot.AimlEngine.Normalize.SplitIntoSentences(_config); string[] rawSentences = splitter.Transform(request.RawInput); foreach (string sentence in rawSentences) { result.InputSentences.Add(sentence); string topic = _botUserService.GetTopic(request.UserId); string lastOutput = _userResultService.GetLastOutput(request.UserId); string path = _loader.GeneratePath(sentence, lastOutput, topic, true); result.NormalizedPaths.Add(path); } // grab the templates for the various sentences from the graphmaster foreach (string path in result.NormalizedPaths) { Utils.SubQuery query = new SubQuery(path); query.Template = _graphmaster.Evaluate(path, query, request, MatchState.UserInput, new StringBuilder(), _config.TimeOut); result.HasTimedOut = request.HasTimedOut; 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, new User(_predicateService, _userResultService, _requestService) { UserId = request.UserId }); if (outputSentence.Length > 0) { result.OutputSentences.Add(outputSentence); } } catch (Exception e) { if (_config.WillCallHome) { PhoneHome(e.Message, request); } _logger.LogWarning("A problem was encountered when trying to process the input: " + request.RawInput + " with the template: \"" + query.Template + "\""); } } } } else { result.OutputSentences.Add(_config.NotAcceptingUserInputMessage); } // populate the Result object result.Duration = DateTime.Now - request.StartedOn; _userResultService.Add(result.Duration.Milliseconds, result.HasTimedOut, result.RawOutput, result.RequestId, result.UserId); return(result); }