-- Copyright (c) 2016-present, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the BSD-style license found in the
-- LICENSE file in the root directory of this source tree.


{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}

module Duckling.Ordinal.ES.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
"primero" , Int
1 )
  , ( Text
"primeros" , Int
1 )
  , ( Text
"primera" , Int
1 )
  , ( Text
"primeras" , Int
1 )
  , ( Text
"segundo" , Int
2 )
  , ( Text
"segunda" , Int
2 )
  , ( Text
"segundas" , Int
2 )
  , ( Text
"segundos" , Int
2 )
  , ( Text
"terceros" , Int
3 )
  , ( Text
"tercera" , Int
3 )
  , ( Text
"terceras" , Int
3 )
  , ( Text
"tercero" , Int
3 )
  , ( Text
"tercer" , Int
3 )
  , ( Text
"cuarta" , Int
4 )
  , ( Text
"cuartas" , Int
4 )
  , ( Text
"cuartos" , Int
4 )
  , ( Text
"cuarto" , Int
4 )
  , ( Text
"quinto" , Int
5 )
  , ( Text
"quinta" , Int
5 )
  , ( Text
"quintas" , Int
5 )
  , ( Text
"quintos" , Int
5 )
  , ( Text
"sextos" , Int
6 )
  , ( Text
"sexto" , Int
6 )
  , ( Text
"sexta" , Int
6 )
  , ( Text
"sextas" , Int
6 )
  , ( Text
"séptimas" , Int
7 )
  , ( Text
"septimas" , Int
7 )
  , ( Text
"séptima" , Int
7 )
  , ( Text
"septimos" , Int
7 )
  , ( Text
"septima" , Int
7 )
  , ( Text
"séptimo" , Int
7 )
  , ( Text
"séptimos" , Int
7 )
  , ( Text
"septimo" , Int
7 )
  , ( Text
"octavas" , Int
8 )
  , ( Text
"octavo" , Int
8 )
  , ( Text
"octavos" , Int
8 )
  , ( Text
"octava" , Int
8 )
  , ( Text
"novenos" , Int
9 )
  , ( Text
"novena" , Int
9 )
  , ( Text
"noveno" , Int
9 )
  , ( Text
"novenas" , Int
9 )
  , ( Text
"décimos" , Int
10 )
  , ( Text
"decimo" , Int
10 )
  , ( Text
"decimos" , Int
10 )
  , ( Text
"décimo" , Int
10 )
  , ( Text
"decimas" , Int
10 )
  , ( Text
"décima" , Int
10 )
  , ( Text
"decima" , Int
10 )
  , ( Text
"décimas" , Int
10 )
  ]

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|segund|tercer|cuart|quint|sext|s[eé]ptim|octav|noven|d[eé]cim)(os?|as?)|(prim|terc)er)"
    ]
  , 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
  }

rules :: [Rule]
rules :: [Rule]
rules =
  [ Rule
ruleOrdinalsPrimero
  ]