{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Numeral.TR.Rules
( rules
) where
import Data.HashMap.Strict (HashMap)
import Data.Maybe
import Data.String
import Data.Text (Text)
import Prelude
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers
import Duckling.Numeral.Types (NumeralData (..))
import Duckling.Regex.Types
import Duckling.Types
import qualified Duckling.Numeral.Types as TNumeral
hundredsMap :: HashMap Text Integer
hundredsMap :: HashMap Text Integer
hundredsMap = [(Text, Integer)] -> HashMap Text Integer
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"yüz", Integer
100)
, ( Text
"ikiyüz", Integer
200)
, ( Text
"üçyüz", Integer
300)
, ( Text
"dörtyüz", Integer
400)
, ( Text
"beşyüz", Integer
500)
, ( Text
"altıyüz", Integer
600)
, ( Text
"yediyüz", Integer
700)
, ( Text
"sekizyüz", Integer
800)
, ( Text
"dokuzyüz", Integer
900)
]
ruleInteger5 :: Rule
ruleInteger5 :: Rule
ruleInteger5 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 100..900"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(yüz|ikiyüz|üçyüz|dörtyüz|beşyüz|altıyüz|yediyüz|sekizyüz|dokuzyüz)"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_) ->
Text -> HashMap Text Integer -> Maybe Integer
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup (Text -> Text
Text.toLower Text
match) HashMap Text Integer
hundredsMap Maybe Integer -> (Integer -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Integer -> Maybe Token
integer Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> Token -> Maybe Token
withGrain Int
2
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
ruleNumeralsPrefixWithNegativeOrMinus :: Rule
ruleNumeralsPrefixWithNegativeOrMinus = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"numbers prefix with -, negative or minus"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"-|eksi|negatif"
, Predicate -> PatternItem
Predicate Predicate
isPositive
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token
_:Token Dimension a
Numeral NumeralData{TNumeral.value = v}:[Token]
_) ->
Double -> Maybe Token
double (Double
v Double -> Double -> Double
forall a. Num a => a -> a -> a
* (- Double
1))
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleACoupleOf :: Rule
ruleACoupleOf :: Rule
ruleACoupleOf = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"a couple (of)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(bir )?çift"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
2 Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> Token -> Maybe Token
withGrain Int
1
}
ruleFew :: Rule
ruleFew :: Rule
ruleFew = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"few"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(bir)?az"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
3
}
ruleTen :: Rule
ruleTen :: Rule
ruleTen = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ten"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"on"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
10 Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> Token -> Maybe Token
withGrain Int
1 Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Token -> Maybe Token
withMultipliable
}
ruleDecimalWithThousandsSeparator :: Rule
ruleDecimalWithThousandsSeparator :: Rule
ruleDecimalWithThousandsSeparator = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"decimal with thousands separator"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(\\d+(\\.\\d\\d\\d)+,\\d+)"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):
[Token]
_) -> let fmt :: Text
fmt = Text -> Text -> Text -> Text
Text.replace Text
"," Text
"." (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Text -> Text
Text.replace Text
"." Text
Text.empty Text
match
in Text -> Maybe Double
parseDouble Text
fmt Maybe Double -> (Double -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Double -> Maybe Token
double
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleMultiply :: Rule
ruleMultiply :: Rule
ruleMultiply = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"compose by multiplication"
, pattern :: Pattern
pattern =
[ Dimension NumeralData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension NumeralData
Numeral
, Predicate -> PatternItem
Predicate Predicate
isMultipliable
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Numeral NumeralData{TNumeral.value = val1}:
Token Dimension a
Numeral NumeralData{TNumeral.value = val2, TNumeral.grain = g2}:
[Token]
_) | Maybe Int -> Bool
forall a. Maybe a -> Bool
isNothing Maybe Int
g2 Bool -> Bool -> Bool
|| (Maybe Int -> Bool
forall a. Maybe a -> Bool
isJust Maybe Int
g2 Bool -> Bool -> Bool
&& Double
val2 Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
val1) -> case Maybe Int
g2 of
Maybe Int
Nothing -> Double -> Maybe Token
double (Double -> Maybe Token) -> Double -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Double
val1 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
val2
Just Int
g -> Double -> Maybe Token
double (Double
val1 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
val2) Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> Token -> Maybe Token
withGrain Int
g
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleDecimalNumeral :: Rule
ruleDecimalNumeral :: Rule
ruleDecimalNumeral = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"decimal number"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(\\d*,\\d+)"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_) ->
Bool -> Text -> Maybe Token
parseDecimal Bool
False Text
match
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
numeralSuffixesHalfsuffixTextMap :: HashMap Text Double
numeralSuffixesHalfsuffixTextMap :: HashMap Text Double
numeralSuffixesHalfsuffixTextMap = [(Text, Double)] -> HashMap Text Double
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"birbuçuk", Double
1.5)
, ( Text
"bibuçuk", Double
1.5)
, ( Text
"ikibuçuk", Double
2.5)
, ( Text
"ü\231buçuk", Double
3.5)
, ( Text
"dörtbuçuk", Double
4.5)
, ( Text
"be\351buçuk", Double
5.5)
, ( Text
"altıbuçuk", Double
6.5)
, ( Text
"yedibuçuk", Double
7.5)
, ( Text
"sekizbuçuk", Double
8.5)
, ( Text
"dokuzbuçuk", Double
9.5)
]
ruleNumeralSuffixesHalfsuffixText :: Rule
ruleNumeralSuffixesHalfsuffixText :: Rule
ruleNumeralSuffixesHalfsuffixText = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"number suffixes (half-suffix text) (1..9)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"((bir?|iki|üçü?|dört|beş|altı|yedi|sekiz|dokuz)(buçuk))"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_) ->
Text -> HashMap Text Double -> Maybe Double
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup (Text -> Text
Text.toLower Text
match) HashMap Text Double
numeralSuffixesHalfsuffixTextMap Maybe Double -> (Double -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Double -> Maybe Token
double
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
tenToNintynineMap :: HashMap Text Integer
tenToNintynineMap :: HashMap Text Integer
tenToNintynineMap = [(Text, Integer)] -> HashMap Text Integer
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"onbi", Integer
11)
, ( Text
"onbir", Integer
11)
, ( Text
"oniki", Integer
12)
, ( Text
"onüç", Integer
13)
, ( Text
"ondört", Integer
14)
, ( Text
"onbeş", Integer
15)
, ( Text
"onaltı", Integer
16)
, ( Text
"onyedi", Integer
17)
, ( Text
"onsekiz", Integer
18)
, ( Text
"ondokuz", Integer
19)
, ( Text
"yirmibi", Integer
21)
, ( Text
"yirmibir", Integer
21)
, ( Text
"yirmiiki", Integer
22)
, ( Text
"yirmiüç", Integer
23)
, ( Text
"yirmidört", Integer
24)
, ( Text
"yirmibeş", Integer
25)
, ( Text
"yirmialtı", Integer
26)
, ( Text
"yirmiyedi", Integer
27)
, ( Text
"yirmisekiz", Integer
28)
, ( Text
"yirmidokuz", Integer
29)
, ( Text
"otuzbi", Integer
31)
, ( Text
"otuzbir", Integer
31)
, ( Text
"otuziki", Integer
32)
, ( Text
"otuzüç", Integer
33)
, ( Text
"otuzdört", Integer
34)
, ( Text
"otuzbeş", Integer
35)
, ( Text
"otuzaltı", Integer
36)
, ( Text
"otuzyedi", Integer
37)
, ( Text
"otuzsekiz", Integer
38)
, ( Text
"otuzdokuz", Integer
39)
, ( Text
"kırkbir", Integer
41)
, ( Text
"kırkbi", Integer
41)
, ( Text
"kırkiki", Integer
42)
, ( Text
"kırküç", Integer
43)
, ( Text
"kırkdört", Integer
44)
, ( Text
"kırkbeş", Integer
45)
, ( Text
"kırkaltı", Integer
46)
, ( Text
"kırkyedi", Integer
47)
, ( Text
"kırksekiz", Integer
48)
, ( Text
"kırkdokuz", Integer
49)
, ( Text
"ellibi", Integer
51)
, ( Text
"ellibir", Integer
51)
, ( Text
"elliiki", Integer
52)
, ( Text
"elliüç", Integer
53)
, ( Text
"ellidört", Integer
54)
, ( Text
"ellibeş", Integer
55)
, ( Text
"ellialtı", Integer
56)
, ( Text
"elliyedi", Integer
57)
, ( Text
"ellisekiz", Integer
58)
, ( Text
"ellidokuz", Integer
59)
, ( Text
"altmışbir", Integer
61)
, ( Text
"atmışbir", Integer
61)
, ( Text
"atmışiki", Integer
62)
, ( Text
"altmışiki", Integer
62)
, ( Text
"atmışüç", Integer
63)
, ( Text
"altmışüç", Integer
63)
, ( Text
"atmışdört", Integer
64)
, ( Text
"altmışdört", Integer
64)
, ( Text
"atmışbeş", Integer
65)
, ( Text
"altmışbeş", Integer
65)
, ( Text
"atmışaltı", Integer
66)
, ( Text
"altmışaltı", Integer
66)
, ( Text
"altmışyedi", Integer
67)
, ( Text
"atmışyedi", Integer
67)
, ( Text
"altmışsekiz", Integer
68)
, ( Text
"atmışsekiz", Integer
68)
, ( Text
"atmışdokuz", Integer
69)
, ( Text
"altmışdokuz", Integer
69)
, ( Text
"yetmişbir", Integer
71)
, ( Text
"yetmişbi", Integer
71)
, ( Text
"yetmişiki", Integer
72)
, ( Text
"yetmişüç", Integer
73)
, ( Text
"yetmişdört", Integer
74)
, ( Text
"yetmişbeş", Integer
75)
, ( Text
"yetmişaltı", Integer
76)
, ( Text
"yetmişyedi", Integer
77)
, ( Text
"yetmişsekiz", Integer
78)
, ( Text
"yetmişdokuz", Integer
79)
, ( Text
"seksenbir", Integer
81)
, ( Text
"seksenbi", Integer
81)
, ( Text
"sekseniki", Integer
82)
, ( Text
"seksenüç", Integer
83)
, ( Text
"seksendört", Integer
84)
, ( Text
"seksenbeş", Integer
85)
, ( Text
"seksenaltı", Integer
86)
, ( Text
"seksenyedi", Integer
87)
, ( Text
"seksensekiz", Integer
88)
, ( Text
"seksendokuz", Integer
89)
, ( Text
"doksanbi", Integer
91)
, ( Text
"doksanbir", Integer
91)
, ( Text
"doksaniki", Integer
92)
, ( Text
"doksanüç", Integer
93)
, ( Text
"doksandört", Integer
94)
, ( Text
"doksanbeş", Integer
95)
, ( Text
"doksanaltı", Integer
96)
, ( Text
"doksanyedi", Integer
97)
, ( Text
"doksansekiz", Integer
98)
, ( Text
"doksandokuz", Integer
99)
]
ruleInteger3 :: Rule
ruleInteger3 :: Rule
ruleInteger3 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 11..19 21..29 31..39 41..49 51..59 61..69 71..79 81..89 91..99"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"((on|yirmi|otuz|kırk|elli|atmış|altmış|yetmiş|seksen|doksan)(bir|bi|iki|üç|dört|beş|altı|yedi|sekiz|dokuz))"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_) ->
Text -> HashMap Text Integer -> Maybe Integer
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup (Text -> Text
Text.toLower Text
match) HashMap Text Integer
tenToNintynineMap 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
}
thousandsMap :: HashMap Text Integer
thousandsMap :: HashMap Text Integer
thousandsMap = [(Text, Integer)] -> HashMap Text Integer
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"bin", Integer
1000)
, ( Text
"ikibin", Integer
2000)
, ( Text
"üçbin", Integer
3000)
, ( Text
"dörtbin", Integer
4000)
, ( Text
"beşbin", Integer
5000)
, ( Text
"altıbin", Integer
6000)
, ( Text
"yedibin", Integer
7000)
, ( Text
"sekizbin", Integer
8000)
, ( Text
"dokuzbin", Integer
9000)
]
ruleInteger6 :: Rule
ruleInteger6 :: Rule
ruleInteger6 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 1000..9000"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(bin|ikibin|üçbin|dörtbin|beşbin|altıbin|yedibin|sekizbin|dokuzbin)"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_) ->
Text -> HashMap Text Integer -> Maybe Integer
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup (Text -> Text
Text.toLower Text
match) HashMap Text Integer
thousandsMap Maybe Integer -> (Integer -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Integer -> Maybe Token
integer Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> Token -> Maybe Token
withGrain Int
3
[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
hasGrain
, Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and ([Bool] -> Bool) -> (Token -> [Bool]) -> Predicate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Predicate] -> Token -> [Bool]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Bool -> Bool
not (Bool -> Bool) -> Predicate -> Predicate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Predicate
isMultipliable, Predicate
isPositive]
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Numeral NumeralData{TNumeral.value = val1, TNumeral.grain = Just g}:
Token Dimension a
Numeral NumeralData{TNumeral.value = val2}:
[Token]
_) | (Double
10 Double -> Double -> Double
forall a. Floating a => a -> a -> a
** Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
g) Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
val2 -> Double -> Maybe Token
double (Double -> Maybe Token) -> Double -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Double
val1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
val2
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleNumeralsSuffixesKMG :: Rule
ruleNumeralsSuffixesKMG :: Rule
ruleNumeralsSuffixesKMG = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"numbers suffixes (K, M, G)"
, pattern :: Pattern
pattern =
[ Dimension NumeralData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension NumeralData
Numeral
, String -> PatternItem
regex String
"([kmgb])(?=[\\W\\$€]|$)"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Numeral NumeralData{TNumeral.value = v}:
Token Dimension a
RegexMatch (GroupMatch (match:_)):
[Token]
_) -> case Text -> Text
Text.toLower Text
match of
Text
"k" -> Double -> Maybe Token
double (Double -> Maybe Token) -> Double -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Double
v Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
1e3
Text
"b" -> Double -> Maybe Token
double (Double -> Maybe Token) -> Double -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Double
v Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
1e3
Text
"m" -> Double -> Maybe Token
double (Double -> Maybe Token) -> Double -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Double
v Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
1e6
Text
"g" -> Double -> Maybe Token
double (Double -> Maybe Token) -> Double -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Double
v Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
1e9
Text
_ -> Maybe Token
forall a. Maybe a
Nothing
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rulePowersOfTen :: Rule
rulePowersOfTen :: Rule
rulePowersOfTen = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"powers of tens"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(y(ü)z|bin|milyon)"
]
, 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
"yüz" -> Double -> Maybe Token
double Double
1e2 Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> Token -> Maybe Token
withGrain Int
2 Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Token -> Maybe Token
withMultipliable
Text
"bin" -> Double -> Maybe Token
double Double
1e3 Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> Token -> Maybe Token
withGrain Int
3 Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Token -> Maybe Token
withMultipliable
Text
"milyon" -> Double -> Maybe Token
double Double
1e6 Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> Token -> Maybe Token
withGrain Int
6 Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Token -> Maybe Token
withMultipliable
Text
_ -> Maybe Token
forall a. Maybe a
Nothing
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
tenThousandsMap :: HashMap Text Integer
tenThousandsMap :: HashMap Text Integer
tenThousandsMap = [(Text, Integer)] -> HashMap Text Integer
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"onbin", Integer
10000)
, ( Text
"yirmibin", Integer
20000)
, ( Text
"otuzbin", Integer
30000)
, ( Text
"kırkbin", Integer
40000)
, ( Text
"ellibin", Integer
50000)
, ( Text
"altmışbin", Integer
60000)
, ( Text
"atmışbin", Integer
60000)
, ( Text
"yetmişbin", Integer
70000)
, ( Text
"seksenbin", Integer
80000)
, ( Text
"doksanbin", Integer
90000)
]
ruleInteger7 :: Rule
ruleInteger7 :: Rule
ruleInteger7 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 10000..90000"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(onbin|yirmibin|otuzbin|kırkbin|ellibin|atmışbin|altmışbin|yetmişbin|seksenbin|doksanbin)"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_) ->
Text -> HashMap Text Integer -> Maybe Integer
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup (Text -> Text
Text.toLower Text
match) HashMap Text Integer
tenThousandsMap Maybe Integer -> (Integer -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Integer -> Maybe Token
integer Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> Token -> Maybe Token
withGrain Int
4
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
hundredThousandsMap :: HashMap Text Integer
hundredThousandsMap :: HashMap Text Integer
hundredThousandsMap = [(Text, Integer)] -> HashMap Text Integer
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"yüzbin", Integer
100000)
, ( Text
"ikiyüzbin", Integer
200000)
, ( Text
"üçyüzbin", Integer
300000)
, ( Text
"dörtyüzbin", Integer
400000)
, ( Text
"beşyüzbin", Integer
500000)
, ( Text
"altıyüzbin", Integer
600000)
, ( Text
"yediyüzbin", Integer
700000)
, ( Text
"sekizyüzbin", Integer
800000)
, ( Text
"dokuzyüzbin", Integer
900000)
]
ruleInteger8 :: Rule
ruleInteger8 :: Rule
ruleInteger8 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 100000..900000"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(yüzbin|ikiyüzbin|üçyüzbin|dörtyüzbin|beşyüzbin|altıyüzbin|yediyüzbin|sekizyüzbin|dokuzyüzbin)"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_) ->
Text -> HashMap Text Integer -> Maybe Integer
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup (Text -> Text
Text.toLower Text
match) HashMap Text Integer
hundredThousandsMap Maybe Integer -> (Integer -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Integer -> Maybe Token
integer Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> Token -> Maybe Token
withGrain Int
5
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleHalf :: Rule
ruleHalf :: Rule
ruleHalf = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"half"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(yarım)"
]
, prod :: Production
prod = \[Token]
_ -> Double -> Maybe Token
double Double
0.5
}
integer9Map :: HashMap Text Double
integer9Map :: HashMap Text Double
integer9Map = [(Text, Double)] -> HashMap Text Double
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"onbirbuçuk", Double
11.5)
, ( Text
"onbibuçuk", Double
11.5)
, ( Text
"onikibuçuk", Double
12.5)
, ( Text
"onüçbuçuk", Double
13.5)
, ( Text
"ondörtbuçuk", Double
14.5)
, ( Text
"onbeşbuçuk", Double
15.5)
, ( Text
"onaltıbuçuk", Double
16.5)
, ( Text
"onyedibuçuk", Double
17.5)
, ( Text
"onsekizbuçuk", Double
18.5)
, ( Text
"ondokuzbuçuk", Double
19.5)
, ( Text
"yirmibibuçuk", Double
21.5)
, ( Text
"yirmibirbuçuk", Double
21.5)
, ( Text
"yirmiikibuçuk", Double
22.5)
, ( Text
"yirmiüçbuçuk", Double
23.5)
, ( Text
"yirmidörtbuçuk", Double
24.5)
, ( Text
"yirmibeşbuçuk", Double
25.5)
, ( Text
"yirmialtıbuçuk", Double
26.5)
, ( Text
"yirmiyedibuçuk", Double
27.5)
, ( Text
"yirmisekizbuçuk", Double
28.5)
, ( Text
"yirmidokuzbuçuk", Double
29.5)
, ( Text
"otuzbibuçuk", Double
31.5)
, ( Text
"otuzbirbuçuk", Double
31.5)
, ( Text
"otuzikibuçuk", Double
32.5)
, ( Text
"otuzüçbuçuk", Double
33.5)
, ( Text
"otuzdörtbuçuk", Double
34.5)
, ( Text
"otuzbeşbuçuk", Double
35.5)
, ( Text
"otuzaltıbuçuk", Double
36.5)
, ( Text
"otuzyedibuçuk", Double
37.5)
, ( Text
"otuzsekizbuçuk", Double
38.5)
, ( Text
"otuzdokuzbuçuk", Double
39.5)
, ( Text
"kırkbirbuçuk", Double
41.5)
, ( Text
"kırkbibuçuk", Double
41.5)
, ( Text
"kırkikibuçuk", Double
42.5)
, ( Text
"kırküçbuçuk", Double
43.5)
, ( Text
"kırkdörtbuçuk", Double
44.5)
, ( Text
"kırkbeşbuçuk", Double
45.5)
, ( Text
"kırkaltıbuçuk", Double
46.5)
, ( Text
"kırkyedibuçuk", Double
47.5)
, ( Text
"kırksekizbuçuk", Double
48.5)
, ( Text
"kırkdokuzbuçuk", Double
49.5)
, ( Text
"ellibibuçuk", Double
51.5)
, ( Text
"ellibirbuçuk", Double
51.5)
, ( Text
"elliikibuçuk", Double
52.5)
, ( Text
"elliüçbuçuk", Double
53.5)
, ( Text
"ellidörtbuçuk", Double
54.5)
, ( Text
"ellibeşbuçuk", Double
55.5)
, ( Text
"ellialtıbuçuk", Double
56.5)
, ( Text
"elliyedibuçuk", Double
57.5)
, ( Text
"ellisekizbuçuk", Double
58.5)
, ( Text
"ellidokuzbuçuk", Double
59.5)
, ( Text
"altmışbirbuçuk", Double
61.5)
, ( Text
"atmışbirbuçuk", Double
61.5)
, ( Text
"altmışikibuçuk", Double
62.5)
, ( Text
"atmışikibuçuk", Double
62.5)
, ( Text
"atmışüçbuçuk", Double
63.5)
, ( Text
"altmışüçbuçuk", Double
63.5)
, ( Text
"altmışdörtbuçuk", Double
64.5)
, ( Text
"atmışdörtbuçuk", Double
64.5)
, ( Text
"altmışbeşbuçuk", Double
65.5)
, ( Text
"atmışbeşbuçuk", Double
65.5)
, ( Text
"altmışaltıbuçuk", Double
66.5)
, ( Text
"atmışaltıbuçuk", Double
66.5)
, ( Text
"atmışyedibuçuk", Double
67.5)
, ( Text
"altmışyedibuçuk", Double
67.5)
, ( Text
"altmışsekizbuçuk", Double
68.5)
, ( Text
"atmışsekizbuçuk", Double
68.5)
, ( Text
"altmışdokuzbuçuk", Double
69.5)
, ( Text
"atmışdokuzbuçuk", Double
69.5)
, ( Text
"yetmişbibuçuk", Double
71.5)
, ( Text
"yetmişbirbuçuk", Double
71.5)
, ( Text
"yetmişikibuçuk", Double
72.5)
, ( Text
"yetmişüçbuçuk", Double
73.5)
, ( Text
"yetmişdörtbuçuk", Double
74.5)
, ( Text
"yetmişbeşbuçuk", Double
75.5)
, ( Text
"yetmişaltıbuçuk", Double
76.5)
, ( Text
"yetmişyedibuçuk", Double
77.5)
, ( Text
"yetmişsekizbuçuk", Double
78.5)
, ( Text
"yetmişdokuzbuçuk", Double
79.5)
, ( Text
"seksenbibuçuk", Double
81.5)
, ( Text
"seksenbirbuçuk", Double
81.5)
, ( Text
"seksenikibuçuk", Double
82.5)
, ( Text
"seksenüçbuçuk", Double
83.5)
, ( Text
"seksendörtbuçuk", Double
84.5)
, ( Text
"seksenbeşbuçuk", Double
85.5)
, ( Text
"seksenaltıbuçuk", Double
86.5)
, ( Text
"seksenyedibuçuk", Double
87.5)
, ( Text
"seksensekizbuçuk", Double
88.5)
, ( Text
"seksendokuzbuçuk", Double
89.5)
, ( Text
"doksanbirbuçuk", Double
91.5)
, ( Text
"doksanbibuçuk", Double
91.5)
, ( Text
"doksanikibuçuk", Double
92.5)
, ( Text
"doksanüçbuçuk", Double
93.5)
, ( Text
"doksandörtbuçuk", Double
94.5)
, ( Text
"doksanbeşbuçuk", Double
95.5)
, ( Text
"doksanaltıbuçuk", Double
96.5)
, ( Text
"doksanyedibuçuk", Double
97.5)
, ( Text
"doksansekizbuçuk", Double
98.5)
, ( Text
"doksandokuzbuçuk", Double
99.5)
]
ruleInteger9 :: Rule
ruleInteger9 :: Rule
ruleInteger9 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 11..19 21..29 31..39 41..49 51..59 61..69 71..79 81..89 91..99"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"((on|yirmi|otuz|kırk|elli|atmış|altmış|yetmiş|seksen|doksan)(bir|bi|iki|üçü?|dört|beş|altı|yedi|sekiz|dokuz)(buçuk))"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_) ->
Text -> HashMap Text Double -> Maybe Double
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup (Text -> Text
Text.toLower Text
match) HashMap Text Double
integer9Map Maybe Double -> (Double -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Double -> Maybe Token
double
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleDozen :: Rule
ruleDozen :: Rule
ruleDozen = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"dozen"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"düzine"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
12 Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> Token -> Maybe Token
withGrain Int
1 Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Token -> Maybe Token
withMultipliable
}
oneToNineMap :: HashMap Text Integer
oneToNineMap :: HashMap Text Integer
oneToNineMap = [(Text, Integer)] -> HashMap Text Integer
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"s\305f\305r", Integer
0)
, ( Text
"yok", Integer
0)
, ( Text
"hiç", Integer
0)
, ( Text
"bir", Integer
1)
, ( Text
"bi", Integer
1)
, ( Text
"yek", Integer
1)
, ( Text
"tek", Integer
1)
, ( Text
"iki", Integer
2)
, ( Text
"üç", Integer
3)
, ( Text
"üçü", Integer
3)
, ( Text
"dört", Integer
4)
, ( Text
"beş", Integer
5)
, ( Text
"altı", Integer
6)
, ( Text
"yedi", Integer
7)
, ( Text
"sekiz", Integer
8)
, ( Text
"dokuz", Integer
9)
]
ruleInteger :: Rule
ruleInteger :: Rule
ruleInteger = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (0..9)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(yok|hi(ç)|s(ı)f(ı)r|bir?|[ty]ek|iki|(ü)(ç)(ü)?|d(ö)rt|be(ş)|alt(ı)|yedi|sekiz|dokuz)"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_) ->
Text -> HashMap Text Integer -> Maybe Integer
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup (Text -> Text
Text.toLower Text
match) HashMap Text Integer
oneToNineMap 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
}
numeralSuffixesHalfsuffixText2Map :: HashMap Text Double
numeralSuffixesHalfsuffixText2Map :: HashMap Text Double
numeralSuffixesHalfsuffixText2Map = [(Text, Double)] -> HashMap Text Double
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"onbuçuk", Double
10.5)
, ( Text
"yirmibuçuk", Double
20.5)
, ( Text
"otuzbuçuk", Double
30.5)
, ( Text
"kırkbuçuk", Double
40.5)
, ( Text
"ellibuçuk", Double
50.5)
, ( Text
"atmışbuçuk", Double
60.5)
, ( Text
"altmışbuçuk", Double
60.5)
, ( Text
"yetmişbuçuk", Double
70.5)
, ( Text
"seksenbuçuk", Double
80.5)
, ( Text
"doksanbuçuk", Double
90.5)
]
ruleNumeralSuffixesHalfsuffixText2 :: Rule
ruleNumeralSuffixesHalfsuffixText2 :: Rule
ruleNumeralSuffixesHalfsuffixText2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"number suffixes (half-suffix text) (10..90)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"((on|yirmi|otuz|kırk|elli|atmış|altmış|yetmiş|seksen|doksan)(buçuk))"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_) ->
Text -> HashMap Text Double -> Maybe Double
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup (Text -> Text
Text.toLower Text
match) HashMap Text Double
numeralSuffixesHalfsuffixText2Map
Maybe Double -> (Double -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Double -> Maybe Token
double
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleNumeralSuffixesHalfSuffix :: Rule
ruleNumeralSuffixesHalfSuffix :: Rule
ruleNumeralSuffixesHalfSuffix = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"number suffixes (half-suffix)"
, pattern :: Pattern
pattern =
[ Dimension NumeralData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension NumeralData
Numeral
, String -> PatternItem
regex String
"(buçuk)(?=[\\W\\$€]|$)"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Numeral NumeralData{TNumeral.value = v}:[Token]
_) -> Double -> Maybe Token
double (Double -> Maybe Token) -> Double -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Double
v Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
0.5
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleInteger4 :: Rule
ruleInteger4 :: Rule
ruleInteger4 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 11..99"
, pattern :: Pattern
pattern =
[ [Double] -> PatternItem
oneOf [Double
70, Double
20, Double
60, Double
50, Double
40, Double
90, Double
30, Double
10, Double
80]
, Double -> Double -> PatternItem
numberBetween Double
1 Double
10
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Numeral NumeralData{TNumeral.value = v1}:
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
}
ruleGroupOfTens :: Rule
ruleGroupOfTens :: Rule
ruleGroupOfTens = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"group of ten(s)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"deste"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
10 Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> Token -> Maybe Token
withGrain Int
1 Maybe Token -> (Token -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Token -> Maybe Token
withMultipliable
}
tensMap :: HashMap Text Integer
tensMap :: HashMap Text Integer
tensMap = [(Text, Integer)] -> HashMap Text Integer
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"on", Integer
10)
, ( Text
"yirmi", Integer
20)
, ( Text
"otuz", Integer
30)
, ( Text
"kırk", Integer
40)
, ( Text
"elli", Integer
50)
, ( Text
"altmış", Integer
60)
, ( Text
"atmış", Integer
60)
, ( Text
"yetmiş", Integer
70)
, ( Text
"seksen", Integer
80)
, ( Text
"doksan", Integer
90)
]
ruleInteger2 :: Rule
ruleInteger2 :: Rule
ruleInteger2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (10..90)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(on|yirmi|otuz|kırk|elli|atmış|altmış|yetmiş|seksen|doksan)"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_) ->
Text -> HashMap Text Integer -> Maybe Integer
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup (Text -> Text
Text.toLower Text
match) HashMap Text Integer
tensMap 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
}
ruleQuarter :: Rule
ruleQuarter :: Rule
ruleQuarter = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"quarter"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(çeyrek)"
]
, prod :: Production
prod = \[Token]
_ -> Double -> Maybe Token
double Double
0.25
}
ruleNumeralDotNumeral :: Rule
ruleNumeralDotNumeral :: Rule
ruleNumeralDotNumeral = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"number dot number"
, pattern :: Pattern
pattern =
[ Dimension NumeralData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension NumeralData
Numeral
, String -> PatternItem
regex String
"nokta|virgül"
, Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not (Bool -> Bool) -> Predicate -> Predicate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Predicate
hasGrain
]
, 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 -> Double
decimalsToDouble Double
v2
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleIntegerWithThousandsSeparator :: Rule
ruleIntegerWithThousandsSeparator :: Rule
ruleIntegerWithThousandsSeparator = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer with thousands separator ."
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(\\d{1,3}(\\.\\d\\d\\d){1,5})"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_) ->
Text -> Maybe Double
parseDouble (Text -> Text -> Text -> Text
Text.replace Text
"." Text
Text.empty Text
match) Maybe Double -> (Double -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Double -> Maybe Token
double
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleACoupleOf
, Rule
ruleDecimalNumeral
, Rule
ruleDecimalWithThousandsSeparator
, Rule
ruleDozen
, Rule
ruleFew
, Rule
ruleGroupOfTens
, Rule
ruleHalf
, Rule
ruleInteger
, Rule
ruleInteger2
, Rule
ruleInteger3
, Rule
ruleInteger4
, Rule
ruleInteger5
, Rule
ruleInteger6
, Rule
ruleInteger7
, Rule
ruleInteger8
, Rule
ruleInteger9
, Rule
ruleIntegerWithThousandsSeparator
, Rule
ruleIntersect
, Rule
ruleNumeralDotNumeral
, Rule
ruleNumeralSuffixesHalfSuffix
, Rule
ruleNumeralSuffixesHalfsuffixText
, Rule
ruleNumeralSuffixesHalfsuffixText2
, Rule
ruleNumeralsPrefixWithNegativeOrMinus
, Rule
ruleNumeralsSuffixesKMG
, Rule
rulePowersOfTen
, Rule
ruleQuarter
, Rule
ruleTen
, Rule
ruleMultiply
]