{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoRebindableSyntax #-}
module Duckling.Numeral.HU.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
ruleNumeralMap :: HashMap Text Integer
ruleNumeralMap :: HashMap Text Integer
ruleNumeralMap = [(Text, Integer)] -> HashMap Text Integer
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"nulla", Integer
0 )
, ( Text
"z\x00E9r\x00F3", Integer
0 )
, ( Text
"egy", Integer
1 )
, ( Text
"kett\x0151", Integer
2 )
, ( Text
"h\x00E1rom", Integer
3 )
, ( Text
"n\x00E9gy", Integer
4 )
, ( Text
"\x00F6t", Integer
5)
, ( Text
"hat", Integer
6)
, ( Text
"h\x00E9t", Integer
7)
, ( Text
"nyolc", Integer
8)
, ( Text
"kilenc", Integer
9)
, ( Text
"t\x00EDz", Integer
10)
]
ruleNumeral :: Rule
ruleNumeral :: Rule
ruleNumeral = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"number (0..10)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(nulla|z\x00E9r\x00F3|egy|kett\x0151|h\x00E1rom|n\x00E9gy|\x00F6t|hat|h\x00E9t|nyolc|kilenc|t\x00EDz)"
]
, 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
ruleNumeralMap 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
}
elevenToNineteenMap :: HashMap Text Integer
elevenToNineteenMap :: HashMap Text Integer
elevenToNineteenMap = [(Text, Integer)] -> HashMap Text Integer
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"tizenegy", Integer
11 )
, ( Text
"tizenkett\x0151", Integer
12 )
, ( Text
"tizenh\x00E1rom", Integer
13 )
, ( Text
"tizenn\x00E9gy", Integer
14 )
, ( Text
"tizen\x00F6t", Integer
15 )
, ( Text
"tizenhat", Integer
16 )
, ( Text
"tizenh\x00E9t", Integer
17 )
, ( Text
"tizennyolc", Integer
18 )
, ( Text
"tizenkilenc", Integer
19 )
]
ruleElevenToNineteen :: Rule
ruleElevenToNineteen :: Rule
ruleElevenToNineteen = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"number (11..19)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(tizenegy|tizenkett\x0151|tizenh\x00E1rom|tizenn\x00E9gy|tizen\x00F6t|tizenhat|tizenh\x00E9t|tizennyolc|tizenkilenc)"
]
, 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
elevenToNineteenMap 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
"huszonegy", Integer
21 )
, ( Text
"huszonkett\x0151", Integer
22 )
, ( Text
"huszonh\x00E1rom", Integer
23 )
, ( Text
"huszonn\x00E9gy", Integer
24 )
, ( Text
"huszon\x00F6t", Integer
25 )
, ( Text
"huszonhat", Integer
26 )
, ( Text
"huszonh\x00E9t", Integer
27 )
, ( Text
"huszonnyolc", Integer
28 )
, ( Text
"huszonkilenc", 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
"(huszonegy|huszonkett\x0151|huszonh\x00E1rom|huszonn\x00E9gy|huszon\x00F6t|huszonhat|huszonh\x00E9t|huszonnyolc|huszonkilenc)"
]
, 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
"h\x00FAsz", Integer
20 )
, ( Text
"harminc", Integer
30 )
, ( Text
"negyven", Integer
40 )
, ( Text
"\x00F6tven", Integer
50 )
, ( Text
"hatvan", Integer
60 )
, ( Text
"hetven", Integer
70 )
, ( Text
"nyolcvan", Integer
80 )
, ( Text
"kilencven", Integer
90 )
]
ruleTens :: Rule
ruleTens :: Rule
ruleTens = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer (20,30..90)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(h\x00FAsz|harminc|negyven|ötven|hatvan|hetven|nyolcvan|kilencven)"
]
, 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
}
ruleCompositeTens :: Rule
ruleCompositeTens :: Rule
ruleCompositeTens = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"integer ([3-9][1-9])"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(harminc|negyven|\x00F6tven|hatvan|hetven|nyolcvan|kilencven)(egy|kett\x0151|h\x00E1rom|n\x00E9gy|\x00F6t|hat|h\x00E9t|nyolc|kilenc)"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (m1:m2:_)):[Token]
_) -> do
Integer
v1 <- 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
m1) HashMap Text Integer
tensMap
Integer
v2 <- 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
m2) HashMap Text Integer
ruleNumeralMap
Integer -> Maybe Token
integer (Integer -> Maybe Token) -> Integer -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Integer
v1 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
v2
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleNumeral
, Rule
ruleElevenToNineteen
, Rule
ruleTwentyoneToTwentynine
, Rule
ruleTens
, Rule
ruleCompositeTens
]