{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.AmountOfMoney.HR.Rules
( rules
) where
import Data.Maybe
import Data.String
import Data.Text (Text)
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
ruleACurrency :: Rule
ruleACurrency :: Rule
ruleACurrency = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"a <currency>"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"jed(an|na|no)"
, Predicate -> PatternItem
Predicate Predicate
isCurrencyOnly
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token
_:
Token Dimension a
AmountOfMoney AmountOfMoneyData{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 -> Maybe Token)
-> AmountOfMoneyData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Double -> AmountOfMoneyData -> AmountOfMoneyData
withValue Double
1 (AmountOfMoneyData -> AmountOfMoneyData)
-> AmountOfMoneyData -> AmountOfMoneyData
forall a b. (a -> b) -> a -> b
$ Currency -> AmountOfMoneyData
currencyOnly Currency
c
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
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
}
ruleIntersectAndNumber :: Rule
ruleIntersectAndNumber :: Rule
ruleIntersectAndNumber = 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
"i"
, 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
}
ruleSar :: Rule
ruleSar :: Rule
ruleSar = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"SAR"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"saudijskirijal|saudi rijal?"
]
, 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
SAR
}
ruleDollar :: Rule
ruleDollar :: Rule
ruleDollar = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"$"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"dolar(a|i|e)?"
]
, 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
}
ruleCent :: Rule
ruleCent :: Rule
ruleCent = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"cent"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"cent(i|a)?|penij(i|a)?|c|¢|lp|lip(a|e)"
]
, 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
}
ruleIntersectIXLipa :: Rule
ruleIntersectIXLipa :: Rule
ruleIntersectIXLipa = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"intersect (i X lipa)"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isWithoutCents
, String -> PatternItem
regex String
"i"
, 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
}
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
}
rulePound :: Rule
rulePound :: Rule
rulePound = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"£"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"funt(a|e|i)?"
]
, 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
}
ruleHrk :: Rule
ruleHrk :: Rule
ruleHrk = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"HRK"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"kn|(hrvatsk(a|ih|e) )?kun(a|e)"
]
, 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
HRK
}
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
}
ruleOtherPounds :: Rule
ruleOtherPounds :: Rule
ruleOtherPounds = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"other pounds"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(egipatska|libanonska) ?funta"
]
, 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
"egipatska" -> 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
"libanonska" -> 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
Text
_ -> Maybe Token
forall a. Maybe a
Nothing
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleInr :: Rule
ruleInr :: Rule
ruleInr = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"INR"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"rupija?"
]
, 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
INR
}
ruleKwd :: Rule
ruleKwd :: Rule
ruleKwd = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"KWD"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"kuvajtski ?dinar"
]
, 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
KWD
}
ruleQar :: Rule
ruleQar :: Rule
ruleQar = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"QAR"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"katarski(i| )rijal"
]
, 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
QAR
}
ruleAed :: Rule
ruleAed :: Rule
ruleAed = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"AED"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"drahma?"
]
, 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
}
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
"oko|otprilike|u blizini|skoro|približno"
, 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
}
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
isNatural
, 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
}
ruleIntervalBetweenNumeral1 :: Rule
ruleIntervalBetweenNumeral1 :: Rule
ruleIntervalBetweenNumeral1 = 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
"od|otprilike|približno"
, Predicate -> PatternItem
Predicate Predicate
isPositive
, String -> PatternItem
regex String
"do"
, 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
}
ruleIntervalBetweenNumeral2 :: Rule
ruleIntervalBetweenNumeral2 :: Rule
ruleIntervalBetweenNumeral2 = 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
"izmedju"
, Predicate -> PatternItem
Predicate Predicate
isPositive
, String -> PatternItem
regex String
"i"
, 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
}
ruleIntervalBetween1 :: Rule
ruleIntervalBetween1 :: Rule
ruleIntervalBetween1 = 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
"od|otprilike"
, Predicate -> PatternItem
Predicate Predicate
isSimpleAmountOfMoney
, String -> PatternItem
regex String
"do"
, 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
}
ruleIntervalBetween2 :: Rule
ruleIntervalBetween2 :: Rule
ruleIntervalBetween2 = 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
"izmedju"
, Predicate -> PatternItem
Predicate Predicate
isSimpleAmountOfMoney
, String -> PatternItem
regex String
"i"
, 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
}
ruleIntervalMin :: Rule
ruleIntervalMin :: Rule
ruleIntervalMin = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"over/above/at least/more than <amount-of-money>"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"više od|najmanje|preko|iznad"
, 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
}
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
"ispod|manje od"
, 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
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleACurrency
, Rule
ruleUnitAmount
, Rule
ruleDollar
, Rule
rulePound
, Rule
ruleOtherPounds
, Rule
ruleAed
, Rule
ruleCent
, Rule
ruleHrk
, Rule
ruleInr
, Rule
ruleIntersect
, Rule
ruleIntersectAndNumber
, Rule
ruleIntersectIXLipa
, Rule
ruleIntersectXCents
, Rule
ruleKwd
, Rule
ruleQar
, Rule
ruleSar
, Rule
rulePrecision
, Rule
ruleIntervalNumeralDash
, Rule
ruleIntervalDash
, Rule
ruleIntervalBetweenNumeral1
, Rule
ruleIntervalBetweenNumeral2
, Rule
ruleIntervalBetween1
, Rule
ruleIntervalBetween2
, Rule
ruleIntervalMin
, Rule
ruleIntervalMax
]