Added new rules to parse phrases for upcoming weeks. (#491)

Summary:
the new rules could parse phrases in the form of
xxx upcoming weeks
upcoming xxx weeks
Pull Request resolved: https://github.com/facebook/duckling/pull/491

Test Plan: Imported from GitHub, without a Test Plan: line.

Differential Revision: D21959647

Pulled By: chinmay87

fbshipit-source-id: a062a8c7a6c2e23b921b1099b886fa589c69c454
This commit is contained in:
Bing Yuan 2020-06-17 14:29:38 -07:00 committed by Facebook GitHub Bot
parent 474ae1b851
commit 097b9260d5
15 changed files with 6715 additions and 5621 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -322,6 +322,7 @@ allExamples = concat
[ "next week"
, "the following week"
, "around next week"
, "upcoming week"
]
, examples (datetime (2013, 1, 1, 0, 0, 0) Month)
[ "last month"
@ -1844,4 +1845,54 @@ allExamples = concat
, examples (datetimeHoliday (2011, 12, 25, 0, 0, 0) Day "Christmas")
[ "the 3rd closest xmas to today"
]
, examples (datetime (2013, 2, 25, 0, 0, 0) Week)
[ "upcoming two weeks"
, "upcoming two week"
, "upcoming 2 weeks"
, "upcoming 2 week"
, "two upcoming weeks"
, "two upcoming week"
, "2 upcoming weeks"
, "2 upcoming week"
]
, examples (datetime (2013, 2, 14, 0, 0, 0) Day)
[ "upcoming two days"
, "upcoming two day"
, "upcoming 2 days"
, "upcoming 2 day"
, "two upcoming days"
, "two upcoming day"
, "2 upcoming days"
, "2 upcoming day"
]
, examples (datetime (2013, 4, 1, 0, 0, 0) Month)
[ "upcoming two months"
, "upcoming two month"
, "upcoming 2 months"
, "upcoming 2 month"
, "two upcoming months"
, "two upcoming month"
, "2 upcoming months"
, "2 upcoming month"
]
, examples (datetime (2013, 7, 1, 0, 0, 0) Quarter)
[ "upcoming two quarters"
, "upcoming two quarter"
, "upcoming 2 quarters"
, "upcoming 2 quarter"
, "two upcoming quarters"
, "two upcoming quarter"
, "2 upcoming quarters"
, "2 upcoming quarter"
]
, examples (datetime (2015, 1, 1, 0, 0, 0) Year)
[ "upcoming two years"
, "upcoming two year"
, "upcoming 2 years"
, "upcoming 2 year"
, "two upcoming years"
, "two upcoming year"
, "2 upcoming years"
, "2 upcoming year"
]
]

View File

@ -2001,7 +2001,7 @@ ruleCycleThisLastNext :: Rule
ruleCycleThisLastNext = Rule
{ name = "this|last|next <cycle>"
, pattern =
[ regex "(this|current|coming|next|(the( following)?)|last|past|previous)"
[ regex "(this|current|coming|next|(the( following)?)|last|past|previous|upcoming)"
, dimension TimeGrain
]
, prod = \tokens -> case tokens of
@ -2014,6 +2014,7 @@ ruleCycleThisLastNext = Rule
"past" -> tt . cycleNth grain $ - 1
"previous" -> tt . cycleNth grain $ - 1
"next" -> tt $ cycleNth grain 1
"upcoming" -> tt $ cycleNth grain 1
"the following" -> tt $ cycleNth grain 1
"the" -> tt $ cycleNth grain 0
_ -> Nothing
@ -2482,6 +2483,38 @@ ruleMidDay = Rule
, prod = \_ -> tt $ hour False 12
}
ruleUpcomingGrain :: Rule
ruleUpcomingGrain = Rule
{ name = "upcoming <integer> <cycle>"
, pattern =
[ regex "upcoming"
, Predicate isNatural
, dimension TimeGrain
]
, prod = \case
( _:
Token Numeral NumeralData{ TNumeral.value = numOfTimeGrain }:
Token TimeGrain grain:
_) -> tt $ cycleNth grain $ floor numOfTimeGrain
_ -> Nothing
}
ruleUpcomingGrainAlt :: Rule
ruleUpcomingGrainAlt = Rule
{ name = "<integer> upcoming <cycle>"
, pattern =
[ Predicate isNatural
, regex "upcoming"
, dimension TimeGrain
]
, prod = \case
( Token Numeral NumeralData{ TNumeral.value = numOfTimeGrain }:
_:
Token TimeGrain grain:
_) -> tt $ cycleNth grain $ floor numOfTimeGrain
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleIntersect
@ -2616,6 +2649,8 @@ rules =
, ruleClosest
, ruleNthClosest
, ruleMidDay
, ruleUpcomingGrain
, ruleUpcomingGrainAlt
]
++ ruleInstants
++ ruleDaysOfWeek