duckling/Duckling/Volume/IT/Rules.hs
Matteo e11014dc4b Volume for IT lang
Summary:
I notice that there are several missing dimensions for the IT language: this patch is for the Volume dimension

Regards
Matteo
Closes https://github.com/facebookincubator/duckling/pull/4

Reviewed By: JonCoens

Differential Revision: D4986389

Pulled By: patapizza

fbshipit-source-id: 314d33e
2017-05-02 11:19:14 -07:00

90 lines
2.0 KiB
Haskell

-- Copyright (c) 2016-present, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the BSD-style license found in the
-- LICENSE file in the root directory of this source tree. An additional grant
-- of patent rights can be found in the PATENTS file in the same directory.
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Volume.IT.Rules
( rules ) where
import Prelude
import Data.String
import Duckling.Dimensions.Types
import Duckling.Types
import Duckling.Volume.Helpers
import qualified Duckling.Volume.Types as TVolume
ruleLatentVolMl :: Rule
ruleLatentVolMl = Rule
{ name = "<latent vol> ml"
, pattern =
[ dimension Volume
, regex "m(l|illilitr(i|o))"
]
, prod = \tokens -> case tokens of
(Token Volume vd:_) ->
Just . Token Volume $ withUnit TVolume.Millilitre vd
_ -> Nothing
}
ruleVolHectoliters :: Rule
ruleVolHectoliters = Rule
{ name = "<vol> hectoliters"
, pattern =
[ dimension Volume
, regex "ettolitr(i|o)"
]
, prod = \tokens -> case tokens of
(Token Volume vd:_) ->
Just . Token Volume $ withUnit TVolume.Hectolitre vd
_ -> Nothing
}
ruleVolLiters :: Rule
ruleVolLiters = Rule
{ name = "<vol> liters"
, pattern =
[ dimension Volume
, regex "l(itr(i|o))?"
]
, prod = \tokens -> case tokens of
(Token Volume vd:_) -> Just . Token Volume $ withUnit TVolume.Litre vd
_ -> Nothing
}
ruleHalfLiter :: Rule
ruleHalfLiter = Rule
{ name = "half liter"
, pattern =
[ regex "mezzo litro"
]
, prod = \_ -> Just . Token Volume . withUnit TVolume.Litre $ volume 0.5
}
ruleLatentVolGallon :: Rule
ruleLatentVolGallon = Rule
{ name = "<latent vol> gallon"
, pattern =
[ dimension Volume
, regex "gal(lon(e|i))?"
]
, prod = \tokens -> case tokens of
(Token Volume vd:_) -> Just . Token Volume $ withUnit TVolume.Gallon vd
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleHalfLiter
, ruleLatentVolGallon
, ruleLatentVolMl
, ruleVolHectoliters
, ruleVolLiters
]