Skip to content

Commit

Permalink
Filter single ambiguous word which extracted as duration under Calend…
Browse files Browse the repository at this point in the history
…ar Mode (#570)

* Filter single ambiguous word extracted as duration under Calendar Mode
  • Loading branch information
sanxing-chen authored and tellarin committed May 25, 2018
1 parent 6294a9e commit 3e51d89
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public static class DateTimeDefinitions
public const string ConnectorRegex = @"^(-|,|for|t|around)$";
public const string FromToRegex = @"\b(from).+(to)\b.+";
public const string SingleAmbiguousMonthRegex = @"^(the\s+)?(may|march)$";
public const string SingleAmbiguousTermsRegex = @"^(the\s+)?(day|week|month|year)$";
public const string PrepositionSuffixRegex = @"\b(on|in|at|around|from|to)$";
public const string FlexibleDayRegex = @"(?<DayOfMonth>([A-Za-z]+\s)?[A-Za-z\d]+)";
public static readonly string ForTheRegex = $@"\b(((for the {FlexibleDayRegex})|(on (the\s+)?{FlexibleDayRegex}(?<=(st|nd|rd|th))))(?<end>\s*(,|\.|!|\?|$)))";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class EnglishMergedExtractorConfiguration : IMergedExtractorConfiguration
{
// one on one
new Regex(DateTimeDefinitions.OneOnOneRegex, RegexOptions.IgnoreCase | RegexOptions.Singleline),
// (the)? (day|week|month|year)
new Regex(DateTimeDefinitions.SingleAmbiguousTermsRegex, RegexOptions.IgnoreCase | RegexOptions.Singleline),
};

public DateTimeOptions Options { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export namespace EnglishDateTime {
export const ConnectorRegex = `^(-|,|for|t|around)$`;
export const FromToRegex = `\\b(from).+(to)\\b.+`;
export const SingleAmbiguousMonthRegex = `^(the\\s+)?(may|march)$`;
export const SingleAmbiguousTermsRegex = `^(the\\s+)?(day|week|month|year)$`;
export const PrepositionSuffixRegex = `\\b(on|in|at|around|from|to)$`;
export const FlexibleDayRegex = `(?<DayOfMonth>([A-Za-z]+\\s)?[A-Za-z\\d]+)`;
export const ForTheRegex = `\\b(((for the ${FlexibleDayRegex})|(on (the\\s+)?${FlexibleDayRegex}(?<=(st|nd|rd|th))))(?<end>\\s*(,|\\.|!|\\?|$)))`;
Expand Down
5 changes: 4 additions & 1 deletion Patterns/English/English-DateTime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ NextDateRegex: !nestedRegex
references: [ NextPrefixRegex, WeekDayRegex ]
SpecialDayRegex: !nestedRegex
def: \b((the\s+)?day before yesterday|(the\s+)?day after (tomorrow|tmr)|((the\s+)?({RelativeRegex}|my)\s+day)|yesterday|tomorrow|tmr|today)\b
references: [ RelativeRegex]
references: [ RelativeRegex ]
SpecialDayWithNumRegex: !nestedRegex
def: \b((?<number>{WrittenNumRegex})\s+days?\s+from\s+(?<day>yesterday|tomorrow|tmr|today))\b
references: [ WrittenNumRegex ]
Expand Down Expand Up @@ -476,6 +476,9 @@ FromToRegex: !simpleRegex
def: \b(from).+(to)\b.+
SingleAmbiguousMonthRegex: !simpleRegex
def: ^(the\s+)?(may|march)$
# Filter ambiguous single word datetime extractions in CalendarMode
SingleAmbiguousTermsRegex: !simpleRegex
def: ^(the\s+)?(day|week|month|year)$
PrepositionSuffixRegex: !simpleRegex
def: \b(on|in|at|around|from|to)$
FlexibleDayRegex: !simpleRegex
Expand Down
155 changes: 153 additions & 2 deletions Specs/DateTime/English/DateTimeModel.json
Original file line number Diff line number Diff line change
Expand Up @@ -2973,8 +2973,7 @@
}
}
]
}
,
},
{
"Input": "I'll leave for Beijing early in the day Wednesday.",
"Context": {
Expand Down Expand Up @@ -3047,4 +3046,156 @@
}
]
}
,
{
"Input": "Hey, we got Cloud partner of the year.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "python",
"Results": [{
"Text": "the year",
"Start": 29,
"End": 36,
"TypeName": "datetimeV2.daterange",
"Resolution": {
"values": [
{
"timex": "2018",
"type": "daterange",
"start": "2018-01-01",
"end": "2019-01-01"
}
]
}
}]
}
,
{
"Input": "Hey, we got a partner of the month.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "python",
"Results": [{
"Text": "the month",
"Start": 25,
"End": 33,
"TypeName": "datetimeV2.daterange",
"Resolution": {
"values": [
{
"timex": "2018-05",
"type": "daterange",
"start": "2018-05-01",
"end": "2018-06-01"
}
]
}
}]
}
,
{
"Input": "Hey, we got a partner of the week.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "python",
"Results": [{
"Text": "the week",
"Start": 25,
"End": 32,
"TypeName": "datetimeV2.daterange",
"Resolution": {
"values": [
{
"timex": "2018-W21",
"type": "daterange",
"start": "2018-05-21",
"end": "2018-05-28"
}
]
}
}]
}
,
{
"Input": "Hey, we got a partner of the day.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "python",
"Results": [{
"Text": "the day",
"Start": 25,
"End": 31,
"TypeName": "datetimeV2.date",
"Resolution": {
"values": [
{
"timex": "2018-05-24",
"type": "date",
"value": "2018-05-24"
}
]
}
}]
}
,
{
"Input": "Have a great month.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "python",
"Results": [{
"Text": "month",
"Start": 13,
"End": 17,
"TypeName": "datetimeV2.daterange",
"Resolution": {
"values": [
{
"timex": "2018-05",
"type": "daterange",
"start": "2018-05-01",
"end": "2018-06-01"
}
]
}
}]
}
,
{
"Input": "Nice day.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "python",
"Results": []
}
,
{
"Input": "Have a great week!",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "python",
"Results": [{
"Text": "week",
"Start": 13,
"End": 16,
"TypeName": "datetimeV2.daterange",
"Resolution": {
"values": [
{
"timex": "2018-W21",
"type": "daterange",
"start": "2018-05-21",
"end": "2018-05-28"
}
]
}
}]
}
]
56 changes: 56 additions & 0 deletions Specs/DateTime/English/DateTimeModelCalendarMode.json
Original file line number Diff line number Diff line change
Expand Up @@ -528,5 +528,61 @@
}
}
]
},
{
"Input": "Hey, we got Cloud partner of the year.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "javascript,python",
"Results": []
},
{
"Input": "Hey, we got a partner of the month.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "javascript,python",
"Results": []
},
{
"Input": "Hey, we got a partner of the week.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "javascript,python",
"Results": []
},
{
"Input": "Hey, we got a partner of the day.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "javascript,python",
"Results": []
},
{
"Input": "Have a great month.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "javascript,python",
"Results": []
},
{
"Input": "Nice day.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "javascript,python",
"Results": []
},
{
"Input": "Have a great week!",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "javascript,python",
"Results": []
}
]
56 changes: 56 additions & 0 deletions Specs/DateTime/English/DateTimeModelComplexCalendar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1816,5 +1816,61 @@
}
}
]
},
{
"Input": "Hey, we got Cloud partner of the year.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "javascript,python",
"Results": []
},
{
"Input": "Hey, we got a partner of the month.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "javascript,python",
"Results": []
},
{
"Input": "Hey, we got a partner of the week.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "javascript,python",
"Results": []
},
{
"Input": "Hey, we got a partner of the day.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "javascript,python",
"Results": []
},
{
"Input": "Have a great month.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "javascript,python",
"Results": []
},
{
"Input": "Nice day.",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "javascript,python",
"Results": []
},
{
"Input": "Have a great week!",
"Context": {
"ReferenceDateTime": "2018-05-24T00:00:00"
},
"NotSupported": "javascript,python",
"Results": []
}
]

0 comments on commit 3e51d89

Please sign in to comment.