Ejemplo n.º 1
0
        /// <summary>
        /// Builds the action from a contextual action.
        /// </summary>
        /// <param name="action">The contextual action.</param>
        /// <param name="intentName">The LUIS intent name of the parent action.</param>
        /// <returns>The parent action.</returns>
        public static ILuisAction BuildContextForContextualAction(ILuisAction action, out string intentName)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            if (!LuisActionResolver.IsContextualAction(action))
            {
                intentName = null;
                return(null);
            }

            var contextType = action
                              .GetType()
                              .GetInterfaces()
                              .First(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ILuisContextualAction <>))
                              .GetGenericArguments()[0];

            var result = Activator.CreateInstance(contextType) as ILuisAction;

            intentName = LuisActionResolver.GetActionDefinition(result).IntentName;

            var isContextual = false;

            LuisActionResolver.IsValidContextualAction(action, result, out isContextual);

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Indicates if the action can be started, either is not a contextual action or it can create the contextual action directly.
        /// </summary>
        /// <param name="action">The action to validate.</param>
        /// <param name="actionDefinition">The action definition.</param>
        public static bool CanStartWithNoContextAction(ILuisAction action, out LuisActionBindingAttribute actionDefinition)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            if (!LuisActionResolver.IsContextualAction(action))
            {
                actionDefinition = null;
                return(true);
            }

            actionDefinition = LuisActionResolver.GetActionDefinition(action);

            return(actionDefinition.CanExecuteWithNoContext);
        }