Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support early/mid/late <month> #35 #43

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 32 additions & 2 deletions Duckling/Ranking/Classifiers/EN.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ classifiers
koData =
ClassData{prior = -infinity, unseen = -1.3862943611198906,
likelihoods = HashMap.fromList [], n = 0}}),
("early <named-month>",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.6094379124341003,
likelihoods =
HashMap.fromList
[("March", -0.6931471805599453), ("month", -0.6931471805599453)],
n = 1},
koData =
ClassData{prior = -infinity, unseen = -1.0986122886681098,
likelihoods = HashMap.fromList [], n = 0}}),
("<day-of-month> (ordinal or number) <named-month>",
Classifier{okData =
ClassData{prior = -0.916290731874155, unseen = -2.3978952727983707,
Expand Down Expand Up @@ -944,6 +954,16 @@ classifiers
koData =
ClassData{prior = -infinity, unseen = -0.6931471805599453,
likelihoods = HashMap.fromList [], n = 0}}),
("late <named-month>",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.6094379124341003,
likelihoods =
HashMap.fromList
[("March", -0.6931471805599453), ("month", -0.6931471805599453)],
n = 1},
koData =
ClassData{prior = -infinity, unseen = -1.0986122886681098,
likelihoods = HashMap.fromList [], n = 0}}),
("<hour-of-day> <integer>",
Classifier{okData =
ClassData{prior = -infinity, unseen = -1.0986122886681098,
Expand Down Expand Up @@ -1166,6 +1186,16 @@ classifiers
koData =
ClassData{prior = -infinity, unseen = -1.0986122886681098,
likelihoods = HashMap.fromList [], n = 0}}),
("mid <named-month>",
Classifier{okData =
ClassData{prior = 0.0, unseen = -1.6094379124341003,
likelihoods =
HashMap.fromList
[("March", -0.6931471805599453), ("month", -0.6931471805599453)],
n = 1},
koData =
ClassData{prior = -infinity, unseen = -1.0986122886681098,
likelihoods = HashMap.fromList [], n = 0}}),
("by <time>",
Classifier{okData =
ClassData{prior = 0.0, unseen = -2.9444389791664407,
Expand Down Expand Up @@ -1621,8 +1651,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"
]
]
31 changes: 31 additions & 0 deletions Duckling/Time/EN/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,36 @@ ruleMonths = zipWith go months [1..12]
, prod = \_ -> tt $ month i
}

partOfMonths :: [(Text, String, Int, Int)]
partOfMonths =
[ ("early <named-month>", "early-?( of)?", 1, 10)
, ("mid <named-month>", "mid-?( of)?", 11, 20)
, ("late <named-month>", "late-?( of)?", 21, -1)
]


rulePartOfMonths :: [Rule]
rulePartOfMonths = map go partOfMonths
where
go :: (Text, String, Int, Int) -> Rule
go (name, regexPattern, sd, ed) = Rule
{ name = name
, pattern =
[ regex regexPattern
, Predicate isAMonth
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> do
start <- intersect td (dayOfMonth sd)
end <- case ed of
- 1 -> Just $ cycleLastOf TG.Day td
_ -> intersect td (dayOfMonth ed)
Token Time <$> interval TTime.Open start end
_ -> Nothing
}



usHolidays :: [(Text, String, Int, Int)]
usHolidays =
[ ( "Christmas" , "(xmas|christmas)( day)?" , 12, 25 )
Expand Down Expand Up @@ -1599,3 +1629,4 @@ rules =
++ ruleMonths
++ ruleUSHolidays
++ ruleMoreUSHolidays
++ rulePartOfMonths