Time/EN: the (nth) closest (day) to (time)

Summary:
Leveraging `predNthClosest` helper in English rules.
"the second closest monday to february 6"
"the closest tax day to boss day 2018"

Reviewed By: haoxuany

Differential Revision: D20214444

fbshipit-source-id: b6be32f63097d221aa7ccc6df4e3639e4deee4a9
This commit is contained in:
Julien Odent 2020-03-03 11:53:27 -08:00 committed by Facebook Github Bot
parent 11f671a95a
commit f57593c9df
16 changed files with 7354 additions and 6572 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

@ -19,7 +19,6 @@ import Data.String
import Prelude
import Duckling.Core
import Duckling.Resolve
import Duckling.Testing.Types hiding (examples)
import Duckling.Time.Corpus
import Duckling.Time.Types hiding (Month, refTime)
@ -1353,6 +1352,12 @@ allExamples = concat
, "4:23am"
, "four twenty-three a m"
]
, examples (datetime (2013, 10, 7, 0, 0, 0) Day)
[ "the closest Monday to Oct 5th"
]
, examples (datetime (2013, 9, 30, 0, 0, 0) Day)
[ "the second closest Mon to October fifth"
]
, examples (datetimeInterval ((2013, 3, 1, 0, 0, 0), (2013, 3, 11, 0, 0, 0)) Day)
[ "early March"
]
@ -1827,4 +1832,13 @@ allExamples = concat
, "chaitra sukladi 2018"
, "chaitra sukhladi 2018"
]
, examples (datetimeHoliday (2012, 12, 25, 0, 0, 0) Day "Christmas")
[ "the closest xmas to today"
]
, examples (datetimeHoliday (2013, 12, 25, 0, 0, 0) Day "Christmas")
[ "the second closest xmas to today"
]
, examples (datetimeHoliday (2011, 12, 25, 0, 0, 0) Day "Christmas")
[ "the 3rd closest xmas to today"
]
]

View File

@ -1018,7 +1018,9 @@ ruleWeekend = Rule
ruleWeek :: Rule
ruleWeek = Rule
{ name = "week"
, pattern = [regex "(all|rest of the|the) week"]
, pattern =
[ regex "(all|rest of the|the) week"
]
, prod = \case
(Token RegexMatch (GroupMatch (match:_)):_) ->
let end = cycleNthAfter True TG.Day (-2) $ cycleNth TG.Week 1
@ -1515,7 +1517,9 @@ ruleEndOrBeginningOfYear = Rule
ruleEndOfYear :: Rule
ruleEndOfYear = Rule
{ name = "end of year"
, pattern = [ regex "(by (the )?|(at )?the )?(EOY|end of (the )?year)" ]
, pattern =
[ regex "(by (the )?|(at )?the )?(EOY|end of (the )?year)"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
start <- std
@ -1532,7 +1536,9 @@ ruleEndOfYear = Rule
ruleBeginningOfYear :: Rule
ruleBeginningOfYear = Rule
{ name = "beginning of year"
, pattern = [ regex "((at )?the )?(BOY|beginning of (the )?year)" ]
, pattern =
[ regex "((at )?the )?(BOY|beginning of (the )?year)"
]
, prod = \_ -> do
start <- intersect (month 1) $ cycleNth TG.Year 0
end <- intersect (month 4) $ cycleNth TG.Year 0
@ -1558,6 +1564,39 @@ ruleEndOrBeginningOfWeek = Rule
_ -> Nothing
}
ruleClosest :: Rule
ruleClosest = Rule
{ name = "the closest <day> to <time>"
, pattern =
[ regex "the\\s+closest"
, Predicate $ isGrainOfTime TG.Day
, regex "to"
, dimension Time
]
, prod = \case
(_:Token Time td1:_:Token Time td2:_) ->
tt $ predNthClosest 0 td1 td2
_ -> Nothing
}
ruleNthClosest :: Rule
ruleNthClosest = Rule
{ name = "the <ordinal> closest <day> to <time>"
, pattern =
[ regex "the"
, dimension Ordinal
, regex "closest"
, Predicate $ isGrainOfTime TG.Day
, regex "to"
, dimension Time
]
, prod = \case
(_:token:_:Token Time td1:_:Token Time td2:_) -> do
n <- getIntValue token
tt $ predNthClosest (n - 1) td1 td2
_ -> Nothing
}
rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays = mkRuleHolidays
-- Fixed dates, year over year
@ -2565,6 +2604,8 @@ rules =
, ruleBeginningOfMonth
, ruleEndOfYear
, ruleBeginningOfYear
, ruleClosest
, ruleNthClosest
]
++ ruleInstants
++ ruleDaysOfWeek

View File

@ -15,7 +15,6 @@ import Prelude
import Duckling.Testing.Types hiding (examples)
import Duckling.Time.Corpus
import Duckling.Time.Types hiding (Month)
import Duckling.TimeGrain.Types hiding (add)
allExamples :: [Example]
@ -216,6 +215,7 @@ allExamples = concat
[ "super tuesday 2012"
, "last super tuesday"
, "super tuesday last year"
, "the second closest super tuesday to the third Sunday of 2015"
]
, examples (datetimeHoliday (2016, 3, 1, 0, 0, 0) Day "Super Tuesday")
[ "super tuesday 2016"
@ -227,10 +227,22 @@ allExamples = concat
, "super tuesday in seven years"
, "the first super tue. after 2019"
, "the 2nd Super Tuesday after next year"
, "the closest super tuesday to 2019"
, "the closest super tuesday to March 6, 2019"
]
, examples (datetimeHoliday (2004, 2, 3, 0, 0, 0) Day "Mini-Tuesday")
[ "mini-tuesday"
, "Mini - Tuesday 2004"
, "mini tuesday nine yrs ago"
]
, examples (datetimeHoliday (2004, 3, 2, 0, 0, 0) Day "Super Tuesday")
[ "the closest super tuesday to mini-tuesday"
]
, examples (datetimeHoliday (2000, 3, 7, 0, 0, 0) Day "Super Tuesday")
[ "the second closest super tuesday to mini-tuesday"
]
, examples (datetimeHoliday (2008, 2, 5, 0, 0, 0) Day "Super Tuesday")
[ "the 3rd closest super tuesday to mini-tuesday"
, "the first closest Super Tuesday to tax day 2006"
]
]