Ejemplo n.º 1
0
        /// <summary>
        /// Attempts a LUIS prediction on the specified text and if confidence is high enough, the intent is executed.
        /// </summary>
        /// <param name="text">
        /// The text used for the prediction.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> that yields the result of the operation as a <see cref="LuisMRResult"/>.
        /// </returns>
        public virtual Task <LuisMRResult> PredictAndHandleAsync(string text)
        {
            // Validate
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentException(nameof(text));
            }

            // Create a context and store the text
            PredictionContext context = new PredictionContext()
            {
                PredictionText = text
            };

            // Pass to context override
            return(PredictAndHandleAsync(context));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Attempts a LUIS prediction on the specified context and if confidence is high enough, the intent is executed.
        /// </summary>
        /// <param name="context">
        /// Context that is used for the prediction. Additional context may still be collected by
        /// the <see cref="ContextProviders"/>.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> that yields the result of the operation as a <see cref="LuisMRResult"/>.
        /// </returns>
        /// <remarks>
        /// At a minimum, <see cref="PredictionContext.PredictionText"/> must be included within the context.
        /// </remarks>
        public virtual async Task <LuisMRResult> PredictAndHandleAsync(PredictionContext context)
        {
            // Validate
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (string.IsNullOrEmpty(context.PredictionText))
            {
                throw new InvalidOperationException("At a minimum, PredictionText must be included within the context.");
            }

            // Make sure we have a client
            EnsureClient();

            // Create our result object
            LuisMRResult mrResult = new LuisMRResult()
            {
                Context = context
            };

            // Stage 1: Capture context
            CaptureContext(context);

            // Stage 2: Predict using the LUIS client
            mrResult.PredictionResult = await client.Predict(context.PredictionText);

            // Only do the next two stages if we have the minimum required confidence
            if (mrResult.PredictionResult.TopScoringIntent.Score >= MinimumIntentScore)
            {
                // Stage 3: Resolve Entities
                ResolveEntities(mrResult);

                // Stage 4: Handle Intents
                HandleIntent(mrResult);
            }

            // Done
            return(mrResult);
        }