public JapaneseDateParserConfiguration(JapaneseDateTimeParserConfiguration configuration) { config = configuration; integerExtractor = new IntegerExtractor(); durationExtractor = new JapaneseDurationExtractorConfiguration(); numberParser = new BaseCJKNumberParser(new JapaneseNumberParserConfiguration()); }
public List <Token> MatchEach(IDateTimeExtractor extractor, string text, DateObject referenceTime) { var ret = new List <Token>(); var ers = extractor.Extract(text, referenceTime); foreach (var er in ers) { var beforeStr = text.Substring(0, er.Start ?? 0); var match = this.config.EachPrefixRegex.Match(beforeStr); if (match.Success) { ret.Add(new Token(match.Index, match.Index + match.Length + (er.Length ?? 0))); } else if (er.Type == Constants.SYS_DATETIME_TIME || er.Type == Constants.SYS_DATETIME_DATE) { // Cases like "every day at 2pm" or "every year on April 15th" var eachRegex = er.Type == Constants.SYS_DATETIME_TIME ? this.config.EachDayRegex : this.config.EachDateUnitRegex; match = eachRegex.Match(beforeStr); if (match.Success) { ret.Add(new Token(match.Index, match.Index + match.Length + (er.Length ?? 0))); } } } return(ret); }
public List <Token> MatchEach(IDateTimeExtractor extractor, string text, DateObject reference) { var ret = new List <Token>(); var matches = config.SetEachRegex.Matches(text); foreach (Match match in matches) { if (match.Success) { // "3pm *each* day" var trimmedText = text.Remove(match.Index, match.Length); var ers = extractor.Extract(trimmedText, reference); foreach (var er in ers) { if (er.Start <= match.Index && (er.Start + er.Length) > match.Index) { ret.Add(new Token(er.Start ?? 0, (er.Start + match.Length + er.Length) ?? 0)); } } } } // handle "Mondays" matches = this.config.SetWeekDayRegex.Matches(text); foreach (Match match in matches) { if (match.Success) { Tuple <string, int> weekdayTuple = config.WeekDayGroupMatchTuple(match); string weekday = weekdayTuple.Item1; int del = weekdayTuple.Item2; var trimmedText = text.Remove(match.Index, match.Length); trimmedText = trimmedText.Insert(match.Index, weekday); var ers = extractor.Extract(trimmedText, reference); foreach (var er in ers) { if (er.Start <= match.Index && er.Text.Contains(match.Groups["weekday"].Value)) { var len = (er.Length ?? 0) + del; if (match.Groups[Constants.PrefixGroupName].ToString().Length > 0) { len += match.Groups[Constants.PrefixGroupName].ToString().Length; } if (match.Groups[Constants.SuffixGroupName].ToString().Length > 0) { len += match.Groups[Constants.SuffixGroupName].ToString().Length; } ret.Add(new Token(er.Start ?? 0, er.Start + len ?? 0)); } } } } return(ret); }
public ChineseDateParserConfiguration(ChineseDateTimeParserConfiguration configuration) { config = configuration; integerExtractor = new IntegerExtractor(); ordinalExtractor = new OrdinalExtractor(); durationExtractor = new ChineseDurationExtractorConfiguration(); numberParser = new BaseCJKNumberParser(new ChineseNumberParserConfiguration(new BaseNumberOptionsConfiguration(configuration.Culture))); }
public DateParser(ChineseDateTimeParserConfiguration configuration) { config = configuration; integerExtractor = new IntegerExtractor(); ordinalExtractor = new OrdinalExtractor(); durationExtractor = new DurationExtractorChs(); numberParser = new BaseCJKNumberParser(new ChineseNumberParserConfiguration()); }
public static DateTimeResolutionResult ParseDurationWithAgoAndLater(string text, DateObject referenceTime, IDateTimeExtractor durationExtractor, IDateTimeParser durationParser, IImmutableDictionary <string, string> unitMap, Regex unitRegex, IDateTimeUtilityConfiguration utilityConfiguration, AgoLaterMode mode) { var ret = new DateTimeResolutionResult(); var durationRes = durationExtractor.Extract(text, referenceTime); if (durationRes.Count > 0) { var pr = durationParser.Parse(durationRes[0], referenceTime); var match = unitRegex.Match(text); if (match.Success) { var afterStr = text.Substring((int)durationRes[0].Start + (int)durationRes[0].Length) .Trim() .ToLowerInvariant(); var beforeStr = text.Substring(0, (int)durationRes[0].Start) .Trim() .ToLowerInvariant(); var srcUnit = match.Groups["unit"].Value.ToLowerInvariant(); if (pr.Value != null) { var durationResult = (DateTimeResolutionResult)pr.Value; var numStr = durationResult.Timex.Substring(0, durationResult.Timex.Length - 1) .Replace("P", "") .Replace("T", ""); if (double.TryParse(numStr, out double number)) { return(GetAgoLaterResult( pr, number, unitMap, srcUnit, afterStr, beforeStr, referenceTime, utilityConfiguration, mode)); } } } } return(ret); }
public List <Token> MatchEach(IDateTimeExtractor extractor, string text, DateObject reference) { var ret = new List <Token>(); var matches = config.SetEachRegex.Matches(text); foreach (Match match in matches) { if (match.Success) { var trimedText = text.Remove(match.Index, match.Length); var ers = extractor.Extract(trimedText, reference); foreach (var er in ers) { if (er.Start <= match.Index && (er.Start + er.Length) > match.Index) { ret.Add(new Token(er.Start ?? 0, (er.Start + match.Length + er.Length) ?? 0)); } } } } // handle "Mondays" matches = this.config.SetWeekDayRegex.Matches(text); foreach (Match match in matches) { if (match.Success) { var trimedText = text.Remove(match.Index, match.Length); trimedText = trimedText.Insert(match.Index, match.Groups["weekday"].ToString()); var ers = extractor.Extract(trimedText, reference); foreach (var er in ers) { if (er.Start <= match.Index && er.Text.Contains(match.Groups["weekday"].Value)) { var len = (er.Length ?? 0) + 1; if (match.Groups["prefix"].ToString() != string.Empty) { len += match.Groups["prefix"].ToString().Length; } ret.Add(new Token(er.Start ?? 0, er.Start + len ?? 0)); } } } } return(ret); }
public static DateTimeResolutionResult ParseDurationWithAgoAndLater(string text, DateObject referenceTime, IDateTimeExtractor durationExtractor, IDateTimeParser durationParser, IImmutableDictionary <string, string> unitMap, Regex unitRegex, IDateTimeUtilityConfiguration utilityConfiguration) { var ret = new DateTimeResolutionResult(); var durationRes = durationExtractor.Extract(text, referenceTime); if (durationRes.Count > 0) { var pr = durationParser.Parse(durationRes[0], referenceTime); var matches = unitRegex.Matches(text); if (matches.Count > 0) { var afterStr = text.Substring((int)durationRes[0].Start + (int)durationRes[0].Length) .Trim() .ToLowerInvariant(); var beforeStr = text.Substring(0, (int)durationRes[0].Start) .Trim() .ToLowerInvariant(); var mode = AgoLaterMode.Date; if (pr.TimexStr.Contains("T")) { mode = AgoLaterMode.DateTime; } if (pr.Value != null) { return(GetAgoLaterResult( pr, afterStr, beforeStr, referenceTime, utilityConfiguration, mode)); } } } return(ret); }
public JapaneseDateParserConfiguration(JapaneseDateTimeParserConfiguration configuration) { config = configuration; var numOptions = NumberOptions.None; if ((config.Options & DateTimeOptions.NoProtoCache) != 0) { numOptions = NumberOptions.NoProtoCache; } var numConfig = new BaseNumberOptionsConfiguration(config.Culture, numOptions); integerExtractor = new IntegerExtractor(); durationExtractor = new JapaneseDurationExtractorConfiguration(); numberParser = new BaseCJKNumberParser(new JapaneseNumberParserConfiguration(numConfig)); }
private DateTimeResolutionResult ParseEach(IDateTimeExtractor extractor, IDateTimeParser parser, string text, DateObject refDate) { var ret = new DateTimeResolutionResult(); List <ExtractResult> ers = null; var success = false; // remove key words of set type from text var match = config.SetEachRegex.Match(text); if (match.Success) { var trimmedText = text.Remove(match.Index, match.Length); ers = extractor.Extract(trimmedText, refDate); if (ers.Count == 1 && ers.First().Length == trimmedText.Length) { success = true; } } // remove suffix 's' and "on" if existed and re-try match = this.config.SetWeekDayRegex.Match(text); if (match.Success) { var trimmedText = text.Remove(match.Index, match.Length); trimmedText = trimmedText.Insert(match.Index, config.WeekDayGroupMatchString(match)); ers = extractor.Extract(trimmedText, refDate); if (ers.Count == 1 && ers.First().Length == trimmedText.Length) { success = true; } } if (success) { var pr = parser.Parse(ers[0], refDate); ret = ResolveSet(ref ret, pr.TimexStr); } return(ret); }
private DateTimeResolutionResult ParseEach(IDateTimeExtractor extractor, IDateTimeParser parser, string text, DateObject refDate) { var ret = new DateTimeResolutionResult(); var ers = extractor.Extract(text, refDate); var success = false; foreach (var er in ers) { var beforeStr = text.Substring(0, er.Start ?? 0); var match = this.config.EachPrefixRegex.Match(beforeStr); if (match.Success && match.Length + er.Length == text.Length) { success = true; } else if (er.Type == Constants.SYS_DATETIME_TIME || er.Type == Constants.SYS_DATETIME_DATE) { // Cases like "every day at 2pm" or "every year on April 15th" var eachRegex = er.Type == Constants.SYS_DATETIME_TIME ? this.config.EachDayRegex : this.config.EachDateUnitRegex; match = eachRegex.Match(beforeStr); if (match.Success && match.Length + er.Length == text.Length) { success = true; } } if (success) { var pr = parser.Parse(er, refDate); ret = SetHandler.ResolveSet(ref ret, pr.TimexStr); break; } } return(ret); }
public GermanTimeExtractorConfiguration(DateTimeOptions options = DateTimeOptions.None) : base(options) { DurationExtractor = new BaseDurationExtractor(new GermanDurationExtractorConfiguration()); }
public ThaiTimeExtractorConfiguration(DateTimeOptions options = DateTimeOptions.None) : base(options) { DurationExtractor = new BaseDurationExtractor(new ThaiDurationExtractorConfiguration()); TimeZoneExtractor = null; }
public EnglishTimeExtractorConfiguration() { DurationExtractor = new BaseDurationExtractor(new EnglishDurationExtractorConfiguration()); }
public EnglishTimeExtractorConfiguration() : base(DateTimeOptions.None) { DurationExtractor = new BaseDurationExtractor(new EnglishDurationExtractorConfiguration()); }
public EnglishTimeExtractorConfiguration(IOptionsConfiguration config) : base(config) { DurationExtractor = new BaseDurationExtractor(new EnglishDurationExtractorConfiguration(this)); TimeZoneExtractor = new BaseTimeZoneExtractor(new EnglishTimeZoneExtractorConfiguration(this)); }
public SpanishTimeExtractorConfiguration() { DurationExtractor = new BaseDurationExtractor(new SpanishDurationExtractorConfiguration()); }
public DateTimeModel(IDateTimeParser parser, IDateTimeExtractor extractor) { this.Parser = parser; this.Extractor = extractor; }
public FrenchTimeExtractorConfiguration() { DurationExtractor = new BaseDurationExtractor(new FrenchDurationExtractorConfiguration()); }
public SpanishTimeExtractorConfiguration(DateTimeOptions options = DateTimeOptions.None) : base(options) { DurationExtractor = new BaseDurationExtractor(new SpanishDurationExtractorConfiguration()); }
public PortugueseTimeExtractorConfiguration() : base(DateTimeOptions.None) { DurationExtractor = new BaseDurationExtractor(new PortugueseDurationExtractorConfiguration()); }
public PortugueseTimeExtractorConfiguration(IOptionsConfiguration config) : base(config) { DurationExtractor = new BaseDurationExtractor(new PortugueseDurationExtractorConfiguration(this)); TimeZoneExtractor = new BaseTimeZoneExtractor(new PortugueseTimeZoneExtractorConfiguration(this)); }
public EnglishTimeExtractorConfiguration(DateTimeOptions options = DateTimeOptions.None) : base(options) { DurationExtractor = new BaseDurationExtractor(new EnglishDurationExtractorConfiguration()); TimeZoneExtractor = new BaseTimeZoneExtractor(new EnglishTimeZoneExtractorConfiguration()); }
public GermanTimeExtractorConfiguration(IOptionsConfiguration config) : base(config) { DurationExtractor = new BaseDurationExtractor(new GermanDurationExtractorConfiguration(this)); TimeZoneExtractor = new BaseTimeZoneExtractor(new GermanTimeZoneExtractorConfiguration(this)); }
public FrenchTimeExtractorConfiguration() : base(DateTimeOptions.None) { DurationExtractor = new BaseDurationExtractor(new FrenchDurationExtractorConfiguration()); }