{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoRebindableSyntax #-}
module Duckling.Numeral.NE.Rules
( rules
) where
import Control.Applicative ((<|>))
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
zeroToNineteenMap :: HashMap Text Integer
zeroToNineteenMap :: HashMap Text Integer
zeroToNineteenMap = [(Text, Integer)] -> HashMap Text Integer
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"शुन्य", Integer
0 )
, ( 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 )
, ( Text
"दश", Integer
10 )
, ( Text
"एघार", Integer
11 )
, ( Text
"बाह्र", Integer
12 )
, ( Text
"तेह्र", Integer
13 )
, ( Text
"चौध", Integer
14 )
, ( Text
"पन्ध्र", Integer
15 )
, ( Text
"सोह्र", Integer
16 )
, ( Text
"सत्र", Integer
17 )
, ( Text
"अठार", Integer
18 )
, ( Text
"उन्नाइस", Integer
19 )
]
ruleToNineteen :: Rule
ruleToNineteen :: Rule
ruleToNineteen = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (0..19)"
, 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 -> Text
Text.toLower Text
match) HashMap Text Integer
zeroToNineteenMap 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
}
twentyoneToTwentynineMap :: HashMap Text Integer
twentyoneToTwentynineMap :: HashMap Text Integer
twentyoneToTwentynineMap = [(Text, Integer)] -> HashMap Text Integer
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"एक्काइस", Integer
21 )
, ( Text
"बाइस", Integer
22 )
, ( Text
"तेइस", Integer
23 )
, ( Text
"चौबिस", Integer
24 )
, ( Text
"पच्चिस", Integer
25 )
, ( Text
"छब्बिस", Integer
26 )
, ( Text
"सत्ताइस", Integer
27 )
, ( Text
"अट्ठाइस", Integer
28 )
, ( Text
"उनन्तिस", Integer
29 )
]
ruleTwentyoneToTwentynine :: Rule
ruleTwentyoneToTwentynine :: Rule
ruleTwentyoneToTwentynine = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"number (21..29)"
, 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 -> Text
Text.toLower Text
match) HashMap Text Integer
twentyoneToTwentynineMap 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
}
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
"बिस", Integer
20 )
, ( Text
"तिस", Integer
30 )
, ( Text
"चालिस", Integer
40 )
, ( Text
"पचास", Integer
50 )
, ( Text
"साठी", Integer
60 )
, ( Text
"सत्तरी", Integer
70 )
, ( Text
"असी", Integer
80 )
, ( Text
"नब्बे", Integer
90 )
]
ruleTens :: Rule
ruleTens :: Rule
ruleTens = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (20..90)"
, 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 -> 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
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleToNineteen
, Rule
ruleTwentyoneToTwentynine
, Rule
ruleTens
]