facebook / duckling

Language, engine, and tooling for expressing, testing, and evaluating composable language rules on input strings.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[ES] Time interval is upper-bound inclusive

emlautarom1 opened this issue · comments

Consider the following test case: de 14 a 16 hs ("from 14 to 16" in English). The output is as follows:

de <datetime> - <datetime> (interval) (de 14 a 16)
-- regex (de)
-- time-of-day (latent) (14)
-- -- integer (numeric) (14)
-- -- -- regex (14)
-- regex (a)
-- time-of-day (latent) (16)
-- -- integer (numeric) (16)
-- -- -- regex (16)
[Entity {dim = "time", body = "de 14 a 16", value = RVal Time (TimeValue (IntervalValue (InstantValue {vValue = 2013-02-12 14:00:00 -0200, vGrain = Hour},InstantValue {vValue = 2013-02-12 16:00:00 -0200, vGrain = Hour})) [IntervalValue (InstantValue {vValue = 2013-02-12 14:00:00 -0200, vGrain = Hour},InstantValue {vValue = 2013-02-12 16:00:00 -0200, vGrain = Hour}),IntervalValue (InstantValue {vValue = 2013-02-13 14:00:00 -0200, vGrain = Hour},InstantValue {vValue = 2013-02-13 16:00:00 -0200, vGrain = Hour}),IntervalValue (InstantValue {vValue = 2013-02-14 14:00:00 -0200, vGrain = Hour},InstantValue {vValue = 2013-02-14 16:00:00 -0200, vGrain = Hour})] Nothing), start = 0, end = 10, latent = False, enode = Node {nodeRange = Range 0 10, token = Token Time TimeData{latent=False, grain=Hour, form=Nothing, direction=Nothing, holiday=Nothing, hasTimezone=False}, children = [Node {nodeRange = Range 0 2, token = Token RegexMatch (GroupMatch []), children = [], rule = Nothing},Node {nodeRange = Range 3 5, token = Token Time TimeData{latent=True, grain=Hour, form=Just (TimeOfDay {hours = Just 14, is12H = False}), direction=Nothing, holiday=Nothing, hasTimezone=False}, children = [Node {nodeRange = Range 3 5, token = Token Numeral (NumeralData {value = 14.0, grain = Nothing, multipliable = False, okForAnyTime = True}), children = [Node {nodeRange = Range 3 5, token = Token RegexMatch (GroupMatch ["14"]), children = [], rule = Nothing}], rule = Just "integer (numeric)"}], rule = Just "time-of-day (latent)"},Node {nodeRange = Range 6 7, token = Token RegexMatch (GroupMatch []), children = [], rule = Nothing},Node {nodeRange = Range 8 10, token = Token Time TimeData{latent=True, grain=Hour, form=Just (TimeOfDay {hours = Just 16, is12H = False}), direction=Nothing, holiday=Nothing, hasTimezone=False}, children = [Node {nodeRange = Range 8 10, token = Token Numeral (NumeralData {value = 16.0, grain = Nothing, multipliable = False, okForAnyTime = True}), children = [Node {nodeRange = Range 8 10, token = Token RegexMatch (GroupMatch ["16"]), children = [], rule = Nothing}], rule = Just "integer (numeric)"}], rule = Just "time-of-day (latent)"}], rule = Just "de <datetime> - <datetime> (interval)"}}]

As you can see, the output is 14:00 - 16:00. The API states that the upper bound should be exclusive, that is 14:00 - 17:00. Other languages return the correct result (EN, DE, etc.) but not in Spanish. The cause is that the time interval is defined as "Open":

ruleDeDatetimeDatetimeInterval :: Rule
ruleDeDatetimeDatetimeInterval = Rule
{ name = "de <datetime> - <datetime> (interval)"
, pattern =
[ regex "del?"
, dimension Time
, regex "\\-|al?"
, dimension Time
]
, prod = \tokens -> case tokens of
(_:Token Time td1:_:Token Time td2:_) ->
Token Time <$> interval TTime.Open td1 td2
_ -> Nothing
}

For example, in English the interval is "Closed". This yields the correct result.

ruleIntervalFrom :: Rule
ruleIntervalFrom = Rule
{ name = "from <datetime> - <datetime> (interval)"
, pattern =
[ regex "from"
, dimension Time
, regex "\\-|to|th?ru|through|(un)?til(l)?"
, dimension Time
]
, prod = \tokens -> case tokens of
(_:Token Time td1:_:Token Time td2:_) ->
Token Time <$> interval TTime.Closed td1 td2
_ -> Nothing
}


The fix requires changing the type of interval from "Open" to "Closed" and adjust the tests.