Exemplo n.º 1
0
        public override async Task <ParseResult> ParseAsync(ChatState chatState, Chat_ParseField chatParseField, ChatMessage message)
        {
            int timezoneOffset = chatState.GetUserTimeZoneOffset();

            if (message.LuisDateOutput == null)
            {
                message.LuisDateOutput = await luisService.Parse(message.UserInput, timezoneOffset);
            }

            var assumeFuture = false;

            if (bool.TryParse(chatParseField?.GetProperty("AssumeFuture"), out bool test))
            {
                assumeFuture = test;
            }

            var results = ExtractDateResults(chatState, message.LuisDateOutput, assumeFuture);

            if ((results == null) || (results.Length == 0))
            {
                logger.InfoFormat("Parse: luis date parser got nothing. - {0}", (message.LuisDateOutput != null) ? JsonConvert.SerializeObject(message.LuisDateOutput) : "null");
                return(ParseResult.Failed);
            }

            if (version == 1)
            {
                return(ProcessAsV1Date(message, timezoneOffset, results));
            }

            return(ParseResult.CreateSuccess(results));
        }
Exemplo n.º 2
0
        private static string[] ExtractV1TimeEntities(ChatState state, LuisResponse luisResponse)
        {
            LuisDateParser parser = new LuisDateParser(state.GetUserTimeZoneOffset());

            var luisTimes = parser.ParseLuisTimes(luisResponse.Entities);

            return((from time in luisTimes
                    where time.Time != null
                    select time.Time.Format12Hour).ToArray());
        }
Exemplo n.º 3
0
        private void UpdateV1State(ChatState state, Chat_ParseField chatParseField, ParseResult result, ChatVariables variables)
        {
            DateTime date   = (DateTime)result.Answer;
            int      offset = state.GetUserTimeZoneOffset();

            variables[chatParseField.FieldName]           = date.AddHours(offset).ToShortDateString();
            variables[chatParseField.FieldName + "_Date"] = date;

            CheckIfAnswerHasPII(state, chatParseField, date.ToString(), PIIMask);
        }
Exemplo n.º 4
0
        private DateTimeParseResult[] ExtractDateResults(ChatState chatState, LuisResponse luisResponse, bool assumeFuture)
        {
            LuisDateParser parser = new LuisDateParser(chatState.GetUserTimeZoneOffset());

            if (luisResponse?.Entities.Length > 0)
            {
                return(parser.ParseLuisDates(luisResponse.Entities, assumeFuture));
            }

            return(null);
        }
Exemplo n.º 5
0
        public override async Task <ParseResult> ParseAsync(ChatState state, Chat_ParseField chatParseField, ChatMessage message)
        {
            if (message.LuisDateOutput == null)
            {
                message.LuisDateOutput = await luisService.Parse(message.UserInput, state.GetUserTimeZoneOffset());
            }

            if (message.LuisDateOutput?.Entities.Length > 0)
            {
                var v1Entities = ExtractV1TimeEntities(state, message.LuisDateOutput);
                if (v1Entities.Length > 0)
                {
                    return(ParseResult.CreateSuccess(v1Entities));
                }
            }

            logger.DebugFormat("Parse: Luis Time Parser got nothing. - {0}", (message.LuisDateOutput != null) ? JsonConvert.SerializeObject(message.LuisDateOutput) : "null");

            return(ParseResult.Failed);
        }