{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE LambdaCase #-}
module Duckling.Ordinal.CA.Rules
( rules ) where
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import Prelude
import Data.String
import Duckling.Dimensions.Types
import Duckling.Ordinal.Helpers
import Duckling.Regex.Types
import Duckling.Types
ordinalsMap :: HashMap.HashMap Text.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
"primer" , Int
1 )
, ( Text
"primers" , Int
1 )
, ( Text
"primera" , Int
1 )
, ( Text
"primeres" , Int
1 )
, ( Text
"segon" , Int
2 )
, ( Text
"segona" , Int
2 )
, ( Text
"segones" , Int
2 )
, ( Text
"segons" , Int
2 )
, ( Text
"tercer" , Int
3 )
, ( Text
"tercera" , Int
3 )
, ( Text
"tercers" , Int
3 )
, ( Text
"terceres" , Int
3 )
, ( Text
"quart" , Int
4 )
, ( Text
"quarta" , Int
4 )
, ( Text
"quarts" , Int
4 )
, ( Text
"quartes" , Int
4 )
, ( Text
"cinquè" , Int
5 )
, ( Text
"cinquena" , Int
5 )
, ( Text
"cinquens" , Int
5 )
, ( Text
"cinquenes" , Int
5 )
, ( Text
"sisè" , Int
6 )
, ( Text
"sisena" , Int
6 )
, ( Text
"sisens" , Int
6 )
, ( Text
"sisenes" , Int
6 )
, ( Text
"setè" , Int
7 )
, ( Text
"setena" , Int
7 )
, ( Text
"setens" , Int
7 )
, ( Text
"setenes" , Int
7 )
, ( Text
"vuitè" , Int
8 )
, ( Text
"vuitena" , Int
8 )
, ( Text
"vuitens" , Int
8 )
, ( Text
"vuitenes" , Int
8 )
, ( Text
"novè" , Int
9 )
, ( Text
"novena" , Int
9 )
, ( Text
"novens" , Int
9 )
, ( Text
"novenes" , Int
9 )
, ( Text
"desè" , Int
10 )
, ( Text
"desena" , Int
10 )
, ( Text
"desens" , Int
10 )
, ( Text
"desenes" , Int
10 )
, ( Text
"onzè" , Int
11 )
, ( Text
"onzena" , Int
11 )
, ( Text
"dotzè" , Int
12 )
, ( Text
"dotzena" , Int
12 )
, ( Text
"tretzè" , Int
13 )
, ( Text
"tretzena" , Int
13 )
, ( Text
"catorzè" , Int
14 )
, ( Text
"catorzena" , Int
14 )
, ( Text
"quinzè" , Int
15 )
, ( Text
"quinzena" , Int
15 )
, ( Text
"setzè" , Int
16 )
, ( Text
"setzena" , Int
16 )
, ( Text
"dissetè" , Int
17 )
, ( Text
"dissetena" , Int
17 )
, ( Text
"divuitè" , Int
18 )
, ( Text
"divuitena" , Int
18 )
, ( Text
"dinovè" , Int
19 )
, ( Text
"dinovena" , Int
19 )
, ( Text
"vintè" , Int
20 )
, ( Text
"vintena" , Int
20 )
]
ruleOrdinalsPrimero :: Rule
ruleOrdinalsPrimero :: Rule
ruleOrdinalsPrimero = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinals (primero..10)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(primer(a|s|es)?|segon(a|s|es)?|tercer(a|s|es)?|quart(a|s|es)?|cinqu(è|(en(a|s|es)))|sis(è|en(a|s|es))|set(è|en(a|s|es))|vuit(è|en(a|s|es))|nov(è|en(a|s|es))|des(è|en(a|s|es))|onz(è|ena)|dotz(è|ena)|tretz(è|ena)|catorz(è|ena)|quinz(è|ena)|setz(è|ena)|disset(è|ena)|divuit(è|ena)|dinov(è|ena)|vint(è|ena))"
]
, prod :: Production
prod = \case
(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
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleOrdinalsPrimero
]