public async Task TestIntentRecognize() { var mockResult = new Result { Score = 0.9, Label = new Label { Name = "mockLabel" } }; var mockScore = new List <Result>() { mockResult }; var mockResolver = new MockResolver(mockScore); var recognizer = new OrchestratorAdaptiveRecognizer(string.Empty, string.Empty, mockResolver) { ModelPath = new StringExpression("fakePath"), SnapshotPath = new StringExpression("fakePath") }; TestAdapter adapter = new TestAdapter(TestAdapter.CreateConversation("ds")); var activity = MessageFactory.Text("hi"); var context = new TurnContext(adapter, activity); var dc = new DialogContext(new DialogSet(), context, new DialogState()); var result = await recognizer.RecognizeAsync(dc, activity, default); Assert.AreEqual(1, result.Intents.Count); Assert.IsTrue(result.Intents.ContainsKey("mockLabel")); Assert.AreEqual(0.9, result.Intents["mockLabel"].Score); }
public async Task TestEntityRecognize() { var mockResult = new Result { Score = 0.9, Label = new Label { Name = "mockLabel" } }; var mockScore = new List <Result> { mockResult }; var mockResolver = new MockResolver(mockScore); var recognizer = new OrchestratorAdaptiveRecognizer(string.Empty, string.Empty, mockResolver) { ModelPath = new StringExpression("fakePath"), SnapshotPath = new StringExpression("fakePath"), ExternalEntityRecognizer = new NumberEntityRecognizer() }; var adapter = new TestAdapter(TestAdapter.CreateConversation("ds")); var activity = MessageFactory.Text("12"); var context = new TurnContext(adapter, activity); var dc = new DialogContext(new DialogSet(), context, new DialogState()); var result = await recognizer.RecognizeAsync(dc, activity, default); Assert.NotNull(result.Entities); Assert.Equal(new JValue("12"), result.Entities["number"][0]); var resolution = result.Entities["$instance"]["number"][0]["resolution"]; Assert.Equal(new JValue("integer"), resolution["subtype"]); Assert.Equal(new JValue("12"), resolution["value"]); }
public async Task TestIntentRecognizeEmptyMessage() { var mockResult = new Result { Score = 0.9, Label = new Label { Name = "mockLabel" } }; var mockScore = new List <Result> { mockResult }; var mockResolver = new MockResolver(mockScore); var recognizer = new OrchestratorRecognizer(string.Empty, string.Empty, mockResolver) { ModelFolder = new StringExpression("fakePath"), SnapshotFile = new StringExpression("fakePath") }; var adapter = new TestAdapter(TestAdapter.CreateConversation("ds")); var activity = MessageFactory.Text(string.Empty); var context = new TurnContext(adapter, activity); var dc = new DialogContext(new DialogSet(), context, new DialogState()); var result = await recognizer.RecognizeAsync(dc, activity, default); Assert.Empty(result.Text); }
public async Task TestEntityRecognize() { var mockResult = new Result { Score = 0.9, Label = new Label { Name = "mockLabel" } }; var mockScore = new List <Result> { mockResult }; var mockEntityResult = new Result { Score = 0.75, Label = new Label { Name = "mockEntityLabel", Type = LabelType.Entity, Span = new Span { Offset = 17, Length = 7 } }, }; var mockEntityScore = new List <Result> { mockEntityResult }; var mockResolver = new MockResolver(mockScore, mockEntityScore); var recognizer = new OrchestratorRecognizer(string.Empty, string.Empty, mockResolver) { ModelFolder = new StringExpression("fakePath"), SnapshotFile = new StringExpression("fakePath"), ScoreEntities = true, ExternalEntityRecognizer = new NumberEntityRecognizer() }; var adapter = new TestAdapter(TestAdapter.CreateConversation("ds")); var activity = MessageFactory.Text("turn on light in room 12"); var context = new TurnContext(adapter, activity); var dc = new DialogContext(new DialogSet(), context, new DialogState()); var result = await recognizer.RecognizeAsync(dc, activity, default); Assert.NotNull(result.Entities); Assert.Equal(new JValue("12"), result.Entities["number"][0]); var resolution = result.Entities["$instance"]["number"][0]["resolution"]; Assert.Equal(new JValue("integer"), resolution["subtype"]); Assert.Equal(new JValue("12"), resolution["value"]); Assert.True(result.Entities.ContainsKey("mockEntityLabel")); Assert.Equal(0.75, result.Entities["mockEntityLabel"][0]["score"]); Assert.Equal("room 12", result.Entities["mockEntityLabel"][0]["text"]); Assert.Equal(17, result.Entities["mockEntityLabel"][0]["start"]); Assert.Equal(24, result.Entities["mockEntityLabel"][0]["end"]); }
public async Task TestIntentRecognizeLogsTelemetry(bool?logPersonalInformation) { var mockResult1 = new Result { Score = 0.9, Label = new Label { Name = "mockLabel" } }; var mockResult2 = new Result { Score = 0.8, Label = new Label { Name = "mockLabel2" } }; var mockScore = new List <Result> { mockResult1, mockResult2 }; var mockResolver = new MockResolver(mockScore); var telemetryClient = new Mock <IBotTelemetryClient>(); var recognizer = new OrchestratorRecognizer(string.Empty, string.Empty, mockResolver) { ModelFolder = new StringExpression("fakePath"), SnapshotFile = new StringExpression("fakePath"), TelemetryClient = telemetryClient.Object, }; if (logPersonalInformation != null) { recognizer.LogPersonalInformation = logPersonalInformation; } var adapter = new TestAdapter(TestAdapter.CreateConversation("ds")); var activity = MessageFactory.Text("hi"); var context = new TurnContext(adapter, activity); var dc = new DialogContext(new DialogSet(), context, new DialogState()); var result = await recognizer.RecognizeAsync(dc, activity, default); if (logPersonalInformation == null) { // Should be false by default, when not specified by user. var(logPersonalInfo, _) = recognizer.LogPersonalInformation.TryGetValue(dc.State); Assert.False(logPersonalInfo); } Assert.Equal(2, result.Intents.Count); Assert.True(result.Intents.ContainsKey("mockLabel")); Assert.Equal(0.9, result.Intents["mockLabel"].Score); ValidateTelemetry(recognizer, telemetryClient, dc, activity, result, callCount: 1); }
public async Task TestIntentNoneRecognize() { var mockResult1 = new Result { Score = 0.3, Label = new Label { Name = "mockLabel" } }; var mockResultNone = new Result { Score = 0.8, Label = new Label { Name = "None" } }; var mockResult2 = new Result { Score = 0.6, Label = new Label { Name = "mockLabel2" } }; var mockScore = new List <Result> { mockResult1, mockResultNone, mockResult2 }.AsReadOnly(); var mockResolver = new MockResolver(mockScore); var recognizer = new OrchestratorRecognizer(string.Empty, string.Empty, mockResolver) { ModelFolder = new StringExpression("fakePath"), SnapshotFile = new StringExpression("fakePath") }; var adapter = new TestAdapter(TestAdapter.CreateConversation("ds")); var activity = MessageFactory.Text("hi"); var context = new TurnContext(adapter, activity); var dc = new DialogContext(new DialogSet(), context, new DialogState()); var result = await recognizer.RecognizeAsync(dc, activity, default); Assert.Equal(3, result.Intents.Count); List <Result> results = (List <Result>)result.Properties[OrchestratorRecognizer.ResultProperty]; Assert.Equal(AdaptiveRecognizer.NoneIntent, results[0].Label.Name); Assert.Equal(3, results.Count); Assert.True(result.Intents.ContainsKey("mockLabel")); Assert.Equal(0.3, result.Intents["mockLabel"].Score); Assert.True(result.Intents.ContainsKey(AdaptiveRecognizer.NoneIntent)); Assert.Equal(1.0, result.Intents[AdaptiveRecognizer.NoneIntent].Score); Assert.True(result.Intents.ContainsKey("mockLabel2")); Assert.Equal(0.6, result.Intents["mockLabel2"].Score); }
public async Task TestAmbiguousResults() { var mockResult1 = new Result { Score = 0.61, Label = new Label { Name = "mockLabel1" } }; var mockResult2 = new Result { Score = 0.62, Label = new Label { Name = "mockLabel2" } }; var mockScore = new List <Result>() { mockResult1, mockResult2 }; var mockResolver = new MockResolver(mockScore); var recognizer = new OrchestratorAdaptiveRecognizer(string.Empty, string.Empty, mockResolver) { ModelPath = new StringExpression("fakePath"), SnapshotPath = new StringExpression("fakePath"), DetectAmbiguousIntents = new BoolExpression(true), DisambiguationScoreThreshold = new NumberExpression(0.5) }; TestAdapter adapter = new TestAdapter(TestAdapter.CreateConversation("ds")); var activity = MessageFactory.Text("12"); var context = new TurnContext(adapter, activity); var dc = new DialogContext(new DialogSet(), context, new DialogState()); var result = await recognizer.RecognizeAsync(dc, activity, default); Assert.IsTrue(result.Intents.ContainsKey("ChooseIntent")); }