{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoRebindableSyntax #-}
module Duckling.Numeral.AR.EG.Rules (rules) where
import Data.Maybe
import Prelude
import qualified Data.HashMap.Strict as HashMap
import Duckling.Dimensions.Types
import Duckling.Numeral.AR.EG.Helpers
( digitsMap
, parseArabicDoubleFromText
, parseArabicIntegerFromText
)
import Duckling.Numeral.Helpers
import Duckling.Numeral.Types (NumeralData (..))
import Duckling.Regex.Types
import Duckling.Types
import qualified Duckling.Numeral.Types as TNumeral
ruleInteger2 :: Rule
ruleInteger2 :: Rule
ruleInteger2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 2"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"[إأا]?تني[ي]?ن"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
2
}
ruleInteger3 :: Rule
ruleInteger3 :: Rule
ruleInteger3 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 3"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"تلات[هة]?"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
3
}
ruleInteger8 :: Rule
ruleInteger8 :: Rule
ruleInteger8 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 8"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"تمان(ي[هة])?"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
8
}
ruleInteger11 :: Rule
ruleInteger11 :: Rule
ruleInteger11 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 11"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(إأا)?حداشر"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
11
}
ruleInteger12 :: Rule
ruleInteger12 :: Rule
ruleInteger12 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 12"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"[إأا]?[تط]ناشر"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
12
}
ruleInteger13 :: Rule
ruleInteger13 :: Rule
ruleInteger13 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 13"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"[تط]ل(ا)?[تط]اشر"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
13
}
ruleInteger14 :: Rule
ruleInteger14 :: Rule
ruleInteger14 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 14"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"[إأا]ربع[تط]اشر"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
14
}
ruleInteger15 :: Rule
ruleInteger15 :: Rule
ruleInteger15 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 15"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"خمس[تط]اشر"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
15
}
ruleInteger16 :: Rule
ruleInteger16 :: Rule
ruleInteger16 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 16"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"س[تط]اشر"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
16
}
ruleInteger17 :: Rule
ruleInteger17 :: Rule
ruleInteger17 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 17"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"سبع[تط]اشر"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
17
}
ruleInteger18 :: Rule
ruleInteger18 :: Rule
ruleInteger18 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 18"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"[تط]من[تط]اشر"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
18
}
ruleInteger19 :: Rule
ruleInteger19 :: Rule
ruleInteger19 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 19"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"تسع[تط]اشر"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
19
}
ruleInteger30_80 :: Rule
ruleInteger30_80 :: Rule
ruleInteger30_80 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (30, 80)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"([تط]لا[تط]|[تط]مان)(ين)"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_ ->
(Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
10) (Integer -> Integer) -> Maybe Integer -> Maybe Integer
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> HashMap Text Integer -> Maybe Integer
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup Text
match HashMap Text Integer
digitsMap Maybe Integer -> (Integer -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Integer -> Maybe Token
integer
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleInteger100 :: Rule
ruleInteger100 :: Rule
ruleInteger100 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (100)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"مي[هةت]"
]
, prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ Integer -> Maybe Token
integer Integer
100
}
ruleInteger200 :: Rule
ruleInteger200 :: Rule
ruleInteger200 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (200)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"م(ي)?تين"
]
, prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ Integer -> Maybe Token
integer Integer
200
}
ruleInteger300 :: Rule
ruleInteger300 :: Rule
ruleInteger300 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (300)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"([تط]و?لا?[تط]و?)مي[هةت]"
]
, prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ Integer -> Maybe Token
integer Integer
300
}
ruleInteger400 :: Rule
ruleInteger400 :: Rule
ruleInteger400 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (400)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(رو?بعو?)مي[هةت]"
]
, prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ Integer -> Maybe Token
integer Integer
400
}
ruleInteger500 :: Rule
ruleInteger500 :: Rule
ruleInteger500 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (500)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(خو?مسو?)مي[هةت]"
]
, prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ Integer -> Maybe Token
integer Integer
500
}
ruleInteger600 :: Rule
ruleInteger600 :: Rule
ruleInteger600 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (600)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(سو?تو?)مي[هةت]"
]
, prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ Integer -> Maybe Token
integer Integer
600
}
ruleInteger700 :: Rule
ruleInteger700 :: Rule
ruleInteger700 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (700)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(سو?بعو?)مي[هةت]"
]
, prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ Integer -> Maybe Token
integer Integer
700
}
ruleInteger800 :: Rule
ruleInteger800 :: Rule
ruleInteger800 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (800)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"([تط]و?منو?)مي[هةت]"
]
, prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ Integer -> Maybe Token
integer Integer
800
}
ruleInteger900 :: Rule
ruleInteger900 :: Rule
ruleInteger900 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (900)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"([تط]و?سعو?)مي[هةت]"
]
, prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ Integer -> Maybe Token
integer Integer
900
}
ruleInteger101_999 :: Rule
ruleInteger101_999 :: Rule
ruleInteger101_999 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 101..999"
, pattern :: Pattern
pattern =
[ [Double] -> PatternItem
oneOf [Double
100, Double
200 .. Double
900]
, String -> PatternItem
regex String
"\\s"
, [Double] -> PatternItem
oneOf ([Double] -> PatternItem) -> [Double] -> PatternItem
forall a b. (a -> b) -> a -> b
$ (Double -> Double -> Double) -> [Double] -> [Double -> Double]
forall a b. (a -> b) -> [a] -> [b]
map Double -> Double -> Double
forall a. Num a => a -> a -> a
(+) [Double
10, Double
20 .. Double
90] [Double -> Double] -> [Double] -> [Double]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Double
1..Double
9]
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Numeral NumeralData{TNumeral.value = v1}:
Token
_:
Token Dimension a
Numeral NumeralData{TNumeral.value = v2}:
[Token]
_) -> Double -> Maybe Token
double (Double -> Maybe Token) -> Double -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Double
v1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
v2
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleInteger3000 :: Rule
ruleInteger3000 :: Rule
ruleInteger3000 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (3000)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"([تط]لا?[تط])( ?[اآ])?لاف"
]
, prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ Integer -> Maybe Token
integer Integer
3000
}
ruleInteger4000 :: Rule
ruleInteger4000 :: Rule
ruleInteger4000 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (4000)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"[أا]ربع(ت| ?[اآ])لاف"
]
, prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ Integer -> Maybe Token
integer Integer
4000
}
ruleInteger5000 :: Rule
ruleInteger5000 :: Rule
ruleInteger5000 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (5000)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"خمس(ت| ?[اآ])لاف"
]
, prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ Integer -> Maybe Token
integer Integer
5000
}
ruleInteger6000 :: Rule
ruleInteger6000 :: Rule
ruleInteger6000 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (6000)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"س(ت| ?[اآ])لاف"
]
, prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ Integer -> Maybe Token
integer Integer
6000
}
ruleInteger7000 :: Rule
ruleInteger7000 :: Rule
ruleInteger7000 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (7000)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"سبع(ت| ?[اآ])لاف"
]
, prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ Integer -> Maybe Token
integer Integer
7000
}
ruleInteger8000 :: Rule
ruleInteger8000 :: Rule
ruleInteger8000 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (8000)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"[تط]م[ا]?ن(ت| ?[اآ])لاف"
]
, prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ Integer -> Maybe Token
integer Integer
8000
}
ruleInteger9000 :: Rule
ruleInteger9000 :: Rule
ruleInteger9000 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (9000)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"([تط]سع)(ت| ?[اآ])لاف"
]
, prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ Integer -> Maybe Token
integer Integer
9000
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleInteger2
, Rule
ruleInteger3
, Rule
ruleInteger8
, Rule
ruleInteger11
, Rule
ruleInteger12
, Rule
ruleInteger13
, Rule
ruleInteger14
, Rule
ruleInteger15
, Rule
ruleInteger16
, Rule
ruleInteger17
, Rule
ruleInteger18
, Rule
ruleInteger19
, Rule
ruleInteger30_80
, Rule
ruleInteger100
, Rule
ruleInteger200
, Rule
ruleInteger300
, Rule
ruleInteger400
, Rule
ruleInteger500
, Rule
ruleInteger600
, Rule
ruleInteger700
, Rule
ruleInteger800
, Rule
ruleInteger900
, Rule
ruleInteger101_999
, Rule
ruleInteger3000
, Rule
ruleInteger4000
, Rule
ruleInteger5000
, Rule
ruleInteger6000
, Rule
ruleInteger7000
, Rule
ruleInteger8000
, Rule
ruleInteger9000
]