|
| 1 | +-- Copyright (c) 2016-present, Facebook, Inc. |
| 2 | +-- All rights reserved. |
| 3 | +-- |
| 4 | +-- This source code is licensed under the BSD-style license found in the |
| 5 | +-- LICENSE file in the root directory of this source tree. An additional grant |
| 6 | +-- of patent rights can be found in the PATENTS file in the same directory. |
| 7 | + |
| 8 | + |
| 9 | +{-# LANGUAGE GADTs #-} |
| 10 | +{-# LANGUAGE OverloadedStrings #-} |
| 11 | + |
| 12 | +module Duckling.Volume.TR.Rules |
| 13 | + ( rules ) where |
| 14 | + |
| 15 | +import Data.String |
| 16 | +import Data.Text (Text) |
| 17 | +import Prelude |
| 18 | + |
| 19 | +import Duckling.Dimensions.Types |
| 20 | +import Duckling.Types |
| 21 | +import Duckling.Volume.Helpers |
| 22 | +import qualified Duckling.Volume.Types as TVolume |
| 23 | + |
| 24 | +ruleHalfLiter :: Rule |
| 25 | +ruleHalfLiter = Rule |
| 26 | + { name = "half liter" |
| 27 | + , pattern = [ regex "yar\305m l(t|itre)" ] |
| 28 | + , prod = \_ -> Just . Token Volume . withUnit TVolume.Litre $ volume 0.5 |
| 29 | + } |
| 30 | + |
| 31 | +volumes :: [(Text, String, TVolume.Unit)] |
| 32 | +volumes = [ ("<latent vol> ml" , "m(l|ililitre)" , TVolume.Millilitre) |
| 33 | + , ("<vol> hectoliters" , "hektolitre" , TVolume.Hectolitre) |
| 34 | + , ("<vol> liters" , "l(t|itre)" , TVolume.Litre) |
| 35 | + , ("<latent vol> gallon", "gal(l?on?)?" , TVolume.Gallon) |
| 36 | + ] |
| 37 | + |
| 38 | +ruleVolumes :: [Rule] |
| 39 | +ruleVolumes = map go volumes |
| 40 | + where |
| 41 | + go :: (Text, String, TVolume.Unit) -> Rule |
| 42 | + go (name, regexPattern, u) = Rule |
| 43 | + { name = name |
| 44 | + , pattern = [ dimension Volume, regex regexPattern ] |
| 45 | + , prod = \tokens -> case tokens of |
| 46 | + (Token Volume vd:_) -> Just . Token Volume $ withUnit u vd |
| 47 | + _ -> Nothing |
| 48 | + } |
| 49 | + |
| 50 | +rules :: [Rule] |
| 51 | +rules = ruleHalfLiter:ruleVolumes |
0 commit comments