コード例 #1
0
 private void SetupOnRecognize()
 {
     this.OnRecognize(async(context) =>
     {
         Middleware.Intent i = await RecognizeAndMap(context.Request.AsMessageActivity()?.Text);
         return(new List <Middleware.Intent>()
         {
             i
         });
     });
 }
コード例 #2
0
        private async Task <Middleware.Intent> RecognizeAndMap(string utterance)
        {
            Middleware.Intent intent = new Middleware.Intent();

            // LUIS client throws an exception on Predict is the utterance is null / empty
            // so just skip those cases and return a non-match.
            if (string.IsNullOrWhiteSpace(utterance))
            {
                intent.Name  = string.Empty;
                intent.Score = 0.0;
            }
            else
            {
                LuisResult result = await _luisClient.Predict(utterance);

                if (result.TopScoringIntent == null)
                {
                    intent.Name  = string.Empty;
                    intent.Score = 0.0;
                }
                else
                {
                    intent.Name  = result.TopScoringIntent.Name;
                    intent.Score = result.TopScoringIntent.Score;
                }

                foreach (var luisEntityList in result.Entities.Values)
                {
                    foreach (var luisEntity in luisEntityList)
                    {
                        intent.Entities.Add(new LuisEntity(luisEntity));
                    }
                }
            }

            return(intent);
        }