示例#1
0
        /// <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 async Task <Result> Query(Request request)
        {
            return(await Task.Run(() =>
            {
                Result result = new Result(request.user, this, request);

                if (this.isAcceptingUserInput)
                {
                    // Normalize the input
                    AIMLLoader loader = new AIMLLoader(this);
                    LIAM.Normalize.SplitIntoSentences splitter = new LIAM.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)
                    {
                        Utils.SubQuery query = new SubQuery(path);
                        query.Template = this.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 = this.processNode(templateNode, query, request, result, request.user);
                                if (outputSentence.Length > 0)
                                {
                                    result.OutputSentences.Add(outputSentence);
                                }
                            }
                            catch
                            {
                                this.writeToLog("WARNING! A problem was encountered when trying to process the input: " + request.rawInput + " with the template: \"" + query.Template + "\"");
                            }
                        }
                    }
                }
                else
                {
                    result.OutputSentences.Add(this.NotAcceptingUserInputMessage);
                }

                // populate the Result object
                result.Duration = DateTime.Now - request.StartedOn;
                request.user.addResult(result);

                return result;
            }));
        }
示例#2
0
        /// <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);
            bool   IsAddResult = true;

            if (this.isAcceptingUserInput)
            {
                // Normalize the input
                AIMLLoader loader = new AIMLLoader(this);
                AIMLbot.Normalize.SplitIntoSentences splitter = new AIMLbot.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)
                {
                    Utils.SubQuery query = new SubQuery(path);
                    query.Template = this.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 = this.processNode(templateNode, query, request, result, request.user);
                            if (outputSentence.Length > 0)
                            {
                                if (outputSentence.Contains("[notadd]"))
                                {
                                    outputSentence = outputSentence.Replace("[notadd]", "");
                                    IsAddResult    = false;
                                }
                                result.OutputSentences.Add(outputSentence);
                            }
                        }
                        catch (Exception e)
                        {
                            if (this.WillCallHome)
                            {
                                this.phoneHome(e.Message, request);
                            }
                            this.writeToLog("WARNING! A problem was encountered when trying to process the input: " + request.rawInput + " with the template: \"" + query.Template + "\"");
                        }
                    }
                }
            }
            else
            {
                result.OutputSentences.Add(this.NotAcceptingUserInputMessage);
            }

            // populate the Result object
            result.Duration = DateTime.Now - request.StartedOn;
            if (IsAddResult)
            {
                request.user.addResult(result);
            }
            return(result);
        }
示例#3
0
        // Token: 0x0600008E RID: 142 RVA: 0x000058A4 File Offset: 0x000048A4
        public Result Chat(Request request)
        {
            Result result = new Result(request.user, this, request);

            if (this.isAcceptingUserInput)
            {
                AIMLLoader         aimlloader         = new AIMLLoader(this);
                SplitIntoSentences splitIntoSentences = new SplitIntoSentences(this);
                string[]           array = splitIntoSentences.Transform(request.rawInput);
                foreach (string text in array)
                {
                    result.InputSentences.Add(text);
                    string item = aimlloader.generatePath(text, request.user.getLastBotOutput(), request.user.Topic, true);
                    result.NormalizedPaths.Add(item);
                }
                foreach (string text2 in result.NormalizedPaths)
                {
                    SubQuery subQuery = new SubQuery(text2);
                    subQuery.Template = this.Graphmaster.evaluate(text2, subQuery, request, MatchState.UserInput, new StringBuilder());
                    result.SubQueries.Add(subQuery);
                }
                using (List <SubQuery> .Enumerator enumerator2 = result.SubQueries.GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        SubQuery subQuery2 = enumerator2.Current;
                        if (subQuery2.Template.Length > 0)
                        {
                            try
                            {
                                XmlNode node  = AIMLTagHandler.getNode(subQuery2.Template);
                                string  text3 = this.processNode(node, subQuery2, request, result, request.user);
                                if (text3.Length > 0)
                                {
                                    result.OutputSentences.Add(text3);
                                }
                            }
                            catch (Exception ex)
                            {
                                if (this.WillCallHome)
                                {
                                    this.phoneHome(ex.Message, request);
                                }
                                this.writeToLog(string.Concat(new string[]
                                {
                                    "WARNING! A problem was encountered when trying to process the input: ",
                                    request.rawInput,
                                    " with the template: \"",
                                    subQuery2.Template,
                                    "\""
                                }));
                            }
                        }
                    }
                    goto IL_1E4;
                }
            }
            result.OutputSentences.Add(this.NotAcceptingUserInputMessage);
IL_1E4:
            result.Duration = DateTime.Now - request.StartedOn;
            request.user.addResult(result);
            return(result);
        }