Exemple #1
0
        private ILuisAction ResolveActionFromLuisIntent(LuisResult result,
                                                        out string intentName,
                                                        out IList <EntityRecommendation> intentEntities,
                                                        Func <PropertyInfo, IEnumerable <EntityRecommendation>, EntityRecommendation> entityExtractor = null)
        {
            intentEntities = default(IList <EntityRecommendation>);
            result.ThrowIfNull(nameof(result));

            // Has Intent?
            intentName = (result.TopScoringIntent ?? result.Intents?.MaxBy(i => i.Score ?? 0d)).Intent;
            if (string.IsNullOrWhiteSpace(intentName))
            {
                return(null);
            }

            // Set out intent entities reference
            intentEntities = result.Entities;

            // Get Actions that map to this intent
            if (!this.luisActions.TryGetValue(intentName, out Type actionType))
            {
                return(null);
            }

            // Get the action instance and check if it implements ILuisAction
            var luisAction = Activator.CreateInstance(actionType) as ILuisAction;

            if (luisAction == null)
            {
                return(null);
            }

            // Try complete parameters from entities
            var properties = luisAction.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            AssignEntitiesToMembers(luisAction, properties, result.Entities, entityExtractor);

            return(luisAction);
        }