Duration/RO: Fix for values above 20

Summary: Same as previous commits.

Reviewed By: haoxuany

Differential Revision: D8325566

fbshipit-source-id: d4f1ae57cabdbdf8149f0673e6b7832496c2c88c
This commit is contained in:
Julien Odent 2018-06-07 16:32:01 -07:00 committed by Facebook Github Bot
parent 567450beea
commit bac1245f45
3 changed files with 31 additions and 8 deletions

View File

@ -38,6 +38,7 @@ allExamples = concat
, examples (DurationData 45 Minute) , examples (DurationData 45 Minute)
[ "trei sferturi de oră" [ "trei sferturi de oră"
, "45min" , "45min"
, "45 de minute"
] ]
, examples (DurationData 12 Week) , examples (DurationData 12 Week)
[ "doișpe saptamanile" [ "doișpe saptamanile"

View File

@ -7,18 +7,22 @@
{-# LANGUAGE GADTs #-} {-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Duckling.Duration.RO.Rules module Duckling.Duration.RO.Rules
( rules ) where ( rules
) where
import Prelude
import Data.String import Data.String
import Prelude
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers import Duckling.Duration.Helpers
import qualified Duckling.TimeGrain.Types as TG import Duckling.Numeral.Helpers (numberWith)
import Duckling.Types import Duckling.Types
import qualified Duckling.Numeral.Types as TNumeral
import qualified Duckling.TimeGrain.Types as TG
ruleQuarterOfAnHour :: Rule ruleQuarterOfAnHour :: Rule
ruleQuarterOfAnHour = Rule ruleQuarterOfAnHour = Rule
@ -54,7 +58,7 @@ ruleOUnitofduration = Rule
[ regex "o|un" [ regex "o|un"
, dimension TimeGrain , dimension TimeGrain
] ]
, prod = \tokens -> case tokens of , prod = \case
(_:Token TimeGrain grain:_) -> Just . Token Duration $ duration grain 1 (_:Token TimeGrain grain:_) -> Just . Token Duration $ duration grain 1
_ -> Nothing _ -> Nothing
} }
@ -66,11 +70,27 @@ ruleExactInJurDeDuration = Rule
[ regex "(exact|aproximativ|(i|î)n jur de)" [ regex "(exact|aproximativ|(i|î)n jur de)"
, dimension Duration , dimension Duration
] ]
, prod = \tokens -> case tokens of , prod = \case
(_:token:_) -> Just token (_:token:_) -> Just token
_ -> Nothing _ -> Nothing
} }
ruleIntegerDeUnitofduration :: Rule
ruleIntegerDeUnitofduration = Rule
{ name = "<integer> <unit-of-duration>"
, pattern =
[ numberWith TNumeral.value (>= 20)
, regex "de"
, dimension TimeGrain
]
, prod = \case
(Token Numeral TNumeral.NumeralData{TNumeral.value = v}:
_:
Token TimeGrain grain:
_) -> Just . Token Duration . duration grain $ floor v
_ -> Nothing
}
rules :: [Rule] rules :: [Rule]
rules = rules =
[ ruleExactInJurDeDuration [ ruleExactInJurDeDuration
@ -78,4 +98,5 @@ rules =
, ruleOUnitofduration , ruleOUnitofduration
, ruleQuarterOfAnHour , ruleQuarterOfAnHour
, ruleTreiSferturiDeOra , ruleTreiSferturiDeOra
, ruleIntegerDeUnitofduration
] ]

View File

@ -10,15 +10,16 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Duckling.TimeGrain.RO.Rules module Duckling.TimeGrain.RO.Rules
( rules ) where ( rules
) where
import Data.String
import Data.Text (Text) import Data.Text (Text)
import Prelude import Prelude
import Data.String
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import qualified Duckling.TimeGrain.Types as TG
import Duckling.Types import Duckling.Types
import qualified Duckling.TimeGrain.Types as TG
grains :: [(Text, String, TG.Grain)] grains :: [(Text, String, TG.Grain)]
grains = [ ("secunde (grain)", "sec(und(a|e|ă))?", TG.Second) grains = [ ("secunde (grain)", "sec(und(a|e|ă))?", TG.Second)