{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.TimeGrain.PL.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
"second (grain)", String
"sekund(y|zie|(e|ę)|om|ami|ach|o|a)?|s", Grain
TG.Second)
, (Text
"minute (grain)", String
"minut(y|cie|(e|ę)|om|o|ami|ach|(a|ą))?|m", Grain
TG.Minute)
, (Text
"hour (grain)", String
"h|godzin(y|(e|ę)|ie|om|o|ami|ach|(a|ą))?", Grain
TG.Hour)
, (Text
"day (grain)", String
"dzie(n|ń|ni(a|ą))|dni(owi|ach|a|ą)?", Grain
TG.Day)
, (Text
"week (grain)", String
"tydzie(n|ń|)|tygod(ni(owi|u|a|em))|tygodn(iach|iami|iom|ie|i)|tyg\\.?", Grain
TG.Week)
, (Text
"month (grain)", String
"miesi(a|ą)c(owi|em|u|e|om|ami|ach|a)?", Grain
TG.Month)
, (Text
"quarter (grain)", String
"kwarta(l|ł)(u|owi|em|e|(o|ó)w|om|ach|ami|y)?", Grain
TG.Quarter)
, (Text
"year (grain)", String
"rok(u|owi|iem)?|lat(ami|ach|a|om)?", 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
}