Skip to content

Commit

Permalink
Support "as early/late as" as a modifier for datetime entities (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanxing-chen authored and tellarin committed Aug 17, 2018
1 parent 0344020 commit cbb928d
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ public static class DateTimeDefinitions
public const string AMTimeRegex = @"(?<am>morning)";
public const string PMTimeRegex = @"\b(?<pm>afternoon|evening|night)\b";
public const string InclusiveModPrepositions = @"(?<include>((on|in|at)\s+or\s+)|(\s+or\s+(on|in|at)))";
public static readonly string BeforeRegex = $@"(\b{InclusiveModPrepositions}?(before|in advance of|prior to|(no later|earlier|sooner) than|ending (with|on)|by|till|til|until){InclusiveModPrepositions}?\b\s*)|(?<!\w|>)((?<include><=)|<)";
public static readonly string BeforeRegex = $@"(\b{InclusiveModPrepositions}?(before|in\s+advance\s+of|prior\s+to|(no\s+later|earlier|sooner)\s+than|ending\s+(with|on)|by|till|til|until|(?<include>as\s+late\s+as)){InclusiveModPrepositions}?\b\s*)|(?<!\w|>)((?<include><=)|<)";
public static readonly string AfterRegex = $@"(\b{InclusiveModPrepositions}?(after(?!\s+or equal to)|(?<!no\s+)later than){InclusiveModPrepositions}?\b\s*)|(?<!\w|<)((?<include>>=)|>)";
public const string SinceRegex = @"(\b(since|after or equal to|starting (from|on|with))\b\s*)|(?<!\w|<)(>=)";
public const string SinceRegex = @"(\b(since|after\s+or\s+equal\s+to|starting\s+(from|on|with)|as\s+early\s+as)\b\s*)|(?<!\w|<)(>=)";
public const string AroundRegex = @"(\b(around|circa)\s*\b)";
public const string AgoRegex = @"\b(ago|before (?<day>yesterday|today))\b";
public const string LaterRegex = @"\b(later|from now|(from|after) (?<day>tomorrow|tmr|today))\b";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ private DateTimeResolutionResult ParseDuration(string text, DateObject reference
switch (durationUnit)
{
case "W":
var diff = 7 - (((int)beginDate.DayOfWeek) == 0 ? 7 : (int)beginDate.DayOfWeek);
var diff = 7 - ((int)beginDate.DayOfWeek == 0 ? 7 : (int)beginDate.DayOfWeek);
endDate = beginDate.AddDays(diff);
timex = "P" + diff + "D";
if (diff == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ export namespace EnglishDateTime {
export const AMTimeRegex = `(?<am>morning)`;
export const PMTimeRegex = `\\b(?<pm>afternoon|evening|night)\\b`;
export const InclusiveModPrepositions = `(?<include>((on|in|at)\\s+or\\s+)|(\\s+or\\s+(on|in|at)))`;
export const BeforeRegex = `(\\b${InclusiveModPrepositions}?(before|in advance of|prior to|(no later|earlier|sooner) than|ending (with|on)|by|till|til|until)${InclusiveModPrepositions}?\\b\\s*)|(?<!\\w|>)((?<include><=)|<)`;
export const BeforeRegex = `(\\b${InclusiveModPrepositions}?(before|in\\s+advance\\s+of|prior\\s+to|(no\\s+later|earlier|sooner)\\s+than|ending\\s+(with|on)|by|till|til|until|(?<include>as\\s+late\\s+as))${InclusiveModPrepositions}?\\b\\s*)|(?<!\\w|>)((?<include><=)|<)`;
export const AfterRegex = `(\\b${InclusiveModPrepositions}?(after(?!\\s+or equal to)|(?<!no\\s+)later than)${InclusiveModPrepositions}?\\b\\s*)|(?<!\\w|<)((?<include>>=)|>)`;
export const SinceRegex = `(\\b(since|after or equal to|starting (from|on|with))\\b\\s*)|(?<!\\w|<)(>=)`;
export const SinceRegex = `(\\b(since|after\\s+or\\s+equal\\s+to|starting\\s+(from|on|with)|as\\s+early\\s+as)\\b\\s*)|(?<!\\w|<)(>=)`;
export const AroundRegex = `(\\b(around|circa)\\s*\\b)`;
export const AgoRegex = `\\b(ago|before (?<day>yesterday|today))\\b`;
export const LaterRegex = `\\b(later|from now|(from|after) (?<day>tomorrow|tmr|today))\\b`;
Expand Down
4 changes: 2 additions & 2 deletions Patterns/English/English-DateTime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,13 @@ PMTimeRegex: !simpleRegex
InclusiveModPrepositions: !simpleRegex
def: (?<include>((on|in|at)\s+or\s+)|(\s+or\s+(on|in|at)))
BeforeRegex: !nestedRegex
def: (\b{InclusiveModPrepositions}?(before|in advance of|prior to|(no later|earlier|sooner) than|ending (with|on)|by|till|til|until){InclusiveModPrepositions}?\b\s*)|(?<!\w|>)((?<include><=)|<)
def: (\b{InclusiveModPrepositions}?(before|in\s+advance\s+of|prior\s+to|(no\s+later|earlier|sooner)\s+than|ending\s+(with|on)|by|till|til|until|(?<include>as\s+late\s+as)){InclusiveModPrepositions}?\b\s*)|(?<!\w|>)((?<include><=)|<)
references: [ InclusiveModPrepositions ]
AfterRegex: !nestedRegex
def: (\b{InclusiveModPrepositions}?(after(?!\s+or equal to)|(?<!no\s+)later than){InclusiveModPrepositions}?\b\s*)|(?<!\w|<)((?<include>>=)|>)
references: [ InclusiveModPrepositions ]
SinceRegex: !simpleRegex
def: (\b(since|after or equal to|starting (from|on|with))\b\s*)|(?<!\w|<)(>=)
def: (\b(since|after\s+or\s+equal\s+to|starting\s+(from|on|with)|as\s+early\s+as)\b\s*)|(?<!\w|<)(>=)
AroundRegex: !simpleRegex
def: (\b(around|circa)\s*\b)
AgoRegex: !simpleRegex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ class EnglishDateTime:
AMTimeRegex = f'(?<am>morning)'
PMTimeRegex = f'\\b(?<pm>afternoon|evening|night)\\b'
InclusiveModPrepositions = f'(?<include>((on|in|at)\\s+or\\s+)|(\\s+or\\s+(on|in|at)))'
BeforeRegex = f'(\\b{InclusiveModPrepositions}?(before|in advance of|prior to|(no later|earlier|sooner) than|ending (with|on)|by|till|til|until){InclusiveModPrepositions}?\\b\\s*)|(?<!\\w|>)((?<include><=)|<)'
BeforeRegex = f'(\\b{InclusiveModPrepositions}?(before|in\\s+advance\\s+of|prior\\s+to|(no\\s+later|earlier|sooner)\\s+than|ending\\s+(with|on)|by|till|til|until|(?<include>as\\s+late\\s+as)){InclusiveModPrepositions}?\\b\\s*)|(?<!\\w|>)((?<include><=)|<)'
AfterRegex = f'(\\b{InclusiveModPrepositions}?(after(?!\\s+or equal to)|(?<!no\\s+)later than){InclusiveModPrepositions}?\\b\\s*)|(?<!\\w|<)((?<include>>=)|>)'
SinceRegex = f'(\\b(since|after or equal to|starting (from|on|with))\\b\\s*)|(?<!\\w|<)(>=)'
SinceRegex = f'(\\b(since|after\\s+or\\s+equal\\s+to|starting\\s+(from|on|with)|as\\s+early\\s+as)\\b\\s*)|(?<!\\w|<)(>=)'
AroundRegex = f'(\\b(around|circa)\\s*\\b)'
AgoRegex = f'\\b(ago|before (?<day>yesterday|today))\\b'
LaterRegex = f'\\b(later|from now|(from|after) (?<day>tomorrow|tmr|today))\\b'
Expand Down
90 changes: 90 additions & 0 deletions Specs/DateTime/English/DateTimeModel.json
Original file line number Diff line number Diff line change
Expand Up @@ -6078,5 +6078,95 @@
}
}
]
},
{
"Input": "Let's meet this week as early as 7:00 am",
"Context": {
"ReferenceDateTime": "2018-08-17T15:00:00"
},
"Results": [
{
"Text": "this week",
"Start": 11,
"End": 19,
"TypeName": "datetimeV2.daterange",
"Resolution": {
"values": [
{
"timex": "2018-W33",
"type": "daterange",
"start": "2018-08-13",
"end": "2018-08-20"
}
]
}
},
{
"Text": "as early as 7:00 am",
"Start": 21,
"End": 39,
"TypeName": "datetimeV2.timerange",
"Resolution": {
"values": [
{
"timex": "T07:00",
"Mod": "since",
"type": "timerange",
"start": "07:00:00"
}
]
}
}
]
},
{
"Input": "I'll leave as late as 7:00 am",
"Context": {
"ReferenceDateTime": "2018-08-17T15:00:00"
},
"NotSupported": "javascript, python",
"Results": [
{
"Text": "as late as 7:00 am",
"Start": 11,
"End": 28,
"TypeName": "datetimeV2.timerange",
"Resolution": {
"values": [
{
"timex": "T07:00",
"Mod": "until",
"type": "timerange",
"end": "07:00:00"
}
]
}
}
]
},
{
"Input": "I'll leave as late as tomorrow.",
"Context": {
"ReferenceDateTime": "2018-08-17T15:00:00"
},
"NotSupported": "javascript, python",
"Results": [
{
"Text": "as late as tomorrow",
"Start": 11,
"End": 29,
"TypeName": "datetimeV2.daterange",
"Resolution": {
"values": [
{
"timex": "2018-08-18",
"Mod": "until",
"type": "daterange",
"end": "2018-08-18"
}
]
}
}
]
}
]
90 changes: 90 additions & 0 deletions Specs/DateTime/English/DateTimeModelComplexCalendar.json
Original file line number Diff line number Diff line change
Expand Up @@ -5091,5 +5091,95 @@
}
}
]
},
{
"Input": "Let's meet this week as early as 7:00 am",
"Context": {
"ReferenceDateTime": "2018-08-17T15:00:00"
},
"Results": [
{
"Text": "this week",
"Start": 11,
"End": 19,
"TypeName": "datetimeV2.daterange",
"Resolution": {
"values": [
{
"timex": "2018-W33",
"type": "daterange",
"start": "2018-08-13",
"end": "2018-08-20"
}
]
}
},
{
"Text": "as early as 7:00 am",
"Start": 21,
"End": 39,
"TypeName": "datetimeV2.timerange",
"Resolution": {
"values": [
{
"timex": "T07:00",
"Mod": "since",
"type": "timerange",
"start": "07:00:00"
}
]
}
}
]
},
{
"Input": "I'll leave as late as 7:00 am",
"Context": {
"ReferenceDateTime": "2018-08-17T15:00:00"
},
"NotSupported": "javascript, python",
"Results": [
{
"Text": "as late as 7:00 am",
"Start": 11,
"End": 28,
"TypeName": "datetimeV2.timerange",
"Resolution": {
"values": [
{
"timex": "T07:00",
"Mod": "until",
"type": "timerange",
"end": "07:00:00"
}
]
}
}
]
},
{
"Input": "I'll leave as late as tomorrow.",
"Context": {
"ReferenceDateTime": "2018-08-17T15:00:00"
},
"NotSupported": "javascript, python",
"Results": [
{
"Text": "as late as tomorrow",
"Start": 11,
"End": 29,
"TypeName": "datetimeV2.daterange",
"Resolution": {
"values": [
{
"timex": "2018-08-18",
"Mod": "until",
"type": "daterange",
"end": "2018-08-18"
}
]
}
}
]
}
]

0 comments on commit cbb928d

Please sign in to comment.