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)
[ "trei sferturi de oră"
, "45min"
, "45 de minute"
]
, examples (DurationData 12 Week)
[ "doișpe saptamanile"

View File

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

View File

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