public static string GenerateEndInclusiveTimex(string originalTimex, DatePeriodTimexType datePeriodTimexType,
                                                       DateObject startDate, DateObject endDate)
        {
            var timexEndInclusive = TimexUtility.GenerateDatePeriodTimex(startDate, endDate, datePeriodTimexType);

            // Sometimes the original timex contains fuzzy part like "XXXX-05-31"
            // The fuzzy part needs to stay the same in the new end-inclusive timex
            if (originalTimex.Contains(Constants.TimexFuzzy) && originalTimex.Length == timexEndInclusive.Length)
            {
                var timexCharSet = new char[timexEndInclusive.Length];

                for (int i = 0; i < originalTimex.Length; i++)
                {
                    if (originalTimex[i] != Constants.TimexFuzzy)
                    {
                        timexCharSet[i] = timexEndInclusive[i];
                    }
                    else
                    {
                        timexCharSet[i] = Constants.TimexFuzzy;
                    }
                }

                timexEndInclusive = new string(timexCharSet);
            }

            return(timexEndInclusive);
        }
Exemple #2
0
        public DateTimeParseResult SetInclusivePeriodEnd(DateTimeParseResult slot)
        {
            if (slot.Type == $"{ParserTypeName}.{Constants.SYS_DATETIME_DATEPERIOD}")
            {
                var timexComponents = slot.TimexStr.Split(Constants.DatePeriodTimexSplitter, StringSplitOptions.RemoveEmptyEntries);

                // Only handle DatePeriod like "(StartDate,EndDate,Duration)"
                if (timexComponents.Length == 3)
                {
                    var value    = (SortedDictionary <string, object>)slot.Value;
                    var altTimex = string.Empty;

                    if (value != null && value.ContainsKey(ResolutionKey.ValueSet))
                    {
                        var valueSet = value[ResolutionKey.ValueSet] as IList <Dictionary <string, string> >;

                        if (valueSet != null && valueSet.Any())
                        {
                            foreach (var values in valueSet)
                            {
                                // This is only a sanity check
                                if (values.ContainsKey(DateTimeResolutionKey.START) && values.ContainsKey(DateTimeResolutionKey.END) && values.ContainsKey(DateTimeResolutionKey.Timex))
                                {
                                    var startDate           = DateObject.Parse(values[DateTimeResolutionKey.START]);
                                    var endDate             = DateObject.Parse(values[DateTimeResolutionKey.END]);
                                    var durationStr         = timexComponents[2];
                                    var datePeriodTimexType = TimexUtility.GetDatePeriodTimexType(durationStr);
                                    endDate = TimexUtility.OffsetDateObject(endDate, offset: 1, timexType: datePeriodTimexType);
                                    var timex = TimexUtility.GenerateDatePeriodTimex(startDate, endDate, datePeriodTimexType);
                                    values[DateTimeResolutionKey.Timex] = TimexUtility.GenerateAlterTimex(slot.TimexStr, timex);
                                    values[DateTimeResolutionKey.END]   = FormatUtil.LuisDate(endDate);

                                    if (string.IsNullOrEmpty(altTimex))
                                    {
                                        altTimex = values[DateTimeResolutionKey.Timex];
                                    }
                                }
                            }
                        }
                    }

                    slot.Value    = value;
                    slot.TimexStr = altTimex;
                }
            }

            return(slot);
        }
Exemple #3
0
        public DateTimeParseResult SetInclusivePeriodEnd(DateTimeParseResult slot)
        {
            if (slot.Type == $"{ParserTypeName}.{Constants.SYS_DATETIME_DATEPERIOD}")
            {
                var timexComponents = slot.TimexStr.Split(Constants.DatePeriodTimexSplitter, StringSplitOptions.RemoveEmptyEntries);

                // Only handle DatePeriod like "(StartDate,EndDate,Duration)"
                if (timexComponents.Length == 3)
                {
                    var startDate           = DateObject.Parse(timexComponents[0]);
                    var endDate             = DateObject.Parse(timexComponents[1]);
                    var durationStr         = timexComponents[2];
                    var datePeriodTimexType = TimexUtility.GetDatePeriodTimexType(durationStr);
                    endDate = TimexUtility.OffsetDateObject(endDate, offset: 1, timexType: datePeriodTimexType);

                    slot.TimexStr = TimexUtility.GenerateDatePeriodTimex(startDate, endDate, datePeriodTimexType);

                    var value = (SortedDictionary <string, object>)slot.Value;

                    if (value != null && value.ContainsKey(ResolutionKey.ValueSet))
                    {
                        var valueSet = value[ResolutionKey.ValueSet] as IList <Dictionary <string, string> >;

                        if (valueSet != null && valueSet.Any())
                        {
                            var values = valueSet[0];

                            if (values.ContainsKey("timex"))
                            {
                                values["timex"] = slot.TimexStr;
                            }

                            if (values.ContainsKey("end"))
                            {
                                values["end"] = FormatUtil.LuisDate(endDate);
                            }
                        }
                    }

                    slot.Value = value;
                }
            }

            return(slot);
        }