module Duckling.Volume.EN.Rules
( rules ) where
import Data.Text (Text)
import Prelude
import Data.String
import Duckling.Dimensions.Types
import Duckling.Types
import Duckling.Volume.Helpers
import qualified Duckling.Volume.Types as TVolume
ruleHalfLiter :: Rule
ruleHalfLiter = Rule
{ name = "half liter"
, pattern = [ regex "half lit(er|re)" ]
, prod = \_ -> Just . Token Volume . withUnit TVolume.Litre $ volume 0.5
}
volumes :: [(Text, String, TVolume.Unit)]
volumes = [ ("<latent vol> ml" , "m(l|illilit(er|re)s?)", TVolume.Millilitre)
, ("<vol> hectoliters" , "hectolit(er|re)s?" , TVolume.Hectolitre)
, ("<vol> liters" , "l(it(er|re)s?)?" , TVolume.Litre)
, ("<latent vol> gallon", "gal(l?ons?)?" , TVolume.Gallon)
]
ruleVolumes :: [Rule]
ruleVolumes = map go volumes
where
go :: (Text, String, TVolume.Unit) -> Rule
go (name, regexPattern, u) = Rule
{ name = name
, pattern = [ dimension Volume, regex regexPattern ]
, prod = \tokens -> case tokens of
(Token Volume vd:_) -> Just . Token Volume $ withUnit u vd
_ -> Nothing
}
rules :: [Rule]
rules = ruleHalfLiter:ruleVolumes