mirror of
https://github.com/facebook/duckling.git
synced 2024-11-24 15:43:20 +03:00
16708d9572
Summary: Minor Volume.FR improvement: add "Centilitre" type. This is useful for recipe parsing. Pull Request resolved: https://github.com/facebook/duckling/pull/354 Reviewed By: patapizza Differential Revision: D26193246 Pulled By: chessai fbshipit-source-id: ddd551e062b8efeff1e786e30e35815c0c29a34c
76 lines
2.0 KiB
Haskell
76 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.
|
|
|
|
|
|
{-# LANGUAGE GADTs #-}
|
|
{-# LANGUAGE LambdaCase #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Duckling.Volume.FR.Rules
|
|
( rules ) where
|
|
|
|
import Data.String
|
|
import Data.Text (Text)
|
|
import Prelude
|
|
|
|
import Duckling.Dimensions.Types
|
|
import Duckling.Types
|
|
import Duckling.Regex.Types
|
|
import Duckling.Volume.Helpers
|
|
import Duckling.Numeral.Helpers (isPositive)
|
|
import qualified Duckling.Volume.Types as TVolume
|
|
import qualified Duckling.Numeral.Types as TNumeral
|
|
|
|
volumes :: [(Text, String, TVolume.Unit)]
|
|
volumes = [ ("<latent vol> ml" , "m(l|illilitres?)" , TVolume.Millilitre)
|
|
, ("<latent vol> cl" , "c(l|entilitres?)" , TVolume.Centilitre)
|
|
, ("<vol> hectoliters" , "(hectolitres?)" , TVolume.Hectolitre)
|
|
, ("<vol> liters" , "l(itres?)?" , TVolume.Litre)
|
|
, ("<latent vol> gallon", "gal(l?ons?)?" , TVolume.Gallon)
|
|
]
|
|
|
|
rulesVolumes :: [Rule]
|
|
rulesVolumes = map go volumes
|
|
where
|
|
go :: (Text, String, TVolume.Unit) -> Rule
|
|
go (name, regexPattern, u) = Rule
|
|
{ name = name
|
|
, pattern =
|
|
[ regex regexPattern
|
|
]
|
|
, prod = \_ -> Just . Token Volume $ unitOnly u
|
|
}
|
|
|
|
fractions :: [(Text, String, Double)]
|
|
fractions = [ ("quart", "quart de", 1/4)
|
|
, ("half", "demi-?", 1/2)
|
|
]
|
|
|
|
rulesFractionalVolume :: [Rule]
|
|
rulesFractionalVolume = map go fractions
|
|
where
|
|
go :: (Text, String, Double) -> Rule
|
|
go (name, regexPattern, f) = Rule
|
|
{ name = name
|
|
, pattern =
|
|
[ regex regexPattern
|
|
, Predicate isUnitOnly
|
|
]
|
|
, prod = \case
|
|
(_:
|
|
Token Volume TVolume.VolumeData{TVolume.unit = Just u}:
|
|
_) ->
|
|
Just . Token Volume $ volume u f
|
|
_ -> Nothing
|
|
}
|
|
|
|
rules :: [Rule]
|
|
rules =
|
|
[
|
|
]
|
|
++ rulesVolumes
|
|
++ rulesFractionalVolume
|