|
5 | 5 | using System.Collections.Generic;
|
6 | 6 | using System.Globalization;
|
7 | 7 | using System.Text.RegularExpressions;
|
| 8 | +using Microsoft.Recognizers.Text.DateTime.Chinese; |
8 | 9 | using Microsoft.Recognizers.Text.Utilities;
|
9 | 10 | using DateObject = System.DateTime;
|
10 | 11 |
|
@@ -355,11 +356,21 @@ protected DateTimeResolutionResult ParseImplicitDate(string text, DateObject ref
|
355 | 356 | ret = MatchThisWeekday(text, referenceDate);
|
356 | 357 | }
|
357 | 358 |
|
| 359 | + if (!ret.Success) |
| 360 | + { |
| 361 | + ret = MatchNextNextWeekday(text, referenceDate); |
| 362 | + } |
| 363 | + |
358 | 364 | if (!ret.Success)
|
359 | 365 | {
|
360 | 366 | ret = MatchNextWeekday(text, referenceDate);
|
361 | 367 | }
|
362 | 368 |
|
| 369 | + if (!ret.Success) |
| 370 | + { |
| 371 | + ret = MatchLastLastWeekday(text, referenceDate); |
| 372 | + } |
| 373 | + |
363 | 374 | if (!ret.Success)
|
364 | 375 | {
|
365 | 376 | ret = MatchLastWeekday(text, referenceDate);
|
@@ -497,6 +508,28 @@ protected DateTimeResolutionResult MatchNextWeekday(string text, DateObject refe
|
497 | 508 | return result;
|
498 | 509 | }
|
499 | 510 |
|
| 511 | + protected DateTimeResolutionResult MatchNextNextWeekday(string text, DateObject reference) |
| 512 | + { |
| 513 | + var result = new DateTimeResolutionResult(); |
| 514 | + var cnConfig = this.config as ChineseDateParserConfiguration; |
| 515 | + if (cnConfig != null) |
| 516 | + { |
| 517 | + var match = cnConfig.NextNextRegex.MatchExact(text, trim: true); |
| 518 | + if (match.Success) |
| 519 | + { |
| 520 | + var weekdayKey = match.Groups["weekday"].Value; |
| 521 | + var value = reference.Next((DayOfWeek)this.config.DayOfWeek[weekdayKey]); |
| 522 | + value = value.Next((DayOfWeek)this.config.DayOfWeek[weekdayKey]); |
| 523 | + |
| 524 | + result.Timex = DateTimeFormatUtil.LuisDate(value); |
| 525 | + result.FutureValue = result.PastValue = DateObject.MinValue.SafeCreateFromValue(value.Year, value.Month, value.Day); |
| 526 | + result.Success = true; |
| 527 | + } |
| 528 | + } |
| 529 | + |
| 530 | + return result; |
| 531 | + } |
| 532 | + |
500 | 533 | protected DateTimeResolutionResult MatchThisWeekday(string text, DateObject reference)
|
501 | 534 | {
|
502 | 535 | var result = new DateTimeResolutionResult();
|
@@ -533,6 +566,29 @@ protected DateTimeResolutionResult MatchLastWeekday(string text, DateObject refe
|
533 | 566 | return result;
|
534 | 567 | }
|
535 | 568 |
|
| 569 | + protected DateTimeResolutionResult MatchLastLastWeekday(string text, DateObject reference) |
| 570 | + { |
| 571 | + var result = new DateTimeResolutionResult(); |
| 572 | + var cnConfig = this.config as ChineseDateParserConfiguration; |
| 573 | + if (cnConfig != null) |
| 574 | + { |
| 575 | + var match = cnConfig.LastLastRegex.MatchExact(text, trim: true); |
| 576 | + |
| 577 | + if (match.Success) |
| 578 | + { |
| 579 | + var weekdayKey = match.Groups["weekday"].Value; |
| 580 | + var value = reference.Last((DayOfWeek)this.config.DayOfWeek[weekdayKey]); |
| 581 | + value = value.Last((DayOfWeek)this.config.DayOfWeek[weekdayKey]); |
| 582 | + |
| 583 | + result.Timex = DateTimeFormatUtil.LuisDate(value); |
| 584 | + result.FutureValue = result.PastValue = DateObject.MinValue.SafeCreateFromValue(value.Year, value.Month, value.Day); |
| 585 | + result.Success = true; |
| 586 | + } |
| 587 | + } |
| 588 | + |
| 589 | + return result; |
| 590 | + } |
| 591 | + |
536 | 592 | protected DateTimeResolutionResult MatchWeekdayAlone(string text, DateObject reference)
|
537 | 593 | {
|
538 | 594 | var result = new DateTimeResolutionResult();
|
|
0 commit comments