{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.AmountOfMoney.AR.Rules
( rules
) where
import Data.Maybe
import Data.String
import Prelude
import qualified Data.Text as Text
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.Regex.Types
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
}
rulePounds :: Rule
rulePounds :: Rule
rulePounds = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"£"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"جنيه(ات)?"
]
, 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
}
ruleEgpAbrreviation :: Rule
ruleEgpAbrreviation :: Rule
ruleEgpAbrreviation = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"EGP abbreviation"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"ج[.]م[.]?"
]
, 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
EGP
}
ruleDinars :: Rule
ruleDinars :: Rule
ruleDinars = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"dinars"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"دينار|دنانير"
]
, 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
Dinar
}
ruleDirhams :: Rule
ruleDirhams :: Rule
ruleDirhams = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"Dirhams"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"درا?هم"
]
, 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
Dirham
}
ruleRiyals :: Rule
ruleRiyals :: Rule
ruleRiyals = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"Riyals"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"ريال(ات)?"
]
, 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
Riyal
}
ruleDollars :: Rule
ruleDollars :: Rule
ruleDollars = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"Dollars"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"دولار(ات)?"
]
, 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
Dollar
}
ruleShekel :: Rule
ruleShekel :: Rule
ruleShekel = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"Shekel"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"شي[كق]ل|شوا[كق]ل"
]
, 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
ILS
}
ruleEuro :: Rule
ruleEuro :: Rule
ruleEuro = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"Euro"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"[أاي]ورو"
]
, 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
EUR
}
ruleOtherPounds :: Rule
ruleOtherPounds :: Rule
ruleOtherPounds = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"other pounds"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"جنيه(ات)? (مصر|استرلين)ي?[ةه]?"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (_:match:_)):
[Token]
_) -> case Text -> Text
Text.toLower Text
match of
Text
"مصر" -> 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
EGP
Text
"استرلين" -> 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
GBP
Text
_ -> Maybe Token
forall a. Maybe a
Nothing
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleOtherDinars :: Rule
ruleOtherDinars :: Rule
ruleOtherDinars = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"dinars"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(دينار|دنانير) ([أا]ردن|كويت|عراق)ي?[ةه]?"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (_:match:_)):
[Token]
_) -> case Text -> Text
Text.toLower Text
match of
Text
"كويت" -> 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
KWD
Text
"اردن" -> 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
JOD
Text
"أردن" -> 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
JOD
Text
"عراق" -> 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
IQD
Text
_ -> Maybe Token
forall a. Maybe a
Nothing
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleOtherDirhams :: Rule
ruleOtherDirhams :: Rule
ruleOtherDirhams = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"dirham"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(درهم|دراهم) (اردن|أردن|مغرب)ي?[ةه]?"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (_:match:_)):
[Token]
_) -> case Text -> Text
Text.toLower Text
match of
Text
"إمارات" -> 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
Text
"امارات" -> 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
Text
"مغرب" -> 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
MAD
Text
_ -> Maybe Token
forall a. Maybe a
Nothing
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleOtherRiyals :: Rule
ruleOtherRiyals :: Rule
ruleOtherRiyals = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"riyals"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(ريال|ريالات) (سعود|قطر)ي?[ةه]?"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (_:match:_)):
[Token]
_) -> case Text -> Text
Text.toLower Text
match of
Text
"قطر" -> 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
QAR
Text
"سعود" -> 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
SAR
Text
_ -> Maybe Token
forall a. Maybe a
Nothing
[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
"سي?نت(ات)?"
]
, 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
}
ruleLBP :: Rule
ruleLBP :: Rule
ruleLBP = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"LBP"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"لير([ةه]|ات) لبناني[ةه]?"
]
, 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
LBP
}
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
"و"
, 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
}
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
"و"
, 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
}
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
}
rulePrecision :: Rule
rulePrecision :: Rule
rulePrecision = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"about|exactly <amount-of-money>"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"حوال[ي|ى]|تقريبا|بحدود"
, 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
}
ruleIntervalBetweenNumeral :: Rule
ruleIntervalBetweenNumeral :: Rule
ruleIntervalBetweenNumeral = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"between|from <numeral> to|and <amount-of-money>"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(من|(ما )?بين)( ال)?"
, Predicate -> PatternItem
Predicate Predicate
isPositive
, String -> PatternItem
regex String
"(الى|حتى|و|ل)( ا?ل)?"
, Predicate -> PatternItem
Predicate Predicate
isSimpleAmountOfMoney
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token
_:
Token Dimension a
Numeral NumeralData {TNumeral.value = from}:
Token
_:
Token Dimension a
AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just to, TAmountOfMoney.currency = c}:
[Token]
_) | Double
from Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< Double
to ->
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, Double) -> AmountOfMoneyData -> AmountOfMoneyData
withInterval (Double
from, Double
to) (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
}
ruleIntervalBetween :: Rule
ruleIntervalBetween :: Rule
ruleIntervalBetween = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"between|from <amount-of-money> to|and <amount-of-money>"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(من|(ما )?بين)( ال)?"
, Predicate -> PatternItem
Predicate Predicate
isSimpleAmountOfMoney
, String -> PatternItem
regex String
"(الى|حتى|و|ل)( ا?ل)?"
, Predicate -> PatternItem
Predicate Predicate
isSimpleAmountOfMoney
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token
_:
Token Dimension a
AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just from, TAmountOfMoney.currency = c1}:
Token
_:
Token Dimension a
AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just to, TAmountOfMoney.currency = c2}:
[Token]
_) | Double
from Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< Double
to Bool -> Bool -> Bool
&& Currency
c1 Currency -> Currency -> Bool
forall a. Eq a => a -> a -> Bool
== Currency
c2 ->
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, Double) -> AmountOfMoneyData -> AmountOfMoneyData
withInterval (Double
from, Double
to) (AmountOfMoneyData -> Maybe Token)
-> AmountOfMoneyData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Currency -> AmountOfMoneyData
currencyOnly Currency
c1
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleIntervalNumeralDash :: Rule
ruleIntervalNumeralDash :: Rule
ruleIntervalNumeralDash = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<numeral> - <amount-of-money>"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isPositive
, String -> PatternItem
regex String
"-"
, Predicate -> PatternItem
Predicate Predicate
isSimpleAmountOfMoney
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Numeral NumeralData {TNumeral.value = from}:
Token
_:
Token Dimension a
AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just to, TAmountOfMoney.currency = c}:
[Token]
_) | Double
from Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< Double
to ->
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, Double) -> AmountOfMoneyData -> AmountOfMoneyData
withInterval (Double
from, Double
to) (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
}
ruleIntervalDash :: Rule
ruleIntervalDash :: Rule
ruleIntervalDash = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<amount-of-money> - <amount-of-money>"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isSimpleAmountOfMoney
, String -> PatternItem
regex String
"-"
, Predicate -> PatternItem
Predicate Predicate
isSimpleAmountOfMoney
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just from, TAmountOfMoney.currency = c1}:
Token
_:
Token Dimension a
AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just to, TAmountOfMoney.currency = c2}:
[Token]
_) | Double
from Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< Double
to Bool -> Bool -> Bool
&& Currency
c1 Currency -> Currency -> Bool
forall a. Eq a => a -> a -> Bool
== Currency
c2 ->
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, Double) -> AmountOfMoneyData -> AmountOfMoneyData
withInterval (Double
from, Double
to) (AmountOfMoneyData -> Maybe Token)
-> AmountOfMoneyData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Currency -> AmountOfMoneyData
currencyOnly Currency
c1
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleIntervalMax :: Rule
ruleIntervalMax :: Rule
ruleIntervalMax = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"under/less/lower/no more than <amount-of-money>"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(حتى|[أا]قل من|تحت|(ما )?دون)|على ال[أا]كثر"
, Predicate -> PatternItem
Predicate Predicate
isSimpleAmountOfMoney
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token
_:
Token Dimension a
AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just to, TAmountOfMoney.currency = 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 -> Token)
-> (AmountOfMoneyData -> AmountOfMoneyData)
-> AmountOfMoneyData
-> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> AmountOfMoneyData -> AmountOfMoneyData
withMax Double
to (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
}
ruleIntervalAtMost :: Rule
ruleIntervalAtMost :: Rule
ruleIntervalAtMost = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"under/less/lower/no more than <amount-of-money>"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"على ال[أا]كثر"
, Predicate -> PatternItem
Predicate Predicate
isSimpleAmountOfMoney
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token
_:
Token Dimension a
AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just to, TAmountOfMoney.currency = 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 -> Token)
-> (AmountOfMoneyData -> AmountOfMoneyData)
-> AmountOfMoneyData
-> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> AmountOfMoneyData -> AmountOfMoneyData
withMax Double
to (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
}
ruleIntervalMin :: Rule
ruleIntervalMin :: Rule
ruleIntervalMin = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"at least/over/above/more than <amount-of-money>"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"فوق||[أا]كثر من|على ال[اأ]قل"
, Predicate -> PatternItem
Predicate Predicate
isSimpleAmountOfMoney
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token
_:
Token Dimension a
AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just to, TAmountOfMoney.currency = 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 -> Token)
-> (AmountOfMoneyData -> AmountOfMoneyData)
-> AmountOfMoneyData
-> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> AmountOfMoneyData -> AmountOfMoneyData
withMin Double
to (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
}
ruleIntervalAtLeast :: Rule
ruleIntervalAtLeast :: Rule
ruleIntervalAtLeast = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<amount-of-money> at least"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isSimpleAmountOfMoney
, String -> PatternItem
regex String
"على ال[اأ]قل"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just to, TAmountOfMoney.currency = 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 -> Token)
-> (AmountOfMoneyData -> AmountOfMoneyData)
-> AmountOfMoneyData
-> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> AmountOfMoneyData -> AmountOfMoneyData
withMin Double
to (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
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleUnitAmount
, Rule
ruleCent
, Rule
rulePounds
, Rule
ruleEgpAbrreviation
, Rule
ruleDinars
, Rule
ruleDirhams
, Rule
ruleRiyals
, Rule
ruleDollars
, Rule
ruleShekel
, Rule
ruleEuro
, Rule
ruleOtherPounds
, Rule
ruleOtherDinars
, Rule
ruleOtherDirhams
, Rule
ruleOtherRiyals
, Rule
ruleLBP
, Rule
ruleIntersect
, Rule
ruleIntersectAndNumeral
, Rule
ruleIntersectAndXCents
, Rule
ruleIntersectXCents
, Rule
ruleIntervalBetweenNumeral
, Rule
ruleIntervalBetween
, Rule
ruleIntervalMax
, Rule
ruleIntervalAtMost
, Rule
ruleIntervalMin
, Rule
ruleIntervalAtLeast
, Rule
ruleIntervalNumeralDash
, Rule
ruleIntervalDash
, Rule
rulePrecision
]