public DateTimeParseResult Parse(ExtractResult er, DateObject refTime) { var referenceTime = refTime; object value = null; if (er.Type.Equals(ParserName)) { var innerResult = ParseSimpleCases(er.Text, referenceTime); if (!innerResult.Success) { innerResult = MergeTwoTimePoints(er.Text, referenceTime); } if (!innerResult.Success) { innerResult = ParseNight(er.Text, referenceTime); } if (innerResult.Success) { innerResult.FutureResolution = new Dictionary <string, string> { { TimeTypeConstants.START_TIME, FormatUtil.FormatTime(((Tuple <DateObject, DateObject>)innerResult.FutureValue).Item1) }, { TimeTypeConstants.END_TIME, FormatUtil.FormatTime(((Tuple <DateObject, DateObject>)innerResult.FutureValue).Item2) } }; innerResult.PastResolution = new Dictionary <string, string> { { TimeTypeConstants.START_TIME, FormatUtil.FormatTime(((Tuple <DateObject, DateObject>)innerResult.PastValue).Item1) }, { TimeTypeConstants.END_TIME, FormatUtil.FormatTime(((Tuple <DateObject, DateObject>)innerResult.PastValue).Item2) } }; value = innerResult; } } var ret = new DateTimeParseResult { Text = er.Text, Start = er.Start, Length = er.Length, Type = er.Type, Data = er.Data, Value = value, TimexStr = value == null ? "" : ((DateTimeResolutionResult)value).Timex, ResolutionStr = "" }; return(ret); }
public DateTimeParseResult Parse(ExtractResult er, DateObject referenceTime) { object value = null; if (er.Type.Equals(ParserName)) { var innerResult = InternalParse(er.Text, referenceTime); if (innerResult.Success) { innerResult.FutureResolution = new Dictionary <string, string> { { TimeTypeConstants.TIME, FormatUtil.FormatTime((DateObject)innerResult.FutureValue) } }; innerResult.PastResolution = new Dictionary <string, string> { { TimeTypeConstants.TIME, FormatUtil.FormatTime((DateObject)innerResult.PastValue) } }; value = innerResult; } } var ret = new DateTimeParseResult { Text = er.Text, Start = er.Start, Length = er.Length, Type = er.Type, Data = er.Data, Value = value, TimexStr = value == null ? "" : ((DateTimeResolutionResult)value).Timex, ResolutionStr = "" }; return(ret); }
public DateTimeParseResult Parse(ExtractResult er, DateObject referenceTime) { object value = null; if (er.Type.Equals(ParserName)) { DateTimeResolutionResult innerResult; // Resolve timezome if ((config.Options & DateTimeOptions.EnablePreview) != 0 && er.Data is KeyValuePair <string, ExtractResult> ) { var timezoneEr = ((KeyValuePair <string, ExtractResult>)er.Data).Value; var timezonePr = config.TimeZoneParser.Parse(timezoneEr); innerResult = InternalParse(er.Text.Substring(0, (int)(er.Length - timezoneEr.Length)), referenceTime); if (timezonePr.Value != null) { innerResult.TimeZoneResolution = ((DateTimeResolutionResult)timezonePr.Value).TimeZoneResolution; } } else { innerResult = InternalParse(er.Text, referenceTime); } if (innerResult.Success) { innerResult.FutureResolution = new Dictionary <string, string> { { TimeTypeConstants.TIME, FormatUtil.FormatTime((DateObject)innerResult.FutureValue) } }; innerResult.PastResolution = new Dictionary <string, string> { { TimeTypeConstants.TIME, FormatUtil.FormatTime((DateObject)innerResult.PastValue) } }; value = innerResult; } } var ret = new DateTimeParseResult { Text = er.Text, Start = er.Start, Length = er.Length, Type = er.Type, Data = er.Data, Value = value, TimexStr = value == null ? "" : ((DateTimeResolutionResult)value).Timex, ResolutionStr = "" }; return(ret); }
private static DateTimeResolutionResult GetResolution(ExtractResult er, DateTimeParseResult pr, DateTimeResolutionResult ret) { var parentText = (string)((Dictionary <string, object>)er.Data)[ExtendedModelResult.ParentTextKey]; var type = pr.Type; var isPeriod = false; var isSinglePoint = false; string singlePointResolution = ""; string pastStartPointResolution = ""; string pastEndPointResolution = ""; string futureStartPointResolution = ""; string futureEndPointResolution = ""; string singlePointType = ""; string startPointType = ""; string endPointType = ""; if (type == Constants.SYS_DATETIME_DATEPERIOD || type == Constants.SYS_DATETIME_TIMEPERIOD || type == Constants.SYS_DATETIME_DATETIMEPERIOD) { isPeriod = true; switch (type) { case Constants.SYS_DATETIME_DATEPERIOD: startPointType = TimeTypeConstants.START_DATE; endPointType = TimeTypeConstants.END_DATE; pastStartPointResolution = FormatUtil.FormatDate(((Tuple <DateObject, DateObject>)ret.PastValue).Item1); pastEndPointResolution = FormatUtil.FormatDate(((Tuple <DateObject, DateObject>)ret.PastValue).Item2); futureStartPointResolution = FormatUtil.FormatDate(((Tuple <DateObject, DateObject>)ret.FutureValue).Item1); futureEndPointResolution = FormatUtil.FormatDate(((Tuple <DateObject, DateObject>)ret.FutureValue).Item2); break; case Constants.SYS_DATETIME_DATETIMEPERIOD: startPointType = TimeTypeConstants.START_DATETIME; endPointType = TimeTypeConstants.END_DATETIME; pastStartPointResolution = FormatUtil.FormatDateTime(((Tuple <DateObject, DateObject>)ret.PastValue).Item1); pastEndPointResolution = FormatUtil.FormatDateTime(((Tuple <DateObject, DateObject>)ret.PastValue).Item2); futureStartPointResolution = FormatUtil.FormatDateTime(((Tuple <DateObject, DateObject>)ret.FutureValue).Item1); futureEndPointResolution = FormatUtil.FormatDateTime(((Tuple <DateObject, DateObject>)ret.FutureValue).Item2); break; case Constants.SYS_DATETIME_TIMEPERIOD: startPointType = TimeTypeConstants.START_TIME; endPointType = TimeTypeConstants.END_TIME; pastStartPointResolution = FormatUtil.FormatTime(((Tuple <DateObject, DateObject>)ret.PastValue).Item1); pastEndPointResolution = FormatUtil.FormatTime(((Tuple <DateObject, DateObject>)ret.PastValue).Item2); futureStartPointResolution = FormatUtil.FormatTime(((Tuple <DateObject, DateObject>)ret.FutureValue).Item1); futureEndPointResolution = FormatUtil.FormatTime(((Tuple <DateObject, DateObject>)ret.FutureValue).Item2); break; } } else { isSinglePoint = true; switch (type) { case Constants.SYS_DATETIME_DATE: singlePointType = TimeTypeConstants.DATE; singlePointResolution = FormatUtil.FormatDate((DateObject)ret.FutureValue); break; case Constants.SYS_DATETIME_DATETIME: singlePointType = TimeTypeConstants.DATETIME; singlePointResolution = FormatUtil.FormatDateTime((DateObject)ret.FutureValue); break; case Constants.SYS_DATETIME_TIME: singlePointType = TimeTypeConstants.TIME; singlePointResolution = FormatUtil.FormatTime((DateObject)ret.FutureValue); break; } } if (isPeriod) { ret.FutureResolution = new Dictionary <string, string> { { startPointType, futureStartPointResolution }, { endPointType, futureEndPointResolution }, { ExtendedModelResult.ParentTextKey, parentText } }; ret.PastResolution = new Dictionary <string, string> { { startPointType, pastStartPointResolution }, { endPointType, pastEndPointResolution }, { ExtendedModelResult.ParentTextKey, parentText } }; } else if (isSinglePoint) { ret.FutureResolution = new Dictionary <string, string> { { singlePointType, singlePointResolution }, { ExtendedModelResult.ParentTextKey, parentText } }; ret.PastResolution = new Dictionary <string, string> { { singlePointType, singlePointResolution }, { ExtendedModelResult.ParentTextKey, parentText } }; } if (((DateTimeResolutionResult)pr.Value).TimeZoneResolution != null) { ret.TimeZoneResolution = ((DateTimeResolutionResult)pr.Value).TimeZoneResolution; } return(ret); }
private static DateTimeResolutionResult GetResolution(ExtractResult er, DateTimeParseResult pr, DateTimeResolutionResult ret) { var parentText = (string)((Dictionary <string, object>)er.Data)[ExtendedModelResult.ParentTextKey]; var type = pr.Type; var singlePointResolution = ""; var pastStartPointResolution = ""; var pastEndPointResolution = ""; var futureStartPointResolution = ""; var futureEndPointResolution = ""; var singlePointType = ""; var startPointType = ""; var endPointType = ""; if (type == Constants.SYS_DATETIME_DATEPERIOD || type == Constants.SYS_DATETIME_TIMEPERIOD || type == Constants.SYS_DATETIME_DATETIMEPERIOD) { switch (type) { case Constants.SYS_DATETIME_DATEPERIOD: startPointType = TimeTypeConstants.START_DATE; endPointType = TimeTypeConstants.END_DATE; pastStartPointResolution = FormatUtil.FormatDate(((Tuple <DateObject, DateObject>)ret.PastValue).Item1); pastEndPointResolution = FormatUtil.FormatDate(((Tuple <DateObject, DateObject>)ret.PastValue).Item2); futureStartPointResolution = FormatUtil.FormatDate(((Tuple <DateObject, DateObject>)ret.FutureValue).Item1); futureEndPointResolution = FormatUtil.FormatDate(((Tuple <DateObject, DateObject>)ret.FutureValue).Item2); break; case Constants.SYS_DATETIME_DATETIMEPERIOD: startPointType = TimeTypeConstants.START_DATETIME; endPointType = TimeTypeConstants.END_DATETIME; if (ret.PastValue is Tuple <DateObject, DateObject> tuple) { pastStartPointResolution = FormatUtil.FormatDateTime(tuple.Item1); pastEndPointResolution = FormatUtil.FormatDateTime(tuple.Item2); futureStartPointResolution = FormatUtil.FormatDateTime(((Tuple <DateObject, DateObject>)ret.FutureValue).Item1); futureEndPointResolution = FormatUtil.FormatDateTime(((Tuple <DateObject, DateObject>)ret.FutureValue).Item2); } else if (ret.PastValue is DateObject datetime) { pastStartPointResolution = FormatUtil.FormatDateTime(datetime); futureStartPointResolution = FormatUtil.FormatDateTime((DateObject)ret.FutureValue); } break; case Constants.SYS_DATETIME_TIMEPERIOD: startPointType = TimeTypeConstants.START_TIME; endPointType = TimeTypeConstants.END_TIME; pastStartPointResolution = FormatUtil.FormatTime(((Tuple <DateObject, DateObject>)ret.PastValue).Item1); pastEndPointResolution = FormatUtil.FormatTime(((Tuple <DateObject, DateObject>)ret.PastValue).Item2); futureStartPointResolution = FormatUtil.FormatTime(((Tuple <DateObject, DateObject>)ret.FutureValue).Item1); futureEndPointResolution = FormatUtil.FormatTime(((Tuple <DateObject, DateObject>)ret.FutureValue).Item2); break; } } else { switch (type) { case Constants.SYS_DATETIME_DATE: singlePointType = TimeTypeConstants.DATE; singlePointResolution = FormatUtil.FormatDate((DateObject)ret.FutureValue); break; case Constants.SYS_DATETIME_DATETIME: singlePointType = TimeTypeConstants.DATETIME; singlePointResolution = FormatUtil.FormatDateTime((DateObject)ret.FutureValue); break; case Constants.SYS_DATETIME_TIME: singlePointType = TimeTypeConstants.TIME; singlePointResolution = FormatUtil.FormatTime((DateObject)ret.FutureValue); break; } } ret.FutureResolution = new Dictionary <string, string>(); ret.PastResolution = new Dictionary <string, string>(); if (!string.IsNullOrEmpty(futureStartPointResolution)) { ret.FutureResolution.Add(startPointType, futureStartPointResolution); } if (!string.IsNullOrEmpty(futureEndPointResolution)) { ret.FutureResolution.Add(endPointType, futureEndPointResolution); } if (!string.IsNullOrEmpty(pastStartPointResolution)) { ret.PastResolution.Add(startPointType, pastStartPointResolution); } if (!string.IsNullOrEmpty(pastEndPointResolution)) { ret.PastResolution.Add(endPointType, pastEndPointResolution); } if (!string.IsNullOrEmpty(singlePointResolution)) { ret.FutureResolution.Add(singlePointType, singlePointResolution); ret.PastResolution.Add(singlePointType, singlePointResolution); } if (!string.IsNullOrEmpty(parentText)) { ret.FutureResolution.Add(ExtendedModelResult.ParentTextKey, parentText); ret.PastResolution.Add(ExtendedModelResult.ParentTextKey, parentText); } if (((DateTimeResolutionResult)pr.Value).Mod != null) { ret.Mod = ((DateTimeResolutionResult)pr.Value).Mod; } if (((DateTimeResolutionResult)pr.Value).TimeZoneResolution != null) { ret.TimeZoneResolution = ((DateTimeResolutionResult)pr.Value).TimeZoneResolution; } return(ret); }