Exemplo n.º 1
0
        public void TestJobSuggestionsIntent()
        {
            RasaQuery userQuery = new RasaQuery("i want to be a web developer");
            var       response  = userQuery.GetResponse();

            Assert.IsTrue(response.Intent.Name == "suggested_papers");

            var job = response.Entities.Where(entity => entity.Entity == "job")
                      .Select(entity => entity.Value);

            Assert.IsTrue(job.Contains("web developer"));
        }
Exemplo n.º 2
0
        public void TestPaperRequirementsQuestion()
        {
            RasaQuery userQuery = new RasaQuery("what is required to do software engineering");
            var       response  = userQuery.GetResponse();

            Assert.IsTrue(response.Intent.Name == "paper_requirements");

            var papers = response.Entities.Where(entity => entity.Entity == "paper")
                         .Select(entity => entity.Value);

            Assert.IsTrue(papers.Contains("software engineering"));
        }
Exemplo n.º 3
0
        public JsonResult Ask([FromBody] QueryArguments query)
        {
            if (query.UserInput.StartsWith("@")) // Enable us to debug the bot in case it's displaying incorrect messages
            {
                RasaQuery    rasaQuery    = new RasaQuery(query.UserInput.Substring(1));
                RasaResponse rasaResponse = rasaQuery.GetResponse();

                return(QueryResponse.Result(rasaResponse.GetDebug()));
            }
            else // Regular messages
            {
                RasaQuery    rasaQuery    = new RasaQuery(query.UserInput);
                RasaResponse rasaResponse = rasaQuery.GetResponse();


                if (rasaResponse.Intent == null)  // If for some reason our bot decides there's no intent, we respond gracefully.
                {
                    return(QueryResponse.Result("I'm only able to answer questions in relations to papers at AUT."));
                }

                RasaIntent intent = rasaResponse.Intent;

                if (intent?.Name == RasaResponse.INTENT_REQUIREMENTS) // Check if our intent is paper_requirements
                {
                    return(GetPaperRequirementResult(rasaResponse));
                }
                else if (intent?.Name == RasaResponse.INTENT_SUGGESTION) // Else if our intent is a paper suggestion
                {
                    return(GetPaperSuggestionResult(rasaResponse));
                }
                else // If our intent isn't supported we need to let the user know
                {
                    return(QueryResponse.Result("I do not yet have the capability to answer that question."));
                }
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello there!");
            string input = string.Empty;

            do
            {
                Console.Write("# ");
                input = Console.ReadLine();

                if (input != string.Empty)
                {
                    RasaQuery rasaQuery = new RasaQuery(input);
                    var       result    = rasaQuery.GetResponse();

                    if (result.Intent.Name == "paper_requirements")
                    {
                        var papers = result.Entities.Where(entity => entity.Entity == "paper").Select(entity => entity.Value);

                        var matchingPapers = papersTest.Where(paper => paper.Name.ToLower() == papers.First().ToLower() ||
                                                              paper.Aliases.ContainsIgnoreCase(papers.First()) ||
                                                              paper.PaperCode.ToLower() == papers.First().ToLower());

                        if (papers.ContainsIgnoreCase("software engineering"))
                        {
                            WriteOutput("To do Contemporary Methods in Software Engineering, you are required to do either COMP603, COMP610 or ENSE600");
                        }
                        else if (papers.ContainsIgnoreCase("web development"))
                        {
                            WriteOutput("Web Development does not require anything to do, but it is a third year paper.");
                        }
                    }
                    else if (result.Intent.Name == "suggested_papers")
                    {
                        var jobs = result.Entities.Where(entity => entity.Entity == "job").Select(entity => entity.Value);
                        if (jobs.ContainsIgnoreCase("web developer"))
                        {
                            WriteOutput("I recommend COMP721 - Web Development");
                        }
                    }


#if SHOW_DEBUG
                    if (result.Intent != null)
                    {
                        Console.WriteLine("Got: {0} @{1}% confidence", result.Intent.Name, result.Intent?.Confidence * 100f);
                    }
                    else
                    {
                        Console.WriteLine("Got no intents.");
                    }

                    foreach (var entity in result.Entities)
                    {
                        Console.WriteLine("\t{0}", entity);
                    }

                    Console.WriteLine("Other potential results:  ");
                    foreach (var intent in result.IntentRankings)
                    {
                        Console.WriteLine("\tGot: {0} @{1}% confidence", intent.Name, intent.Confidence * 100);
                        foreach (var entity in result.Entities)
                        {
                            Console.WriteLine("\t\t{0}", entity);
                        }
                    }
#endif
                }
            }while (input != string.Empty);
        }