示例#1
0
        private Recognizer CreateRecognizer()
        {
            var reg = new RegexRecognizer
            {
                Intents = new List <IntentPattern>
                {
                    new IntentPattern("book", "(?i)book"),
                    new IntentPattern("weather", "(?i)weather")
                }
            };

            return(reg);
        }
示例#2
0
        private static IRecognizer CreateRegexRecognizer()
        {
            var recognizer = new RegexRecognizer
            {
                Intents = new Dictionary <string, string>
                {
                    { "Book", "(?i)book" },
                    { "Weather", "(?i)weather" },
                }
            };

            return(recognizer);
        }
示例#3
0
        private Recognizer CreateRecognizer()
        {
            var reg = new RegexRecognizer
            {
                Intents = new List <IntentPattern>
                {
                    new IntentPattern("hi", "(?i)hi"),
                    new IntentPattern("hello", "(?i)hello"),
                    new IntentPattern("issue", "(?i)issue"),
                    new IntentPattern("incident", "(?i)incident")
                }
            };

            return(reg);
        }
示例#4
0
        public async Task LogPiiFalseByDefault()
        {
            var telemetryClient = new Mock <IBotTelemetryClient>();
            var recognizer      = new RegexRecognizer {
                TelemetryClient = telemetryClient.Object
            };
            var dc = TestUtils.CreateContext("Salutations!");

            var(logPersonalInformation, _) = recognizer.LogPersonalInformation.TryGetValue(dc.State);

            Assert.False(logPersonalInformation);

            var result = await recognizer.RecognizeAsync(dc, dc.Context.Activity, CancellationToken.None);

            Assert.NotNull(result);
        }
        private static RegexRecognizer CreateReconRecognizer()
        {
            var recognizer = new RegexRecognizer()
            {
                Intents = new List <IntentPattern>()
                {
                    new IntentPattern(TextInput, "(?i)textinput"),
                    new IntentPattern(NumberInput, "(?i)numberinput"),
                    new IntentPattern(ConfirmInput, "(?i)confirminput"),
                    new IntentPattern(ChoiceInput, "(?i)choiceinput"),
                    new IntentPattern(DateTime, "(?i)datetime"),
                    new IntentPattern(Attachment, "(?i)attachment"),
                    new IntentPattern(LogIn, "(?i)login"),
                    new IntentPattern(LogOut, "(?i)logout")
                },
            };

            return(recognizer);
        }
        public async Task RegexRecognizer_Intent()
        {
            var recognizer = new RegexRecognizer()
            {
                Intents = new List <IntentPattern>()
                {
                    new IntentPattern("codeIntent", "(?<code>[a-z][0-9])"),
                    new IntentPattern("colorIntent", "(?i)(color|colour)"),
                },
                Entities = new EntityRecognizerSet()
                {
                    new AgeEntityRecognizer(),
                    new ConfirmationEntityRecognizer(),
                    new CurrencyEntityRecognizer(),
                    new DateTimeEntityRecognizer(),
                    new DimensionEntityRecognizer(),
                    new EmailEntityRecognizer(),
                    new GuidEntityRecognizer(),
                    new HashtagEntityRecognizer(),
                    new IpEntityRecognizer(),
                    new MentionEntityRecognizer(),
                    new NumberEntityRecognizer(),
                    new NumberRangeEntityRecognizer(),
                    new OrdinalEntityRecognizer(),
                    new PercentageEntityRecognizer(),
                    new PhoneNumberEntityRecognizer(),
                    new TemperatureEntityRecognizer(),
                    new UrlEntityRecognizer(),
                    new RegexEntityRecognizer()
                    {
                        Name = "color", Pattern = "(?i)(red|green|blue|purple|orange|violet|white|black)"
                    },
                    new RegexEntityRecognizer()
                    {
                        Name = "backgroundColor", Pattern = "(?i)(back|background) {color}"
                    },
                    new RegexEntityRecognizer()
                    {
                        Name = "foregroundColor", Pattern = "(?i)(foreground|front) {color}"
                    },
                }
            };
            var tc = CreateContext("intent a1 b2");

            var result = await recognizer.RecognizeAsync(tc, CancellationToken.None);

            // intent assertions
            Assert.AreEqual(1, result.Intents.Count, "Should recognize one intent");
            Assert.AreEqual("codeIntent", result.Intents.Select(i => i.Key).First(), "Should recognize codeIntent");

            // entity assertions from capture group
            dynamic entities = result.Entities;

            Assert.IsNotNull(entities.code, "should find code");
            Assert.IsNull(entities.color, "should not find color");
            Assert.AreEqual(2, entities.code.Count, "should find 2 codes");
            Assert.AreEqual("a1", (string)entities.code[0], "should find a1");
            Assert.AreEqual("b2", (string)entities.code[1], "should find b2");

            tc = CreateContext("I would like color red and orange");

            // intent assertions
            result = await recognizer.RecognizeAsync(tc, CancellationToken.None);

            Assert.AreEqual(1, result.Intents.Count, "Should recognize one intent");
            Assert.AreEqual("colorIntent", result.Intents.Select(i => i.Key).First(), "Should recognize colorIntent");

            // entity assertions from capture group
            entities = result.Entities;
            Assert.IsNotNull(entities.color, "should find color");
            Assert.IsNull(entities.code, "should not find code");
            Assert.AreEqual(2, entities.color.Count, "should find 2 colors");
            Assert.AreEqual("red", (string)entities.color[0], "should find red");
            Assert.AreEqual("orange", (string)entities.color[1], "should find orange");
        }
        public async Task RegexRecognizerTests_Intents()
        {
            var recognizer = new RegexRecognizer()
            {
                Intents = new List <IntentPattern>()
                {
                    new IntentPattern("codeIntent", "(?<code>[a-z][0-9])"),
                    new IntentPattern("colorIntent", "(?i)(color|colour)"),
                },
                Entities = new EntityRecognizerSet()
                {
                    new AgeEntityRecognizer(),
                    new ConfirmationEntityRecognizer(),
                    new CurrencyEntityRecognizer(),
                    new DateTimeEntityRecognizer(),
                    new DimensionEntityRecognizer(),
                    new EmailEntityRecognizer(),
                    new GuidEntityRecognizer(),
                    new HashtagEntityRecognizer(),
                    new IpEntityRecognizer(),
                    new MentionEntityRecognizer(),
                    new NumberEntityRecognizer(),
                    new NumberRangeEntityRecognizer(),
                    new OrdinalEntityRecognizer(),
                    new PercentageEntityRecognizer(),
                    new PhoneNumberEntityRecognizer(),
                    new TemperatureEntityRecognizer(),
                    new UrlEntityRecognizer(),
                    new RegexEntityRecognizer()
                    {
                        Name = "color", Pattern = "(?i)(red|green|blue|purple|orange|violet|white|black)"
                    },
                    new RegexEntityRecognizer()
                    {
                        Name = "backgroundColor", Pattern = "(?i)(back|background) {color}"
                    },
                    new RegexEntityRecognizer()
                    {
                        Name = "foregroundColor", Pattern = "(?i)(foreground|front) {color}"
                    },
                }
            };

            // test with DC
            var dc     = CreateContext("intent a1 b2");
            var result = await recognizer.RecognizeAsync(dc, dc.Context.Activity, CancellationToken.None);

            ValidateCodeIntent(result);

            dc     = CreateContext("I would like color red and orange");
            result = await recognizer.RecognizeAsync(dc, dc.Context.Activity, CancellationToken.None);

            ValidateColorIntent(result);

            dc = CreateContext(string.Empty);

            // test custom activity
            var activity = Activity.CreateMessageActivity();

            activity.Text   = "intent a1 b2";
            activity.Locale = Culture.English;
            result          = await recognizer.RecognizeAsync(dc, (Activity)activity, CancellationToken.None);

            ValidateCodeIntent(result);

            activity.Text = "I would like color red and orange";
            result        = await recognizer.RecognizeAsync(dc, (Activity)activity, CancellationToken.None);

            ValidateColorIntent(result);
        }
示例#8
0
        public RootDialog() : base(nameof(RootDialog))
        {
            string[] paths    = { ".", "Dialogs", $"RootDialog.lg" };
            var      fullPath = Path.Combine(paths);

            _templates = Templates.ParseFile(fullPath);

            Recognizer = new RegexRecognizer()
            {
                Intents = new List <IntentPattern>()
                {
                    new IntentPattern()
                    {
                        Intent  = "ChangeLang",
                        Pattern = "(language|speak|change)"
                    },
                    new IntentPattern()
                    {
                        Intent  = "Help",
                        Pattern = "(help|options)"
                    },
                    new IntentPattern()
                    {
                        Intent  = "Hero",
                        Pattern = "hero"
                    }
                }
            };

            Triggers = new List <OnCondition>
            {
                new OnConversationUpdateActivity()
                {
                    Actions = WelcomeUserSteps()
                },
                new OnIntent()
                {
                    Intent  = "ChangeLang",
                    Actions = new List <Dialog>()
                    {
                        new TextInput()
                        {
                            AlwaysPrompt  = true,
                            Property      = "dialog.LanguagePreference",
                            Prompt        = new ActivityTemplate("${LanguageChoicePrompt()}"),
                            InvalidPrompt = new ActivityTemplate("${InvalidChoice()}"),
                            Validations   = new List <BoolExpression>()
                            {
                                new BoolExpression("this.value == 'en' || this.value == 'it' || this.value == 'fr' || this.value == 'es'")
                            }
                        },
                        new SetProperty()
                        {
                            Property = "user.LanguagePreference",
                            Value    = "=dialog.LanguagePreference"
                        },
                        new SendActivity("${ShowSelection()}"),
                    }
                },
                new OnIntent()
                {
                    Intent  = "Hero",
                    Actions = new List <Dialog>()
                    {
                        new SendActivity("${HeroCard()}")
                    }
                },
                new OnIntent()
                {
                    Intent  = "Help",
                    Actions = new List <Dialog>()
                    {
                        new SendActivity("${HelpInfo()}")
                    }
                },
                new OnUnknownIntent()
                {
                    Actions = new List <Dialog>()
                    {
                        new SendActivity("You said: '${turn.Activity.Text}'"),
                    }
                }
            };

            Generator = new TemplateEngineLanguageGenerator(_templates);
        }