{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Quantity.FR.Rules
( rules
) where
import Data.String
import Prelude
import qualified Data.Text as Text
import Duckling.Dimensions.Types
import Duckling.Quantity.Helpers
import Duckling.Numeral.Types (NumeralData (..))
import Duckling.Regex.Types
import Duckling.Types
import qualified Duckling.Numeral.Types as TNumeral
import qualified Duckling.Quantity.Types as TQuantity
ruleNumeralUnits :: Rule
ruleNumeralUnits :: Rule
ruleNumeralUnits = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<number> <units>"
, pattern :: Pattern
pattern =
[ Dimension NumeralData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension NumeralData
Numeral
, String -> PatternItem
regex String
"(tasses?|cuill?(e|è)res? (a|à) soupe?)"
]
, prod :: Production
prod = \case
(Token Dimension a
Numeral NumeralData {TNumeral.value = v}:
Token Dimension a
RegexMatch (GroupMatch (match:_)):
[Token]
_) -> case Text -> Text
Text.toLower Text
match of
Text
"tasse" -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (QuantityData -> Token) -> QuantityData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension QuantityData -> QuantityData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension QuantityData
Quantity (QuantityData -> Maybe Token) -> QuantityData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Unit -> Double -> QuantityData
quantity Unit
TQuantity.Cup Double
v
Text
"tasses" -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (QuantityData -> Token) -> QuantityData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension QuantityData -> QuantityData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension QuantityData
Quantity (QuantityData -> Maybe Token) -> QuantityData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Unit -> Double -> QuantityData
quantity Unit
TQuantity.Cup Double
v
Text
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (QuantityData -> Token) -> QuantityData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension QuantityData -> QuantityData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension QuantityData
Quantity (QuantityData -> Maybe Token) -> QuantityData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Unit -> Double -> QuantityData
quantity Unit
TQuantity.Tablespoon Double
v
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleQuantityOfProduct :: Rule
ruleQuantityOfProduct :: Rule
ruleQuantityOfProduct = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<quantity> of product"
, pattern :: Pattern
pattern =
[ Dimension QuantityData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension QuantityData
Quantity
, String -> PatternItem
regex String
"de (caf(e|é)|sucre)"
]
, prod :: Production
prod = \case
(Token Dimension a
Quantity a
qd:
Token Dimension a
RegexMatch (GroupMatch (match:_)):
[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (QuantityData -> Token) -> QuantityData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension QuantityData -> QuantityData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension QuantityData
Quantity (QuantityData -> Maybe Token) -> QuantityData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Text -> QuantityData -> QuantityData
withProduct Text
match a
QuantityData
qd
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleNumeralUnits
, Rule
ruleQuantityOfProduct
]