private static DateTimeResolutionResult GetAgoLaterResult( DateTimeParseResult durationParseResult, double number, IImmutableDictionary <string, string> unitMap, string srcUnit, string afterStr, string beforeStr, System.DateTime referenceTime, IDateTimeUtilityConfiguration utilityConfiguration, AgoLaterMode mode) { var ret = new DateTimeResolutionResult(); if (unitMap.ContainsKey(srcUnit)) { var unitStr = unitMap[srcUnit]; var numStr = number.ToString(CultureInfo.InvariantCulture); var result = new DateTimeResolutionResult(); if (MatchingUtil.ContainsAgoLaterIndex(afterStr, utilityConfiguration.AgoRegex)) { if (mode.Equals(AgoLaterMode.Date)) { result = GetDateResult(unitStr, numStr, referenceTime, false); } else if (mode.Equals(AgoLaterMode.DateTime)) { result = GetDateTimeResult(unitStr, numStr, referenceTime, false); } ((DateTimeResolutionResult)durationParseResult.Value).Mod = TimeTypeConstants.beforeMod; result.SubDateTimeEntities = new List <object> { durationParseResult }; return(result); } if (MatchingUtil.ContainsAgoLaterIndex(afterStr, utilityConfiguration.LaterRegex) || MatchingUtil.ContainsInIndex(beforeStr, utilityConfiguration.InConnectorRegex)) { if (mode.Equals(AgoLaterMode.Date)) { result = GetDateResult(unitStr, numStr, referenceTime, true); } else if (mode.Equals(AgoLaterMode.DateTime)) { result = GetDateTimeResult(unitStr, numStr, referenceTime, true); } ((DateTimeResolutionResult)durationParseResult.Value).Mod = TimeTypeConstants.afterMod; result.SubDateTimeEntities = new List <object> { durationParseResult }; return(result); } } return(ret); }
private static DateTimeResolutionResult GetAgoLaterResult(IParser numberParser, ExtractResult er, IImmutableDictionary <string, string> unitMap, string srcUnit, string afterStr, string beforeStr, System.DateTime referenceTime, IDateTimeUtilityConfiguration utilityConfiguration, AgoLaterMode mode) { var ret = new DateTimeResolutionResult(); var pr = numberParser.Parse(er); var number = int.Parse(pr.ResolutionStr); if (unitMap.ContainsKey(srcUnit)) { var unitStr = unitMap[srcUnit]; var numStr = number.ToString(); if (MatchingUtil.ContainsAgoLaterIndex(afterStr, utilityConfiguration.AgoStringList)) { if (mode.Equals(AgoLaterMode.Date)) { return(GetDateResult(unitStr, numStr, referenceTime, false)); } if (mode.Equals(AgoLaterMode.DateTime)) { return(GetDateTimeResult(unitStr, numStr, referenceTime, false)); } } if (MatchingUtil.ContainsAgoLaterIndex(afterStr, utilityConfiguration.LaterStringList) || MatchingUtil.ContainsInIndex(beforeStr, utilityConfiguration.InStringList)) { if (mode.Equals(AgoLaterMode.Date)) { return(GetDateResult(unitStr, numStr, referenceTime, true)); } if (mode.Equals(AgoLaterMode.DateTime)) { return(GetDateTimeResult(unitStr, numStr, referenceTime, true)); } } } return(ret); }
private static DateTimeResolutionResult GetAgoLaterResult( DateTimeParseResult durationParseResult, string afterStr, string beforeStr, System.DateTime referenceTime, IDateTimeUtilityConfiguration utilityConfiguration, AgoLaterMode mode) { var ret = new DateTimeResolutionResult(); var resultDateTime = referenceTime; var timex = durationParseResult.TimexStr; if (MatchingUtil.ContainsAgoLaterIndex(afterStr, utilityConfiguration.AgoRegex)) { resultDateTime = DurationParsingUtil.ShiftDateTime(timex, referenceTime, false); ((DateTimeResolutionResult)durationParseResult.Value).Mod = Constants.BEFORE_MOD; } else if (MatchingUtil.ContainsAgoLaterIndex(afterStr, utilityConfiguration.LaterRegex) || MatchingUtil.ContainsInIndex(beforeStr, utilityConfiguration.InConnectorRegex)) { resultDateTime = DurationParsingUtil.ShiftDateTime(timex, referenceTime, true); ((DateTimeResolutionResult)durationParseResult.Value).Mod = Constants.AFTER_MOD; } if (resultDateTime != referenceTime) { if (mode.Equals(AgoLaterMode.Date)) { ret.Timex = $"{FormatUtil.LuisDate(resultDateTime)}"; } else if (mode.Equals(AgoLaterMode.DateTime)) { ret.Timex = $"{FormatUtil.LuisDateTime(resultDateTime)}"; } ret.FutureValue = ret.PastValue = resultDateTime; ret.SubDateTimeEntities = new List <object> { durationParseResult }; ret.Success = true; } return(ret); }
private static DateTimeResolutionResult GetAgoLaterResult(double number, IImmutableDictionary <string, string> unitMap, string srcUnit, string afterStr, string beforeStr, System.DateTime referenceTime, IDateTimeUtilityConfiguration utilityConfiguration, AgoLaterMode mode) { var ret = new DateTimeResolutionResult(); if (unitMap.ContainsKey(srcUnit)) { var unitStr = unitMap[srcUnit]; var numStr = number.ToString(CultureInfo.InvariantCulture); if (MatchingUtil.ContainsAgoLaterIndex(afterStr, utilityConfiguration.AgoRegex)) { if (mode.Equals(AgoLaterMode.Date)) { return(GetDateResult(unitStr, numStr, referenceTime, false)); } if (mode.Equals(AgoLaterMode.DateTime)) { return(GetDateTimeResult(unitStr, numStr, referenceTime, false)); } } if (MatchingUtil.ContainsAgoLaterIndex(afterStr, utilityConfiguration.LaterRegex) || MatchingUtil.ContainsInIndex(beforeStr, utilityConfiguration.InConnectorRegex)) { if (mode.Equals(AgoLaterMode.Date)) { return(GetDateResult(unitStr, numStr, referenceTime, true)); } if (mode.Equals(AgoLaterMode.DateTime)) { return(GetDateTimeResult(unitStr, numStr, referenceTime, true)); } } } return(ret); }