Skip to content

Commit

Permalink
Can't recognize modifier "starting|beginning" date (#1539)
Browse files Browse the repository at this point in the history
* Fix .Net and add Specs

* Fix in other platforms
  • Loading branch information
yuyingzz authored and tellarin committed Apr 25, 2019
1 parent 128b181 commit aa3002e
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public static class DateTimeDefinitions
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\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><=)|<))(\s+the)?";
public static readonly string AfterRegex = $@"(\b{InclusiveModPrepositions}?((after|(?<!no\s+)later than)|(year greater than))(?!\s+or equal to){InclusiveModPrepositions}?\b\s*)|(?<!\w|<)((?<include>>=)|>)";
public static readonly string AfterRegex = $@"(\b{InclusiveModPrepositions}?((after|(starting|beginning)(\s+on)?(?!\sfrom)|(?<!no\s+)later than)|(year greater than))(?!\s+or equal to){InclusiveModPrepositions}?\b\s*)|(?<!\w|<)((?<include>>=)|>)";
public const string SinceRegex = @"((\b(since|after\s+or\s+equal\s+to|starting\s+(from|on|with)|as\s+early\s+as|any\s+time\s+from)\b\s*)|(?<!\w|<)(>=))";
public const string AroundRegex = @"(\b(around|circa)\s*\b)";
public const string AgoRegex = @"\b(ago|before\s+(?<day>yesterday|today))\b";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ public class EnglishDateTime {
public static final 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><=)|<))(\\s+the)?"
.replace("{InclusiveModPrepositions}", InclusiveModPrepositions);

public static final String AfterRegex = "(\\b{InclusiveModPrepositions}?((after|(?<!no\\s+)later than)|(year greater than))(?!\\s+or equal to){InclusiveModPrepositions}?\\b\\s*)|(?<!\\w|<)((?<include>>=)|>)"
public static final String AfterRegex = "(\\b{InclusiveModPrepositions}?((after|(starting|beginning)(\\s+on)?(?!\\sfrom)|(?<!no\\s+)later than)|(year greater than))(?!\\s+or equal to){InclusiveModPrepositions}?\\b\\s*)|(?<!\\w|<)((?<include>>=)|>)"
.replace("{InclusiveModPrepositions}", InclusiveModPrepositions);

public static final String SinceRegex = "((\\b(since|after\\s+or\\s+equal\\s+to|starting\\s+(from|on|with)|as\\s+early\\s+as|any\\s+time\\s+from)\\b\\s*)|(?<!\\w|<)(>=))";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,26 +168,33 @@ export class BaseMergedExtractor implements IDateTimeExtractor {
let lastEnd = 0;
ers.forEach(er => {
let beforeStr = source.substr(lastEnd, er.start).toLowerCase();
let isSuccess = false;
let before = this.hasTokenIndex(beforeStr.trim(), this.config.beforeRegex);
if (before.matched) {
let modLength = beforeStr.length - before.index;
er.length += modLength;
er.start -= modLength;
er.text = source.substr(er.start, er.length);
isSuccess = true;
}
let after = this.hasTokenIndex(beforeStr.trim(), this.config.afterRegex);
if (after.matched) {
let modLength = beforeStr.length - after.index;
er.length += modLength;
er.start -= modLength;
er.text = source.substr(er.start, er.length);
if(!isSuccess){
let after = this.hasTokenIndex(beforeStr.trim(), this.config.afterRegex);
if (after.matched) {
let modLength = beforeStr.length - after.index;
er.length += modLength;
er.start -= modLength;
er.text = source.substr(er.start, er.length);
isSuccess = true;
}
}
let since = this.hasTokenIndex(beforeStr.trim(), this.config.sinceRegex);
if (since.matched) {
let modLength = beforeStr.length - since.index;
er.length += modLength;
er.start -= modLength;
er.text = source.substr(er.start, er.length);
if(!isSuccess){
let since = this.hasTokenIndex(beforeStr.trim(), this.config.sinceRegex);
if (since.matched) {
let modLength = beforeStr.length - since.index;
er.length += modLength;
er.start -= modLength;
er.text = source.substr(er.start, er.length);
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export namespace EnglishDateTime {
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\\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><=)|<))(\\s+the)?`;
export const AfterRegex = `(\\b${InclusiveModPrepositions}?((after|(?<!no\\s+)later than)|(year greater than))(?!\\s+or equal to)${InclusiveModPrepositions}?\\b\\s*)|(?<!\\w|<)((?<include>>=)|>)`;
export const AfterRegex = `(\\b${InclusiveModPrepositions}?((after|(starting|beginning)(\\s+on)?(?!\\sfrom)|(?<!no\\s+)later than)|(year greater than))(?!\\s+or equal to)${InclusiveModPrepositions}?\\b\\s*)|(?<!\\w|<)((?<include>>=)|>)`;
export const SinceRegex = `((\\b(since|after\\s+or\\s+equal\\s+to|starting\\s+(from|on|with)|as\\s+early\\s+as|any\\s+time\\s+from)\\b\\s*)|(?<!\\w|<)(>=))`;
export const AroundRegex = `(\\b(around|circa)\\s*\\b)`;
export const AgoRegex = `\\b(ago|before\\s+(?<day>yesterday|today))\\b`;
Expand Down
3 changes: 2 additions & 1 deletion Patterns/English/English-DateTime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,9 @@ InclusiveModPrepositions: !simpleRegex
BeforeRegex: !nestedRegex
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><=)|<))(\s+the)?
references: [ InclusiveModPrepositions ]
# "starting from" is SinceRegex
AfterRegex: !nestedRegex
def: (\b{InclusiveModPrepositions}?((after|(?<!no\s+)later than)|(year greater than))(?!\s+or equal to){InclusiveModPrepositions}?\b\s*)|(?<!\w|<)((?<include>>=)|>)
def: (\b{InclusiveModPrepositions}?((after|(starting|beginning)(\s+on)?(?!\sfrom)|(?<!no\s+)later than)|(year greater than))(?!\s+or equal to){InclusiveModPrepositions}?\b\s*)|(?<!\w|<)((?<include>>=)|>)
references: [ InclusiveModPrepositions ]
SinceRegex: !simpleRegex
def: ((\b(since|after\s+or\s+equal\s+to|starting\s+(from|on|with)|as\s+early\s+as|any\s+time\s+from)\b\s*)|(?<!\w|<)(>=))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,27 +207,32 @@ def add_mod(self, ers: List[ExtractResult], source: str) -> List[ExtractResult]:

def add_mod_item(self, er: ExtractResult, source: str) -> ExtractResult:
before_str = source[0:er.start]
is_success = False

before = self.has_token_index(before_str.strip(), self.config.before_regex)
if before.matched:
mod_len = len(before_str) - before.index
er.length += mod_len
er.start -= mod_len
er.text = source[er.start:er.start + er.length]

after = self.has_token_index(before_str.strip(), self.config.after_regex)
if after.matched:
mod_len = len(before_str) - after.index
er.length += mod_len
er.start -= mod_len
er.text = source[er.start:er.start + er.length]

since = self.has_token_index(before_str.strip(), self.config.since_regex)
if since.matched:
mod_len = len(before_str) - since.index
er.length += mod_len
er.start -= mod_len
er.text = source[er.start:er.start + er.length]
is_success = True

if not is_success:
after = self.has_token_index(before_str.strip(), self.config.after_regex)
if after.matched:
mod_len = len(before_str) - after.index
er.length += mod_len
er.start -= mod_len
er.text = source[er.start:er.start + er.length]
is_success = True

if not is_success:
since = self.has_token_index(before_str.strip(), self.config.since_regex)
if not is_success and since.matched:
mod_len = len(before_str) - since.index
er.length += mod_len
er.start -= mod_len
er.text = source[er.start:er.start + er.length]

return er

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class EnglishDateTime:
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\\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><=)|<))(\\s+the)?'
AfterRegex = f'(\\b{InclusiveModPrepositions}?((after|(?<!no\\s+)later than)|(year greater than))(?!\\s+or equal to){InclusiveModPrepositions}?\\b\\s*)|(?<!\\w|<)((?<include>>=)|>)'
AfterRegex = f'(\\b{InclusiveModPrepositions}?((after|(starting|beginning)(\\s+on)?(?!\\sfrom)|(?<!no\\s+)later than)|(year greater than))(?!\\s+or equal to){InclusiveModPrepositions}?\\b\\s*)|(?<!\\w|<)((?<include>>=)|>)'
SinceRegex = f'((\\b(since|after\\s+or\\s+equal\\s+to|starting\\s+(from|on|with)|as\\s+early\\s+as|any\\s+time\\s+from)\\b\\s*)|(?<!\\w|<)(>=))'
AroundRegex = f'(\\b(around|circa)\\s*\\b)'
AgoRegex = f'\\b(ago|before\\s+(?<day>yesterday|today))\\b'
Expand Down
120 changes: 120 additions & 0 deletions Specs/DateTime/English/DateTimeModel.json
Original file line number Diff line number Diff line change
Expand Up @@ -10699,6 +10699,66 @@
}
]
},
{
"Input": "Please can you arrange a Microsoft Teams Meeting starting January 7th to discuss ARM Templates?",
"Context": {
"ReferenceDateTime": "2019-04-24T00:00:00"
},
"Results": [
{
"Text": "starting january 7th",
"Start": 49,
"End": 68,
"TypeName": "datetimeV2.daterange",
"Resolution": {
"values": [
{
"timex": "XXXX-01-07",
"Mod": "after",
"type": "daterange",
"start": "2019-01-07"
},
{
"timex": "XXXX-01-07",
"Mod": "after",
"type": "daterange",
"start": "2020-01-07"
}
]
}
}
]
},
{
"Input": "Please can you arrange a Microsoft Teams Meeting starting on January 7th to discuss ARM Templates?",
"Context": {
"ReferenceDateTime": "2019-04-24T00:00:00"
},
"Results": [
{
"Text": "starting on january 7th",
"Start": 49,
"End": 71,
"TypeName": "datetimeV2.daterange",
"Resolution": {
"values": [
{
"timex": "XXXX-01-07",
"Mod": "after",
"type": "daterange",
"start": "2019-01-07"
},
{
"timex": "XXXX-01-07",
"Mod": "after",
"type": "daterange",
"start": "2020-01-07"
}
]
}
}
]
},
{
"Input": "Let's meet on february twenty second at 3:30",
"Context": {
Expand Down Expand Up @@ -10777,6 +10837,66 @@
}
]
},
{
"Input": "Please can you arrange a Microsoft Teams Meeting beginning January 7th to discuss ARM Templates?",
"Context": {
"ReferenceDateTime": "2019-04-24T00:00:00"
},
"Results": [
{
"Text": "beginning january 7th",
"Start": 49,
"End": 69,
"TypeName": "datetimeV2.daterange",
"Resolution": {
"values": [
{
"timex": "XXXX-01-07",
"Mod": "after",
"type": "daterange",
"start": "2019-01-07"
},
{
"timex": "XXXX-01-07",
"Mod": "after",
"type": "daterange",
"start": "2020-01-07"
}
]
}
}
]
},
{
"Input": "Please can you arrange a Microsoft Teams Meeting beginning on January 7th to discuss ARM Templates?",
"Context": {
"ReferenceDateTime": "2019-04-24T00:00:00"
},
"Results": [
{
"Text": "beginning on january 7th",
"Start": 49,
"End": 72,
"TypeName": "datetimeV2.daterange",
"Resolution": {
"values": [
{
"timex": "XXXX-01-07",
"Mod": "after",
"type": "daterange",
"start": "2019-01-07"
},
{
"timex": "XXXX-01-07",
"Mod": "after",
"type": "daterange",
"start": "2020-01-07"
}
]
}
}
]
},
{
"Input": "Let's meet on friday march fifteenth nine a m.",
"Context": {
Expand Down

0 comments on commit aa3002e

Please sign in to comment.