{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Ordinal.HR.Rules
( rules ) where
import Data.HashMap.Strict (HashMap)
import Data.Maybe
import Data.String
import Data.Text (Text)
import Prelude
import qualified Data.Text as Text
import qualified Data.HashMap.Strict as HashMap
import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Ordinal.Helpers
import Duckling.Ordinal.Types (OrdinalData (..))
import Duckling.Regex.Types
import Duckling.Types
import qualified Duckling.Ordinal.Types as TOrdinal
ordinalsMap :: HashMap Text Int
ordinalsMap :: HashMap Text Int
ordinalsMap = [(Text, Int)] -> HashMap Text Int
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ (Text
"prva", Int
1)
, (Text
"prvi", Int
1)
, (Text
"prvoga", Int
1)
, (Text
"prvo", Int
1)
, (Text
"prvog", Int
1)
, (Text
"drugoga", Int
2)
, (Text
"drugo", Int
2)
, (Text
"druga", Int
2)
, (Text
"drugi", Int
2)
, (Text
"drugog", Int
2)
, (Text
"tre\263i", Int
3)
, (Text
"tre\263ega", Int
3)
, (Text
"trece", Int
3)
, (Text
"tre\263eg", Int
3)
, (Text
"treca", Int
3)
, (Text
"tre\263a", Int
3)
, (Text
"treci", Int
3)
, (Text
"\269etvrti", Int
4)
, (Text
"\269etvrtoga", Int
4)
, (Text
"cetvrtoga", Int
4)
, (Text
"cetvrto", Int
4)
, (Text
"cetvrtog", Int
4)
, (Text
"cetvrti", Int
4)
, (Text
"\269etvrtog", Int
4)
, (Text
"cetvrta", Int
4)
, (Text
"\269etvrto", Int
4)
, (Text
"\269etvrta", Int
4)
, (Text
"peto", Int
5)
, (Text
"peti", Int
5)
, (Text
"petoga", Int
5)
, (Text
"petog", Int
5)
, (Text
"peta", Int
5)
, (Text
"sesti", Int
6)
, (Text
"\353estoga", Int
6)
, (Text
"\353estog", Int
6)
, (Text
"sestoga", Int
6)
, (Text
"sesta", Int
6)
, (Text
"\353esta", Int
6)
, (Text
"\353esto", Int
6)
, (Text
"\353esti", Int
6)
, (Text
"sesto", Int
6)
, (Text
"sestog", Int
6)
, (Text
"sedmi", Int
7)
, (Text
"sedmog", Int
7)
, (Text
"sedma", Int
7)
, (Text
"sedmo", Int
7)
, (Text
"sedmoga", Int
7)
, (Text
"osmo", Int
8)
, (Text
"osmog", Int
8)
, (Text
"osma", Int
8)
, (Text
"osmi", Int
8)
, (Text
"osmoga", Int
8)
, (Text
"devetog", Int
9)
, (Text
"deveta", Int
9)
, (Text
"deveto", Int
9)
, (Text
"devetoga", Int
9)
, (Text
"deveti", Int
9)
, (Text
"desetoga", Int
10)
, (Text
"desetog", Int
10)
, (Text
"deseta", Int
10)
, (Text
"deseto", Int
10)
, (Text
"deseti", Int
10)
, (Text
"jedanaestoga", Int
11)
, (Text
"jedanaesta", Int
11)
, (Text
"jedanaesti", Int
11)
, (Text
"jedanaesto", Int
11)
, (Text
"jedanaestog", Int
11)
, (Text
"dvanaesto", Int
12)
, (Text
"dvanaestog", Int
12)
, (Text
"dvanaesti", Int
12)
, (Text
"dvanaesta", Int
12)
, (Text
"dvanaestoga", Int
12)
, (Text
"trinaesta", Int
13)
, (Text
"trinaestoga", Int
13)
, (Text
"trinaestog", Int
13)
, (Text
"trinaesto", Int
13)
, (Text
"trinaesti", Int
13)
, (Text
"cetrnaestog", Int
14)
, (Text
"cetrnaesto", Int
14)
, (Text
"cetrnaesti", Int
14)
, (Text
"\269etrnaestoga", Int
14)
, (Text
"cetrnaesta", Int
14)
, (Text
"\269etrnaesto", Int
14)
, (Text
"\269etrnaesta", Int
14)
, (Text
"cetrnaestoga", Int
14)
, (Text
"\269etrnaesti", Int
14)
, (Text
"\269etrnaestog", Int
14)
, (Text
"petnaestog", Int
15)
, (Text
"petnaesto", Int
15)
, (Text
"petnaesta", Int
15)
, (Text
"petnaesti", Int
15)
, (Text
"petnaestoga", Int
15)
, (Text
"sesnaesto", Int
16)
, (Text
"sesnaestog", Int
16)
, (Text
"sesnaesti", Int
16)
, (Text
"\353esnaestoga", Int
16)
, (Text
"sesnaesta", Int
16)
, (Text
"\353esnaesto", Int
16)
, (Text
"sesnaestoga", Int
16)
, (Text
"\353esnaesti", Int
16)
, (Text
"\353esnaesta", Int
16)
, (Text
"\353esnaestog", Int
16)
, (Text
"sedamnaesto", Int
17)
, (Text
"sedamnaestoga", Int
17)
, (Text
"sedamnaesti", Int
17)
, (Text
"sedamnaesta", Int
17)
, (Text
"sedamnaestog", Int
17)
, (Text
"osamnaestoga", Int
18)
, (Text
"osamnaestog", Int
18)
, (Text
"osamnaesti", Int
18)
, (Text
"osamnaesta", Int
18)
, (Text
"osamnaesto", Int
18)
, (Text
"devetnaestoga", Int
19)
, (Text
"devetnaestog", Int
19)
, (Text
"devetnaesto", Int
19)
, (Text
"devetnaesti", Int
19)
, (Text
"devetnaesta", Int
19)
]
ruleOrdinalsFirstth :: Rule
ruleOrdinalsFirstth :: Rule
ruleOrdinalsFirstth = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinals (first..19th)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(prv(i|a|o(ga?)?)|drug(i|a|o(ga?)?)|tre(c|ć)(i|a|e(ga?)?)|(č|c)etvrt(i|a|o(ga?)?)|pet(i|a|o(ga?)?)|(š|s)est(i|a|o(ga?)?)|sedm(i|a|o(ga?)?)|osm(i|a|o(ga?)?)|devet(i|a|o(ga?)?)|deset(i|a|o(ga?)?)|jedanaest(i|a|o(ga?)?)|dvanaest(i|a|o(ga?)?)|trinaest(i|a|o(ga?)?)|(c|č)etrnaest(i|a|o(ga?)?)|petnaest(i|a|o(ga?)?)|(s|š)esnaest(i|a|o(ga?)?)|sedamnaest(i|a|o(ga?)?)|osamnaest(i|a|o(ga?)?)|devetnaest(i|a|o(ga?)?))"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_) ->
Int -> Token
ordinal (Int -> Token) -> Maybe Int -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> HashMap Text Int -> Maybe Int
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup (Text -> Text
Text.toLower Text
match) HashMap Text Int
ordinalsMap
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleOrdinalDigits :: Rule
ruleOrdinalDigits :: Rule
ruleOrdinalDigits = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal (digits)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"0*(\\d+)(\\.| ?(t(i|a)(n|r|s)?)|(ste(n|r|s)?))"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_) -> Int -> Token
ordinal (Int -> Token) -> Maybe Int -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Maybe Int
parseInt Text
match
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleOrdinalDigits
, Rule
ruleOrdinalsFirstth
]