コード例 #1
0
        /// <summary>
        /// Register an intent handler with this <see cref="IntentRouter"/>.
        /// </summary>
        /// <param name="intentName">Name of the intent as defined in the LUIS application.</param>
        /// <param name="confidenceThreshold">Confidence score required to accitvate the handler.</param>
        /// <param name="handler">Function to call when routing the intent to this handler.</param>
        public void RegisterHandler(string intentName, double confidenceThreshold, IntentHandlerFunc handler)
        {
            if (string.IsNullOrWhiteSpace(intentName))
            {
                throw new ArgumentException(nameof(intentName));
            }
            if ((confidenceThreshold < 0) || (confidenceThreshold > 1))
            {
                throw new ArgumentOutOfRangeException(nameof(confidenceThreshold));
            }
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }
            if (_handlers.ContainsKey(intentName))
            {
                throw new InvalidOperationException($"Router already has a handler for intent '{intentName}'");
            }

            _handlers[intentName] = new HandlerDetails()
            {
                Threshold = confidenceThreshold,
                Exec      = handler
            };
        }
コード例 #2
0
        public static void RegisterHandler(Type intentType, IntentHandlerFunc intentHandler, double threshold)
        {
            var             intentAttribute = intentType.GetCustomAttribute <IntentAttribute>();
            var             intentName      = intentAttribute.Name;
            IList <Handler> handlersList;

            if (!handlersContainer.TryGetValue(intentName, out handlersList))
            {
                handlersContainer[intentName] = new List <Handler>()
                {
                    new Handler(threshold, intentHandler)
                };
            }
            else
            {
                handlersList.Add(new Handler(threshold, intentHandler));
            }
        }
コード例 #3
0
 public Handler(double threshold, IntentHandlerFunc exec)
 {
     Threshold = threshold;
     Exec      = exec;
 }