Exemplo n.º 1
0
        public async Task Regex_RecognizeIntentViaRegex()
        {
            TestAdapter adapter = new TestAdapter();

            RegExpRecognizerMiddleware recognizer = new RegExpRecognizerMiddleware()
                                                    .AddIntent("aaaaa", new Regex("a", RegexOptions.IgnoreCase))
                                                    .AddIntent("bbbbb", new Regex("b", RegexOptions.IgnoreCase));

            Bot bot = new Bot(adapter)
                      .Use(recognizer);

            bot.OnReceive(async(context) =>
            {
                if (context.IfIntent(new Regex("a")))
                {
                    context.Reply("aaaa Intent");
                }
                if (context.IfIntent(new Regex("b")))
                {
                    context.Reply("bbbb Intent");
                }
            });

            await adapter.Test("aaaaaaaaa", "aaaa Intent")
            .Test("bbbbbbbbb", "bbbb Intent")
            .StartTest();
        }
        public async Task Regex_MultipleIntents()
        {
            RegExpRecognizerMiddleware helpRecognizer = new RegExpRecognizerMiddleware()
                                                        .AddIntent("HelpIntent", new Regex("help", RegexOptions.IgnoreCase))
                                                        .AddIntent("CancelIntent", new Regex("cancel", RegexOptions.IgnoreCase))
                                                        .AddIntent("TacoIntent", new Regex("taco", RegexOptions.IgnoreCase));

            TestAdapter adapter = new TestAdapter()
                                  .Use(helpRecognizer);

            await new TestFlow(adapter, async(context) =>
            {
                var recognized = context.Get <IRecognizedIntents>();
                if (recognized.TopIntent.Name == "HelpIntent")
                {
                    context.Reply("You selected HelpIntent");
                }
                else if (recognized.TopIntent.Name == "CancelIntent")
                {
                    context.Reply("You selected CancelIntent");
                }
                else if (recognized.TopIntent.Name == "TacoIntent")
                {
                    context.Reply("You selected TacoIntent");
                }
            })
            .Send("help").AssertReply("You selected HelpIntent")
            .Send("cancel").AssertReply("You selected CancelIntent")
            .Send("taco").AssertReply("You selected TacoIntent")
            .StartTest();
        }
Exemplo n.º 3
0
        public async Task Regex_MultipleIntents()
        {
            TestAdapter adapter = new TestAdapter();

            RegExpRecognizerMiddleware helpRecognizer = new RegExpRecognizerMiddleware()
                                                        .AddIntent("HelpIntent", new Regex("help", RegexOptions.IgnoreCase))
                                                        .AddIntent("CancelIntent", new Regex("cancel", RegexOptions.IgnoreCase))
                                                        .AddIntent("TacoIntent", new Regex("taco", RegexOptions.IgnoreCase));

            Bot bot = new Bot(adapter)
                      .Use(helpRecognizer);

            bot.OnReceive(async(context) =>
            {
                if (context.IfIntent("HelpIntent"))
                {
                    context.Reply("You selected HelpIntent");
                }
                else if (context.IfIntent("CancelIntent"))
                {
                    context.Reply("You selected CancelIntent");
                }
                else if (context.IfIntent("TacoIntent"))
                {
                    context.Reply("You selected TacoIntent");
                }
            });

            await adapter
            .Send("help").AssertReply("You selected HelpIntent")
            .Send("cancel").AssertReply("You selected CancelIntent")
            .Send("taco").AssertReply("You selected TacoIntent")
            .StartTest();
        }
Exemplo n.º 4
0
        public async Task Regex_DoNotRecognizeCancelIntent()
        {
            TestAdapter adapter = new TestAdapter();

            RegExpRecognizerMiddleware helpRecognizer = new RegExpRecognizerMiddleware()
                                                        .AddIntent("CancelIntent", new Regex("cancel", RegexOptions.IgnoreCase));

            Bot bot = new Bot(adapter)
                      .Use(helpRecognizer);

            bot.OnReceive(async(context) =>
            {
                if (context.IfIntent("CancelIntent"))
                {
                    context.Reply("You selected CancelIntent");
                }
                else
                {
                    context.Reply("Bot received request of type message");
                }
            });

            await adapter.Test("tacos", "Bot received request of type message")
            .StartTest();
        }
        public async Task Regex_ExtractEntityGroupsNamedCaptureNoList()
        {
            Regex  r     = new Regex(@"how (?<One>.*) (?<Two>.*)");
            string input = "how 11111 22222";

            Intent i = RegExpRecognizerMiddleware.Recognize(input, r, 1.0);

            Assert.IsNotNull(i, "Expected an Intent");
            Assert.IsTrue(i.Entities.Count == 2, "Should match 2 groups");
            Assert.IsTrue(i.Entities[0].ValueAs <string>() == "11111");
            Assert.IsTrue(i.Entities[0].GroupName == "One");

            Assert.IsTrue(i.Entities[1].ValueAs <string>() == "22222");
            Assert.IsTrue(i.Entities[1].GroupName == "Two");
        }
        public async Task Regex_ExtractEntityGroupsNamedCaptureViaList()
        {
            Regex  r     = new Regex(@"how (.*) (.*)", RegexOptions.IgnoreCase);
            string input = "How 11111 22222";

            Intent i = RegExpRecognizerMiddleware.Recognize(input, r, new List <string>()
            {
                "One", "Two"
            }, 1.0);

            Assert.IsNotNull(i, "Expected an Intent");
            Assert.IsTrue(i.Entities.Count == 2, "Should match 2 groups");
            Assert.IsTrue(i.Entities[0].ValueAs <string>() == "11111");
            Assert.IsTrue(i.Entities[0].GroupName == "One");

            Assert.IsTrue(i.Entities[1].ValueAs <string>() == "22222");
            Assert.IsTrue(i.Entities[1].GroupName == "Two");
        }
Exemplo n.º 7
0
        public async Task Regex_RecognizeHelpIntent()
        {
            RegExpRecognizerMiddleware helpRecognizer = new RegExpRecognizerMiddleware()
                                                        .AddIntent("HelpIntent", new Regex("help", RegexOptions.IgnoreCase));

            TestAdapter adapter = new TestAdapter()
                                  .Use(helpRecognizer);

            await new TestFlow(adapter, async(context) =>
            {
                if (context.IfIntent("HelpIntent"))
                {
                    context.Reply("You selected HelpIntent");
                }
            })
            .Test("help", "You selected HelpIntent")
            .StartTest();
        }
        public async Task Regex_RecognizeCancelIntent()
        {
            RegExpRecognizerMiddleware helpRecognizer = new RegExpRecognizerMiddleware()
                                                        .AddIntent("CancelIntent", new Regex("cancel", RegexOptions.IgnoreCase));

            TestAdapter adapter = new TestAdapter()
                                  .Use(helpRecognizer);

            await new TestFlow(adapter, async(context) =>
            {
                var recognized = context.Get <IRecognizedIntents>();
                if (recognized.TopIntent.Name == "CancelIntent")
                {
                    context.Reply("You selected CancelIntent");
                }
            })
            .Test("cancel", "You selected CancelIntent")
            .StartTest();
        }
Exemplo n.º 9
0
        public async Task Regex_RecognizeHelpIntent()
        {
            RegExpRecognizerMiddleware helpRecognizer = new RegExpRecognizerMiddleware()
                                                        .AddIntent("HelpIntent", new Regex("help", RegexOptions.IgnoreCase));

            TestAdapter adapter = new TestAdapter()
                                  .Use(helpRecognizer);

            await new TestFlow(adapter, async(context) =>
            {
                var recognized = context.Services.Get <IRecognizedIntents>();
                if (recognized.TopIntent.Name == "HelpIntent")
                {
                    await context.SendActivity("You selected HelpIntent");
                }
            })
            .Test("help", "You selected HelpIntent")
            .StartTest();
        }
Exemplo n.º 10
0
        public async Task Regex_RecognizeHelpIntent()
        {
            TestAdapter adapter = new TestAdapter();

            RegExpRecognizerMiddleware helpRecognizer = new RegExpRecognizerMiddleware()
                                                        .AddIntent("HelpIntent", new Regex("help", RegexOptions.IgnoreCase));

            Bot bot = new Bot(adapter)
                      .Use(helpRecognizer);

            bot.OnReceive(async(context) =>
            {
                if (context.IfIntent("HelpIntent"))
                {
                    context.Reply("You selected HelpIntent");
                }
            });

            await adapter.Test("help", "You selected HelpIntent")
            .StartTest();
        }
Exemplo n.º 11
0
        public async Task Regex_DoNotRecognizeCancelIntent()
        {
            RegExpRecognizerMiddleware helpRecognizer = new RegExpRecognizerMiddleware()
                                                        .AddIntent("CancelIntent", new Regex("cancel", RegexOptions.IgnoreCase));

            TestAdapter adapter = new TestAdapter()
                                  .Use(helpRecognizer);

            await new TestFlow(adapter, async(context) =>
            {
                var recognized = context.Services.Get <IRecognizedIntents>();
                if (recognized.TopIntent?.Name == "CancelIntent")
                {
                    await context.SendActivity("You selected CancelIntent");
                }
                else
                {
                    await context.SendActivity("Bot received activity of type message");
                }
            })
            .Test("tacos", "Bot received activity of type message")
            .Test("cancel", "You selected CancelIntent")
            .StartTest();
        }