{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Numeral.MY.Rules
( rules
) where
import Data.HashMap.Strict (HashMap)
import Data.String
import Data.Text (Text)
import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers
import Duckling.Numeral.Types (NumeralData (..))
import Duckling.Regex.Types
import Duckling.Types
import Prelude
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import qualified Duckling.Numeral.Types as TNumeral
ruleInteger5 :: Rule
ruleInteger5 :: Rule
ruleInteger5 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (11..99) "
, pattern :: Pattern
pattern =
[ Double -> Double -> PatternItem
numberBetween Double
1 Double
10
, String -> PatternItem
regex String
"ဆယ့်"
, 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
_:
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 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
10
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
integer09Map :: HashMap Text Integer
integer09Map :: HashMap Text Integer
integer09Map = [(Text, Integer)] -> HashMap Text Integer
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"၀", Integer
0 )
, ( Text
"၁", Integer
1 )
, ( Text
"၂", Integer
2 )
, ( Text
"၃", Integer
3 )
, ( Text
"၄", Integer
4 )
, ( Text
"၅", Integer
5 )
, ( Text
"၆", Integer
6 )
, ( Text
"၇", Integer
7 )
, ( Text
"၈", Integer
8 )
, ( Text
"၉", Integer
9 )
]
ruleInteger09 :: Rule
ruleInteger09 :: Rule
ruleInteger09 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (0..9) - numeric"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(၀|၁|၂|၃|၄|၅|၆|၇|၈|၉)"
]
, 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
match HashMap Text Integer
integer09Map 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
}
ruleInteger3 :: Rule
ruleInteger3 :: Rule
ruleInteger3 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (11..19) "
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"ဆယ့်"
, Double -> Double -> PatternItem
numberBetween Double
1 Double
10
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token
_: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
10
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
integerPaliMap :: HashMap Text Integer
integerPaliMap :: HashMap Text Integer
integerPaliMap = [(Text, Integer)] -> HashMap Text Integer
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"ပထမ", Integer
1 )
, ( Text
"ဒုတိယ", Integer
2 )
, ( Text
"တတိယ", Integer
3 )
]
ruleIntegerPali :: Rule
ruleIntegerPali :: Rule
ruleIntegerPali = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (1..3) - pali"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(ပထမ|ဒုတိယ|တတိယ)"
]
, 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
match HashMap Text Integer
integerPaliMap 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
}
ruleInteger6 :: Rule
ruleInteger6 :: Rule
ruleInteger6 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (100..900)"
, pattern :: Pattern
pattern =
[ Double -> Double -> PatternItem
numberBetween Double
1 Double
10
, String -> PatternItem
regex String
"ရာ"
]
, 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
100
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleInteger7 :: Rule
ruleInteger7 :: Rule
ruleInteger7 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (1000..9000)"
, pattern :: Pattern
pattern =
[ Double -> Double -> PatternItem
numberBetween Double
1 Double
10
, String -> PatternItem
regex String
"ထောင်"
]
, 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
1000
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleInteger8 :: Rule
ruleInteger8 :: Rule
ruleInteger8 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (10000..90000)"
, pattern :: Pattern
pattern =
[ Double -> Double -> PatternItem
numberBetween Double
1 Double
10
, String -> PatternItem
regex String
"သောင်း"
]
, 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
10000
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleInteger :: Rule
ruleInteger :: Rule
ruleInteger = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer 0"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"သုံည|မရှိ"
]
, prod :: Production
prod = \[Token]
_ -> Integer -> Maybe Token
integer Integer
0
}
ruleInteger4 :: Rule
ruleInteger4 :: Rule
ruleInteger4 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (10..90)"
, pattern :: Pattern
pattern =
[ Double -> Double -> PatternItem
numberBetween Double
1 Double
10
, String -> PatternItem
regex String
"ဆယ်"
]
, 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
10
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
integer2Map :: HashMap Text Integer
integer2Map :: HashMap Text Integer
integer2Map = [(Text, Integer)] -> HashMap Text Integer
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"တစ်", Integer
1 )
, ( Text
"နှစ်", Integer
2 )
, ( Text
"သုံး", Integer
3 )
, ( Text
"လေး", Integer
4 )
, ( Text
"ငါး", Integer
5 )
, ( Text
"ခြေါက်", Integer
6 )
, ( Text
"ခုနှစ်", Integer
7 )
, ( Text
"ရှစ်", Integer
8 )
, ( Text
"ကိုး", Integer
9 )
, ( Text
"တစ်ဆယ်", Integer
10 )
]
ruleInteger2 :: Rule
ruleInteger2 :: Rule
ruleInteger2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (1..10)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(တစ်|နှစ်|သုံး|လေး|ငါး|ခြေါက်|ခုနှစ်|ရှစ်|ကိုး|တစ်ဆယ်)"
]
, 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
match HashMap Text Integer
integer2Map 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
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleInteger
, Rule
ruleInteger2
, Rule
ruleInteger3
, Rule
ruleInteger4
, Rule
ruleInteger5
, Rule
ruleInteger6
, Rule
ruleInteger7
, Rule
ruleInteger8
, Rule
ruleInteger09
, Rule
ruleIntegerPali
]