Skip to content

Commit 902deb3

Browse files
yuyingzztellarin
authored andcommitted
Fix regression in time span extraction (microsoft#1484)
* Fix the .Net and add test specs * Support other platforms
1 parent 8a1b31a commit 902deb3

File tree

7 files changed

+95
-5
lines changed

7 files changed

+95
-5
lines changed

.NET/Microsoft.Recognizers.Definitions.Common/English/DateTimeDefinitions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public static class DateTimeDefinitions
238238
public const string FlexibleDayRegex = @"(?<DayOfMonth>([A-Za-z]+\s)?[A-Za-z\d]+)";
239239
public static readonly string ForTheRegex = $@"\b((((?<=for\s+)the\s+{FlexibleDayRegex})|((?<=on\s+)(the\s+)?{FlexibleDayRegex}(?<=(st|nd|rd|th))))(?<end>\s*(,|\.|!|\?|$)))";
240240
public static readonly string WeekDayAndDayOfMonthRegex = $@"\b{WeekDayRegex}\s+(the\s+{FlexibleDayRegex})\b";
241-
public static readonly string WeekDayAndDayRegex = $@"\b{WeekDayRegex}\s+(?!(the)){DayRegex}(?!([-]|(\s+({AmDescRegex}|{PmDescRegex}))))\b";
241+
public static readonly string WeekDayAndDayRegex = $@"\b{WeekDayRegex}\s+(?!(the)){DayRegex}(?!([-:]|(\s+({AmDescRegex}|{PmDescRegex}))))\b";
242242
public const string RestOfDateRegex = @"\brest\s+(of\s+)?((the|my|this|current)\s+)?(?<duration>week|month|year|decade)\b";
243243
public const string RestOfDateTimeRegex = @"\brest\s+(of\s+)?((the|my|this|current)\s+)?(?<unit>day)\b";
244244
public const string MealTimeRegex = @"\b(at\s+)?(?<mealTime>lunchtime)\b";

Java/libraries/recognizers-text-date-time/src/main/java/com/microsoft/recognizers/text/datetime/resources/EnglishDateTime.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ public class EnglishDateTime {
767767
.replace("{WeekDayRegex}", WeekDayRegex)
768768
.replace("{FlexibleDayRegex}", FlexibleDayRegex);
769769

770-
public static final String WeekDayAndDayRegex = "\\b{WeekDayRegex}\\s+(?!(the)){DayRegex}(?!([-]|(\\s+({AmDescRegex}|{PmDescRegex}))))\\b"
770+
public static final String WeekDayAndDayRegex = "\\b{WeekDayRegex}\\s+(?!(the)){DayRegex}(?!([-:]|(\\s+({AmDescRegex}|{PmDescRegex}))))\\b"
771771
.replace("{WeekDayRegex}", WeekDayRegex)
772772
.replace("{DayRegex}", DayRegex)
773773
.replace("{AmDescRegex}", AmDescRegex)

JavaScript/packages/recognizers-date-time/src/resources/englishDateTime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export namespace EnglishDateTime {
229229
export const FlexibleDayRegex = `(?<DayOfMonth>([A-Za-z]+\\s)?[A-Za-z\\d]+)`;
230230
export const ForTheRegex = `\\b((((?<=for\\s+)the\\s+${FlexibleDayRegex})|((?<=on\\s+)(the\\s+)?${FlexibleDayRegex}(?<=(st|nd|rd|th))))(?<end>\\s*(,|\\.|!|\\?|$)))`;
231231
export const WeekDayAndDayOfMonthRegex = `\\b${WeekDayRegex}\\s+(the\\s+${FlexibleDayRegex})\\b`;
232-
export const WeekDayAndDayRegex = `\\b${WeekDayRegex}\\s+(?!(the))${DayRegex}(?!([-]|(\\s+(${AmDescRegex}|${PmDescRegex}))))\\b`;
232+
export const WeekDayAndDayRegex = `\\b${WeekDayRegex}\\s+(?!(the))${DayRegex}(?!([-:]|(\\s+(${AmDescRegex}|${PmDescRegex}))))\\b`;
233233
export const RestOfDateRegex = `\\brest\\s+(of\\s+)?((the|my|this|current)\\s+)?(?<duration>week|month|year|decade)\\b`;
234234
export const RestOfDateTimeRegex = `\\brest\\s+(of\\s+)?((the|my|this|current)\\s+)?(?<unit>day)\\b`;
235235
export const MealTimeRegex = `\\b(at\\s+)?(?<mealTime>lunchtime)\\b`;

Patterns/English/English-DateTime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ WeekDayAndDayOfMonthRegex: !nestedRegex
572572
def: \b{WeekDayRegex}\s+(the\s+{FlexibleDayRegex})\b
573573
references: [WeekDayRegex, FlexibleDayRegex]
574574
WeekDayAndDayRegex: !nestedRegex
575-
def: \b{WeekDayRegex}\s+(?!(the)){DayRegex}(?!([-]|(\s+({AmDescRegex}|{PmDescRegex}))))\b
575+
def: \b{WeekDayRegex}\s+(?!(the)){DayRegex}(?!([-:]|(\s+({AmDescRegex}|{PmDescRegex}))))\b
576576
references: [WeekDayRegex, DayRegex, AmDescRegex, PmDescRegex]
577577
RestOfDateRegex: !simpleRegex
578578
def: \brest\s+(of\s+)?((the|my|this|current)\s+)?(?<duration>week|month|year|decade)\b

Python/libraries/recognizers-date-time/recognizers_date_time/resources/english_date_time.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class EnglishDateTime:
230230
FlexibleDayRegex = f'(?<DayOfMonth>([A-Za-z]+\\s)?[A-Za-z\\d]+)'
231231
ForTheRegex = f'\\b((((?<=for\\s+)the\\s+{FlexibleDayRegex})|((?<=on\\s+)(the\\s+)?{FlexibleDayRegex}(?<=(st|nd|rd|th))))(?<end>\\s*(,|\\.|!|\\?|$)))'
232232
WeekDayAndDayOfMonthRegex = f'\\b{WeekDayRegex}\\s+(the\\s+{FlexibleDayRegex})\\b'
233-
WeekDayAndDayRegex = f'\\b{WeekDayRegex}\\s+(?!(the)){DayRegex}(?!([-]|(\\s+({AmDescRegex}|{PmDescRegex}))))\\b'
233+
WeekDayAndDayRegex = f'\\b{WeekDayRegex}\\s+(?!(the)){DayRegex}(?!([-:]|(\\s+({AmDescRegex}|{PmDescRegex}))))\\b'
234234
RestOfDateRegex = f'\\brest\\s+(of\\s+)?((the|my|this|current)\\s+)?(?<duration>week|month|year|decade)\\b'
235235
RestOfDateTimeRegex = f'\\brest\\s+(of\\s+)?((the|my|this|current)\\s+)?(?<unit>day)\\b'
236236
MealTimeRegex = f'\\b(at\\s+)?(?<mealTime>lunchtime)\\b'

Specs/DateTime/English/DateTimeModel.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10159,6 +10159,51 @@
1015910159
}
1016010160
]
1016110161
},
10162+
{
10163+
"Input": "book my time for swimming every Tuesday and Thursday 19:00 - 21:00.",
10164+
"Context": {
10165+
"ReferenceDateTime": "2019-03-01T00:00:00"
10166+
},
10167+
"Results": [
10168+
{
10169+
"Text": "every tuesday",
10170+
"Start": 26,
10171+
"End": 38,
10172+
"TypeName": "datetimeV2.set",
10173+
"Resolution": {
10174+
"values": [
10175+
{
10176+
"timex": "XXXX-WXX-2",
10177+
"type": "set",
10178+
"value": "not resolved"
10179+
}
10180+
]
10181+
}
10182+
},
10183+
{
10184+
"Text": "thursday 19:00 - 21:00",
10185+
"Start": 44,
10186+
"End": 65,
10187+
"TypeName": "datetimeV2.datetimerange",
10188+
"Resolution": {
10189+
"values": [
10190+
{
10191+
"timex": "(XXXX-WXX-4T19:00,XXXX-WXX-4T21:00,PT2H)",
10192+
"type": "datetimerange",
10193+
"start": "2019-02-28 19:00:00",
10194+
"end": "2019-02-28 21:00:00"
10195+
},
10196+
{
10197+
"timex": "(XXXX-WXX-4T19:00,XXXX-WXX-4T21:00,PT2H)",
10198+
"type": "datetimerange",
10199+
"start": "2019-03-07 19:00:00",
10200+
"end": "2019-03-07 21:00:00"
10201+
}
10202+
]
10203+
}
10204+
}
10205+
]
10206+
},
1016210207
{
1016310208
"Input": "Is this a valid date? 12-2015",
1016410209
"Context": {

Specs/DateTime/English/DateTimeModelComplexCalendar.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8896,6 +8896,51 @@
88968896
}
88978897
]
88988898
},
8899+
{
8900+
"Input": "book my time for swimming every Tuesday and Thursday 19:00 - 21:00.",
8901+
"Context": {
8902+
"ReferenceDateTime": "2019-03-01T00:00:00"
8903+
},
8904+
"Results": [
8905+
{
8906+
"Text": "every tuesday",
8907+
"Start": 26,
8908+
"End": 38,
8909+
"TypeName": "datetimeV2.set",
8910+
"Resolution": {
8911+
"values": [
8912+
{
8913+
"timex": "XXXX-WXX-2",
8914+
"type": "set",
8915+
"value": "not resolved"
8916+
}
8917+
]
8918+
}
8919+
},
8920+
{
8921+
"Text": "thursday 19:00 - 21:00",
8922+
"Start": 44,
8923+
"End": 65,
8924+
"TypeName": "datetimeV2.datetimerange",
8925+
"Resolution": {
8926+
"values": [
8927+
{
8928+
"timex": "(XXXX-WXX-4T19:00,XXXX-WXX-4T21:00,PT2H)",
8929+
"type": "datetimerange",
8930+
"start": "2019-02-28 19:00:00",
8931+
"end": "2019-02-28 21:00:00"
8932+
},
8933+
{
8934+
"timex": "(XXXX-WXX-4T19:00,XXXX-WXX-4T21:00,PT2H)",
8935+
"type": "datetimerange",
8936+
"start": "2019-03-07 19:00:00",
8937+
"end": "2019-03-07 21:00:00"
8938+
}
8939+
]
8940+
}
8941+
}
8942+
]
8943+
},
88998944
{
89008945
"Input": "Is this a valid date? 12-2015",
89018946
"Context": {

0 commit comments

Comments
 (0)