Skip to content

Commit

Permalink
[EN DateTimeV2] Fix for case like 'March one 2020'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-gradinari committed Apr 27, 2023
1 parent 17de6bb commit dcc8e88
Show file tree
Hide file tree
Showing 4 changed files with 543 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1417,8 +1417,13 @@ def parse_number_with_month(self, source: str, reference: datetime) -> DateTimeP
if match:
month = self.config.month_of_year.get(match.group())
day = num
suffix = trimmed_source[match.end():]
prefix = trimmed_source[0: match.start()]

prefix_end = min(ers[0].start, match.start())
prefix = trimmed_source[0:prefix_end]

suffix_start = max(ers[0].start + ers[0].length, match.end())
suffix = trimmed_source[suffix_start:]

year = self._get_year_in_affix(suffix, False)

if year == Constants.INVALID_YEAR and self.config.check_both_before_after:
Expand Down Expand Up @@ -1472,7 +1477,7 @@ def parse_number_with_month(self, source: str, reference: datetime) -> DateTimeP
future_date = future_date.replace(year=future_date.year+1)

if past_date >= reference:
past_date = past_date.replace(year=past_date.year+1)
past_date = past_date.replace(year=past_date.year-1)
else:
result.timex = DateTimeFormatUtil.luis_date(year, month, day)

Expand Down
99 changes: 99 additions & 0 deletions Specs/DateTime/English/DateExtractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,105 @@
}
]
},
{
"Input": "I'll go back on April first 2021.",
"Results": [
{
"Text": "April first 2021",
"Type": "date",
"Start": 16,
"Length": 16
}
]
},
{
"Input": "I'll go back Jun third 2023",
"Results": [
{
"Text": "Jun third 2023",
"Type": "date",
"Start": 13,
"Length": 14
}
]
},
{
"Input": "I'll go back September the second 2025.",
"Results": [
{
"Text": "September the second 2025",
"Type": "date",
"Start": 13,
"Length": 25
}
]
},
{
"Input": "I'll go back March one 2020",
"Results": [
{
"Text": "March one 2020",
"Type": "date",
"Start": 13,
"Length": 14
}
]
},
{
"Input": "I'll go back Aug twelve 2024.",
"Results": [
{
"Text": "Aug twelve 2024",
"Type": "date",
"Start": 13,
"Length": 15
}
]
},
{
"Input": "I'll go back February twenty fifth",
"Results": [
{
"Text": "February twenty fifth",
"Type": "date",
"Start": 13,
"Length": 21
}
]
},
{
"Input": "I'll go back on Nov the twelfth.",
"Results": [
{
"Text": "Nov the twelfth",
"Type": "date",
"Start": 16,
"Length": 15
}
]
},
{
"Input": "I'll go back January thirty one",
"Results": [
{
"Text": "January thirty one",
"Type": "date",
"Start": 13,
"Length": 18
}
]
},
{
"Input": "I'll go back Oct twenty three.",
"Results": [
{
"Text": "Oct twenty three",
"Type": "date",
"Start": 13,
"Length": 16
}
]
},
{
"Input": "i went back two months ago",
"Results": [
Expand Down
207 changes: 207 additions & 0 deletions Specs/DateTime/English/DateParser.json
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,213 @@
}
]
},
{
"Input": "I'll go back on April first 2021.",
"Context": {
"ReferenceDateTime": "2023-04-25T00:00:00"
},
"Results": [
{
"Text": "April first 2021",
"Type": "date",
"Value": {
"Timex": "2021-04-01",
"FutureResolution": {
"date": "2021-04-01"
},
"PastResolution": {
"date": "2021-04-01"
}
},
"Start": 16,
"Length": 16
}
]
},
{
"Input": "I'll go back Jun third 2023",
"Context": {
"ReferenceDateTime": "2023-04-25T00:00:00"
},
"Results": [
{
"Text": "Jun third 2023",
"Type": "date",
"Value": {
"Timex": "2023-06-03",
"FutureResolution": {
"date": "2023-06-03"
},
"PastResolution": {
"date": "2023-06-03"
}
},
"Start": 13,
"Length": 14
}
]
},
{
"Input": "I'll go back September the second 2025.",
"Context": {
"ReferenceDateTime": "2023-04-25T00:00:00"
},
"Results": [
{
"Text": "September the second 2025",
"Type": "date",
"Value": {
"Timex": "2025-09-02",
"FutureResolution": {
"date": "2025-09-02"
},
"PastResolution": {
"date": "2025-09-02"
}
},
"Start": 13,
"Length": 25
}
]
},
{
"Input": "I'll go back March one 2020",
"Context": {
"ReferenceDateTime": "2023-04-25T00:00:00"
},
"Results": [
{
"Text": "March one 2020",
"Type": "date",
"Value": {
"Timex": "2020-03-01",
"FutureResolution": {
"date": "2020-03-01"
},
"PastResolution": {
"date": "2020-03-01"
}
},
"Start": 13,
"Length": 14
}
]
},
{
"Input": "I'll go back Aug twelve 2024.",
"Context": {
"ReferenceDateTime": "2023-04-25T00:00:00"
},
"Results": [
{
"Text": "Aug twelve 2024",
"Type": "date",
"Value": {
"Timex": "2024-08-12",
"FutureResolution": {
"date": "2024-08-12"
},
"PastResolution": {
"date": "2024-08-12"
}
},
"Start": 13,
"Length": 15
}
]
},
{
"Input": "I'll go back February twenty fifth",
"Context": {
"ReferenceDateTime": "2023-04-25T00:00:00"
},
"Results": [
{
"Text": "February twenty fifth",
"Type": "date",
"Value": {
"Timex": "XXXX-02-25",
"FutureResolution": {
"date": "2024-02-25"
},
"PastResolution": {
"date": "2023-02-25"
}
},
"Start": 13,
"Length": 21
}
]
},
{
"Input": "I'll go back on Nov the twelfth.",
"Context": {
"ReferenceDateTime": "2023-04-25T00:00:00"
},
"Results": [
{
"Text": "Nov the twelfth",
"Type": "date",
"Value": {
"Timex": "XXXX-11-12",
"FutureResolution": {
"date": "2023-11-12"
},
"PastResolution": {
"date": "2022-11-12"
}
},
"Start": 16,
"Length": 15
}
]
},
{
"Input": "I'll go back January thirty one",
"Context": {
"ReferenceDateTime": "2023-04-25T00:00:00"
},
"Results": [
{
"Text": "January thirty one",
"Type": "date",
"Value": {
"Timex": "XXXX-01-31",
"FutureResolution": {
"date": "2024-01-31"
},
"PastResolution": {
"date": "2023-01-31"
}
},
"Start": 13,
"Length": 18
}
]
},
{
"Input": "I'll go back Oct twenty three.",
"Context": {
"ReferenceDateTime": "2023-04-25T00:00:00"
},
"Results": [
{
"Text": "Oct twenty three",
"Type": "date",
"Value": {
"Timex": "XXXX-10-23",
"FutureResolution": {
"date": "2023-10-23"
},
"PastResolution": {
"date": "2022-10-23"
}
},
"Start": 13,
"Length": 16
}
]
},
{
"Input": "I'll go back on Friday",
"Context": {
Expand Down
Loading

0 comments on commit dcc8e88

Please sign in to comment.