Пример #1
0
        public static async Task <QueryValueResult> QueryValueFromLuisAsync(
            ILuisService service,
            ILuisAction action,
            string paramName,
            object paramValue,
            CancellationToken token,
            Func <PropertyInfo, IEnumerable <EntityRecommendation>, EntityRecommendation> entityExtractor = null)
        {
            var originalValue = paramValue;

            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            if (string.IsNullOrWhiteSpace(paramName))
            {
                throw new ArgumentNullException(nameof(paramName));
            }

            if (paramValue == null)
            {
                throw new ArgumentNullException(nameof(paramValue));
            }

            var result = await service.QueryAsync(paramValue.ToString(), token);

            var queryIntent = result.Intents.FirstOrDefault();

            if (queryIntent != null)
            {
                if (!Intents.None.Equals(queryIntent.Intent, StringComparison.InvariantCultureIgnoreCase))
                {
                    string newIntentName;
                    var    newAction =
                        new LuisActionResolver(action.GetType().Assembly).ResolveActionFromLuisIntent(result,
                                                                                                      out newIntentName);
                    if (newAction != null && !newAction.GetType().Equals(action.GetType()))
                    {
                        return(new QueryValueResult(false)
                        {
                            NewAction = newAction,
                            NewIntent = newIntentName
                        });
                    }
                }
            }

            var properties = new List <PropertyInfo> {
                action.GetType().GetProperty(paramName, BindingFlags.Public | BindingFlags.Instance)
            };

            if (!AssignEntitiesToMembers(action, properties, result.Entities, entityExtractor))
            {
                return(new QueryValueResult(AssignValue(action, properties.First(), originalValue)));
            }

            return(new QueryValueResult(true));
        }
Пример #2
0
 public AppRootDialog() : base(new LuisService(new LuisModelAttribute("203c9bdc-1a3d-473b-8373-ef622e482601", "3a99606f687246c5b8d953ab4052afd8")))
 {
     _actionResolver = new LuisActionResolver(typeof(GetOrderStatusAction).Assembly);
 }