{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.AmountOfMoney.SV.Rules
( rules
) where
import Data.Maybe
import Data.String
import Prelude
import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..), AmountOfMoneyData (..))
import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (isNatural, isPositive)
import Duckling.Numeral.Types (NumeralData (..))
import Duckling.Types
import qualified Duckling.AmountOfMoney.Types as TAmountOfMoney
import qualified Duckling.Numeral.Types as TNumeral
ruleUnitAmount :: Rule
ruleUnitAmount :: Rule
ruleUnitAmount = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<unit> <amount>"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isCurrencyOnly
, Predicate -> PatternItem
Predicate Predicate
isPositive
]
, prod :: Production
prod = \case
(Token Dimension a
AmountOfMoney AmountOfMoneyData{TAmountOfMoney.currency = c}:
Token Dimension a
Numeral NumeralData{TNumeral.value = v}:
[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (AmountOfMoneyData -> Token) -> AmountOfMoneyData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension AmountOfMoneyData -> AmountOfMoneyData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension AmountOfMoneyData
AmountOfMoney (AmountOfMoneyData -> Token)
-> (AmountOfMoneyData -> AmountOfMoneyData)
-> AmountOfMoneyData
-> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> AmountOfMoneyData -> AmountOfMoneyData
withValue Double
v (AmountOfMoneyData -> Maybe Token)
-> AmountOfMoneyData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Currency -> AmountOfMoneyData
currencyOnly Currency
c
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleIntersectAndNumeral :: Rule
ruleIntersectAndNumeral :: Rule
ruleIntersectAndNumeral = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"intersect (and number)"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isWithoutCents
, String -> PatternItem
regex String
"och"
, Predicate -> PatternItem
Predicate Predicate
isNatural
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
AmountOfMoney a
fd:
Token
_:
Token Dimension a
Numeral NumeralData{TNumeral.value = c}:
[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (AmountOfMoneyData -> Token) -> AmountOfMoneyData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension AmountOfMoneyData -> AmountOfMoneyData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension AmountOfMoneyData
AmountOfMoney (AmountOfMoneyData -> Maybe Token)
-> AmountOfMoneyData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Double -> AmountOfMoneyData -> AmountOfMoneyData
withCents Double
c a
AmountOfMoneyData
fd
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleAboutAmountofmoney :: Rule
ruleAboutAmountofmoney :: Rule
ruleAboutAmountofmoney = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"about <amount-of-money>"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"omkring|cirka|runt|ca"
, Predicate -> PatternItem
Predicate Predicate
isMoneyWithValue
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token
_:Token
token:[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just Token
token
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleCent :: Rule
ruleCent :: Rule
ruleCent = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"cent"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"cents?|penn(y|ies)|öre"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (AmountOfMoneyData -> Token) -> AmountOfMoneyData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension AmountOfMoneyData -> AmountOfMoneyData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension AmountOfMoneyData
AmountOfMoney (AmountOfMoneyData -> Maybe Token)
-> AmountOfMoneyData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Currency -> AmountOfMoneyData
currencyOnly Currency
Cent
}
ruleExactlyAmountofmoney :: Rule
ruleExactlyAmountofmoney :: Rule
ruleExactlyAmountofmoney = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"exactly <amount-of-money>"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"exakt|precis"
, Predicate -> PatternItem
Predicate Predicate
isMoneyWithValue
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token
_:Token
token:[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just Token
token
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleIntersectXCents :: Rule
ruleIntersectXCents :: Rule
ruleIntersectXCents = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"intersect (X cents)"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isWithoutCents
, Predicate -> PatternItem
Predicate Predicate
isCents
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
AmountOfMoney a
fd:
Token Dimension a
AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just c}:
[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (AmountOfMoneyData -> Token) -> AmountOfMoneyData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension AmountOfMoneyData -> AmountOfMoneyData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension AmountOfMoneyData
AmountOfMoney (AmountOfMoneyData -> Maybe Token)
-> AmountOfMoneyData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Double -> AmountOfMoneyData -> AmountOfMoneyData
withCents Double
c a
AmountOfMoneyData
fd
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleNok :: Rule
ruleNok :: Rule
ruleNok = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"NOK"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"norska kronor|nkr"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (AmountOfMoneyData -> Token) -> AmountOfMoneyData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension AmountOfMoneyData -> AmountOfMoneyData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension AmountOfMoneyData
AmountOfMoney (AmountOfMoneyData -> Maybe Token)
-> AmountOfMoneyData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Currency -> AmountOfMoneyData
currencyOnly Currency
NOK
}
rulePounds :: Rule
rulePounds :: Rule
rulePounds = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"£"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"pund?"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (AmountOfMoneyData -> Token) -> AmountOfMoneyData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension AmountOfMoneyData -> AmountOfMoneyData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension AmountOfMoneyData
AmountOfMoney (AmountOfMoneyData -> Maybe Token)
-> AmountOfMoneyData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Currency -> AmountOfMoneyData
currencyOnly Currency
Pound
}
ruleIntersectAndXCents :: Rule
ruleIntersectAndXCents :: Rule
ruleIntersectAndXCents = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"intersect (and X cents)"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isWithoutCents
, String -> PatternItem
regex String
"och"
, Predicate -> PatternItem
Predicate Predicate
isCents
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
AmountOfMoney a
fd:
Token
_:
Token Dimension a
AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just c}:
[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (AmountOfMoneyData -> Token) -> AmountOfMoneyData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension AmountOfMoneyData -> AmountOfMoneyData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension AmountOfMoneyData
AmountOfMoney (AmountOfMoneyData -> Maybe Token)
-> AmountOfMoneyData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Double -> AmountOfMoneyData -> AmountOfMoneyData
withCents Double
c a
AmountOfMoneyData
fd
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleIntersect :: Rule
ruleIntersect :: Rule
ruleIntersect = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"intersect"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isWithoutCents
, Predicate -> PatternItem
Predicate Predicate
isNatural
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
AmountOfMoney a
fd:
Token Dimension a
Numeral NumeralData{TNumeral.value = c}:
[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (AmountOfMoneyData -> Token) -> AmountOfMoneyData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension AmountOfMoneyData -> AmountOfMoneyData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension AmountOfMoneyData
AmountOfMoney (AmountOfMoneyData -> Maybe Token)
-> AmountOfMoneyData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Double -> AmountOfMoneyData -> AmountOfMoneyData
withCents Double
c a
AmountOfMoneyData
fd
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleSek :: Rule
ruleSek :: Rule
ruleSek = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"SEK"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"kr(onor)?"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (AmountOfMoneyData -> Token) -> AmountOfMoneyData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension AmountOfMoneyData -> AmountOfMoneyData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension AmountOfMoneyData
AmountOfMoney (AmountOfMoneyData -> Maybe Token)
-> AmountOfMoneyData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Currency -> AmountOfMoneyData
currencyOnly Currency
SEK
}
ruleDirham :: Rule
ruleDirham :: Rule
ruleDirham = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"AED"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"dirhams?"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (AmountOfMoneyData -> Token) -> AmountOfMoneyData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension AmountOfMoneyData -> AmountOfMoneyData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension AmountOfMoneyData
AmountOfMoney (AmountOfMoneyData -> Maybe Token)
-> AmountOfMoneyData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Currency -> AmountOfMoneyData
currencyOnly Currency
AED
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleUnitAmount
, Rule
ruleAboutAmountofmoney
, Rule
ruleCent
, Rule
ruleDirham
, Rule
ruleExactlyAmountofmoney
, Rule
ruleIntersect
, Rule
ruleIntersectAndNumeral
, Rule
ruleIntersectAndXCents
, Rule
ruleIntersectXCents
, Rule
ruleNok
, Rule
rulePounds
, Rule
ruleSek
]