mirror of
https://github.com/facebook/duckling.git
synced 2024-09-11 21:27:13 +03:00
EN/Time: Add "<integer> <day-of-time> from <time>" rule
Summary: "What is the date three Fridays from now?" resolves incorrectly: - On Friday, it detects "three fridays", "fridays from now" - On other days, it detects "three fridays", "from now" Thus, added a new rule, "<integer> <day-of-week> from <time>" to give the expected result of three Fridays after the current day and added test examples. If there are too many test examples, please let me know! Reviewed By: chinmay87 Differential Revision: D15110770 fbshipit-source-id: a77b86de8b6d8f7c947df9e14edb17f61bcc8419
This commit is contained in:
parent
9962e25845
commit
0b551597ce
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
@ -13,15 +13,17 @@ module Duckling.Time.EN.Corpus
|
||||
, defaultCorpus
|
||||
, negativeCorpus
|
||||
, latentCorpus
|
||||
, diffCorpus
|
||||
) where
|
||||
|
||||
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)
|
||||
import Duckling.Time.Types hiding (Month, refTime)
|
||||
import Duckling.TimeGrain.Types hiding (add)
|
||||
|
||||
corpus :: Corpus
|
||||
@ -153,6 +155,21 @@ latentCorpus = (testContext, testOptions {withLatent = True}, xs)
|
||||
]
|
||||
]
|
||||
|
||||
diffContext :: Context
|
||||
diffContext = Context
|
||||
{ locale = makeLocale EN Nothing
|
||||
, referenceTime = refTime (2013, 2, 15, 4, 30, 0) (-2)
|
||||
}
|
||||
|
||||
diffCorpus :: Corpus
|
||||
diffCorpus = (diffContext, testOptions, diffExamples)
|
||||
where
|
||||
diffExamples =
|
||||
examples (datetime (2013, 3, 8, 0, 0, 0) Day)
|
||||
[ "3 fridays from now"
|
||||
, "three fridays from now"
|
||||
]
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (datetime (2013, 2, 12, 4, 30, 0) Second)
|
||||
@ -614,6 +631,18 @@ allExamples = concat
|
||||
, examples (datetime (2016, 2, 12, 0, 0, 0) Day)
|
||||
[ "3 years from today"
|
||||
]
|
||||
, examples (datetime (2013, 3, 1, 0, 0, 0) Day)
|
||||
[ "3 fridays from now"
|
||||
, "three fridays from now"
|
||||
]
|
||||
, examples (datetime (2013, 2, 24, 0, 0, 0) Day)
|
||||
[ "2 sundays from now"
|
||||
, "two sundays from now"
|
||||
]
|
||||
, examples (datetime (2013, 3, 12, 0, 0, 0) Day)
|
||||
[ "4 tuesdays from now"
|
||||
, "four tuesdays from now"
|
||||
]
|
||||
, examples (datetime (2013, 2, 19, 4, 0, 0) Hour)
|
||||
[ "in 7 days"
|
||||
]
|
||||
|
@ -322,6 +322,22 @@ ruleTheNthTimeAfterTime = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNDOWFromTime :: Rule
|
||||
ruleNDOWFromTime = Rule
|
||||
{ name = "<integer> <day-of-week> from <time>"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, Predicate isADayOfWeek
|
||||
, regex "from"
|
||||
, dimension Time
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(token:Token Time td1:_:Token Time td2:_) -> do
|
||||
n <- getIntValue token
|
||||
tt $ predNthAfter (n - 1) td1 td2
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleYearLatent :: Rule
|
||||
ruleYearLatent = Rule
|
||||
{ name = "year (latent)"
|
||||
@ -2392,6 +2408,7 @@ rules =
|
||||
, ruleTheNthTimeOfTime
|
||||
, ruleNthTimeAfterTime
|
||||
, ruleTheNthTimeAfterTime
|
||||
, ruleNDOWFromTime
|
||||
, ruleYearLatent
|
||||
, ruleYearADBC
|
||||
, ruleTheDOMNumeral
|
||||
|
@ -47,6 +47,7 @@ tests :: TestTree
|
||||
tests = testGroup "EN Tests"
|
||||
[ makeCorpusTest [This Time] defaultCorpus
|
||||
, makeNegativeCorpusTest [This Time] negativeCorpus
|
||||
, makeCorpusTest [This Time] diffCorpus
|
||||
, exactSecondTests
|
||||
, valuesTest
|
||||
, intersectTests
|
||||
|
Loading…
Reference in New Issue
Block a user