Skip to content

Commit

Permalink
Support early/mid/late <month> #35
Browse files Browse the repository at this point in the history
Summary: Closes #43

Reviewed By: blandinw

Differential Revision: D5264974

Pulled By: patapizza

fbshipit-source-id: 0330f2b
  • Loading branch information
serefayar authored and facebook-github-bot committed Jun 16, 2017
1 parent 3ec2228 commit b057419
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Duckling/Ranking/Classifiers/EN.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,16 @@ classifiers
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("part of <named-month>",
Classifier{okData =
ClassData{prior = 0.0, unseen = -2.1972245773362196,
likelihoods =
HashMap.fromList
[("March", -0.6931471805599453), ("month", -0.6931471805599453)],
n = 3},
koData =
ClassData{prior = -infinity, unseen = -1.0986122886681098,
likelihoods = HashMap.fromList [], n = 0}}),
("a <unit-of-duration>",
Classifier{okData =
ClassData{prior = -0.6286086594223742,
Expand Down Expand Up @@ -1621,8 +1631,8 @@ classifiers
n = 18}}),
("March",
Classifier{okData =
ClassData{prior = 0.0, unseen = -2.772588722239781,
likelihoods = HashMap.fromList [("", 0.0)], n = 14},
ClassData{prior = 0.0, unseen = -2.9444389791664407,
likelihoods = HashMap.fromList [("", 0.0)], n = 17},
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
Expand Down
9 changes: 9 additions & 0 deletions Duckling/Time/EN/Corpus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -785,4 +785,13 @@ allExamples = concat
[ "at 4:23"
, "4:23am"
]
, examples (datetimeInterval ((2013, 3, 1, 0, 0, 0), (2013, 3, 11, 0, 0, 0)) Day)
[ "early March"
]
, examples (datetimeInterval ((2013, 3, 11, 0, 0, 0), (2013, 3, 21, 0, 0, 0)) Day)
[ "mid March"
]
, examples (datetimeInterval ((2013, 3, 21, 0, 0, 0), (2013, 4, 1, 0, 0, 0)) Day)
[ "late March"
]
]
23 changes: 23 additions & 0 deletions Duckling/Time/EN/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,28 @@ ruleMonths = zipWith go months [1..12]
, prod = \_ -> tt $ month i
}

rulePartOfMonth :: Rule
rulePartOfMonth = Rule
{ name = "part of <named-month>"
, pattern =
[ regex "(early|mid|late)-?( of)?"
, Predicate isAMonth
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):Token Time td:_) -> do
(sd, ed) <- case Text.toLower match of
"early" -> Just (1, 10)
"mid" -> Just (11, 20)
"late" -> Just (21, -1)
_ -> Nothing
start <- intersect td $ dayOfMonth sd
end <- if ed /= -1
then intersect td $ dayOfMonth ed
else Just $ cycleLastOf TG.Day td
Token Time <$> interval TTime.Open start end
_ -> Nothing
}

usHolidays :: [(Text, String, Int, Int)]
usHolidays =
[ ( "Christmas" , "(xmas|christmas)( day)?" , 12, 25 )
Expand Down Expand Up @@ -1593,6 +1615,7 @@ rules =
, ruleDurationAfterBeforeTime
, ruleInNumeral
, ruleTimezone
, rulePartOfMonth
]
++ ruleInstants
++ ruleDaysOfWeek
Expand Down

0 comments on commit b057419

Please sign in to comment.