-- 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.TimeGrain.GA.Rules
  ( rules ) where

import Data.Text (Text)
import Prelude
import Data.String

import Duckling.Dimensions.Types
import qualified Duckling.TimeGrain.Types as TG
import Duckling.Types

grains :: [(Text, String, TG.Grain)]
grains :: [(Text, String, Grain)]
grains = [ (Text
"soicind (grain)", String
"t?sh?oicind(í|i)?", Grain
TG.Second)
         , (Text
"nóiméad (grain)", String
"n[óo]im(é|e)[ai]da?", Grain
TG.Minute)
         , (Text
"uair (grain)", String
"([thn]-?)?uair(e|eanta)?", Grain
TG.Hour)
         , (Text
"lá (grain)", String
"l(ae(thanta)?|(á|a))", Grain
TG.Day)
         , (Text
"seachtain (grain)", String
"t?sh?eachtain(e|(í|i))?", Grain
TG.Week)
         , (Text
"mí (grain)", String
"mh?(í|i)(sa|nna)", Grain
TG.Month)
         , (Text
"ráithe (grain)", String
"r(á|a)ith(e|(í|i))", Grain
TG.Quarter)
         , (Text
"bliain (grain)", String
"m?bh?lia(in|na|nta)", Grain
TG.Year)
         ]

rules :: [Rule]
rules :: [Rule]
rules = ((Text, String, Grain) -> Rule)
-> [(Text, String, Grain)] -> [Rule]
forall a b. (a -> b) -> [a] -> [b]
map (Text, String, Grain) -> Rule
go [(Text, String, Grain)]
grains
  where
    go :: (Text, String, Grain) -> Rule
go (Text
name, String
regexPattern, Grain
grain) = Rule :: Text -> Pattern -> Production -> Rule
Rule
      { name :: Text
name = Text
name
      , pattern :: Pattern
pattern = [String -> PatternItem
regex String
regexPattern]
      , prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Dimension Grain -> Grain -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension Grain
TimeGrain Grain
grain
      }