{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Ordinal.FR.Rules
( rules
) where
import Data.HashMap.Strict ( HashMap)
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 (parseInt)
import Duckling.Ordinal.Helpers
import Duckling.Regex.Types (GroupMatch (..))
import Duckling.Types
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
"première", Int
1 )
, ( Text
"premiere", Int
1 )
, ( Text
"premier", Int
1 )
, ( Text
"deuxième", Int
2 )
, ( Text
"deuxieme", Int
2 )
, ( Text
"second", Int
2 )
, ( Text
"seconde", Int
2 )
, ( Text
"troisième", Int
3 )
, ( Text
"troisieme", Int
3 )
, ( Text
"quatrieme", Int
4 )
, ( Text
"quatrième", Int
4 )
, ( Text
"cinquieme", Int
5 )
, ( Text
"cinquième", Int
5 )
, ( Text
"sixième", Int
6 )
, ( Text
"sixieme", Int
6 )
, ( Text
"septieme", Int
7 )
, ( Text
"septième", Int
7 )
, ( Text
"huitième", Int
8 )
, ( Text
"huitieme", Int
8 )
, ( Text
"neuvieme", Int
9 )
, ( Text
"neuvième", Int
9 )
, ( Text
"dixième", Int
10 )
, ( Text
"dixieme", Int
10 )
, ( Text
"onzième", Int
11 )
, ( Text
"onzieme", Int
11 )
, ( Text
"douzieme", Int
12 )
, ( Text
"douzième", Int
12 )
, ( Text
"treizieme", Int
13 )
, ( Text
"treizième", Int
13 )
, ( Text
"quatorzième", Int
14 )
, ( Text
"quatorzieme", Int
14 )
, ( Text
"quinzième", Int
15 )
, ( Text
"quinzieme", Int
15 )
, ( Text
"seizieme", Int
16 )
, ( Text
"seizième", Int
16 )
]
ruleOrdinalsPremierseizieme :: Rule
ruleOrdinalsPremierseizieme :: Rule
ruleOrdinalsPremierseizieme = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinals (premier..seizieme)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(premi(ere?|ère)|(deux|trois|quatr|cinqu|six|sept|huit|neuv|dix|onz|douz|treiz|quatorz|quinz|seiz)i(e|è)me|seconde?)"
]
, 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
}
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+) ?(ere?|ère|ème|eme|e)"
]
, 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 -> Maybe Int
parseInt Text
match
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleOrdinalDigits
, Rule
ruleOrdinalsPremierseizieme
]