-- 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 NoRebindableSyntax #-}
{-# LANGUAGE OverloadedStrings #-}

module Duckling.Time.EL.Rules
  ( rules
  ) where

import Data.HashMap.Strict (HashMap)
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.Duration.Helpers (duration, isGrain)
import Duckling.Duration.Types (DurationData(DurationData))
import Duckling.Numeral.Helpers (parseInt, numeralMapEL)
import Duckling.Numeral.Types (NumeralData(..))
import Duckling.Ordinal.Types (OrdinalData(..), isBetween)
import Duckling.Regex.Types
import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData(..))
import Duckling.Types
import qualified Duckling.Numeral.Types as TNumeral
import qualified Duckling.Ordinal.Types as TOrdinal
import qualified Duckling.Time.Types as TTime
import qualified Duckling.TimeGrain.Types as TG

ruleInstants :: [Rule]
ruleInstants :: [Rule]
ruleInstants = [(Text, Grain, Int, String)] -> [Rule]
mkRuleInstants
  [ ( Text
"now"             , Grain
TG.Second,  Int
0, String
"(αμέσως\\s+)?τώρα(\\s+αμέσως)?|αυτή τη στιγμή" )
  , ( Text
"today"           , Grain
TG.Day   ,  Int
0, String
"σήμερα"                   )
  , ( Text
"tomorrow"        , Grain
TG.Day   ,  Int
1, String
"(επ)?αύριο"               )
  , ( Text
"yesterday"       , Grain
TG.Day   , -Int
1, String
"ε?χ[θτ][εέ]ς"             )
  , ( Text
"after tomorrow"  , Grain
TG.Day   ,  Int
2, String
"μεθαύριο"                 )
  , ( Text
"before yesterday", Grain
TG.Day   , -Int
2, String
"προχ[θτ]ές"               )
  , ( Text
"EOD|End of day"  , Grain
TG.Day   ,  Int
1, String
"τέλου?ς\\s+της\\s+η?μέρας")
  , ( Text
"EOM|End of month", Grain
TG.Month ,  Int
1, String
"τέλου?ς\\s+του\\s+μήνα"   )
  , ( Text
"EOY|End of year" , Grain
TG.Year  ,  Int
1, String
"τέλου?ς\\s+του\\s+χρόνου" )
  ]

daysOfWeek :: [(Text, String)]
daysOfWeek :: [(Text, String)]
daysOfWeek =
  [ ( Text
"monday"    , String
"δευτ(έρας?|\\.?)"          )
  , ( Text
"tuesday"   , String
"τρ[ιί](της?|\\.?)"         )
  , ( Text
"wednesday" , String
"τετ(άρτης?|\\.?)"          )
  , ( Text
"thursday"  , String
"π[εέ]μ(πτης?|\\.?)"        )
  , ( Text
"friday"    , String
"παρ(ασκευής?|\\.?)"        )
  , ( Text
"saturday"  , String
"σ[αά]β(β[αά]το[νυ]?|\\.?)" )
  , ( Text
"sunday"    , String
"κυρ(ιακής?|\\.?)"          )
  ]

ruleDaysOfWeek :: [Rule]
ruleDaysOfWeek :: [Rule]
ruleDaysOfWeek = ((Text, String) -> Int -> Rule)
-> [(Text, String)] -> [Int] -> [Rule]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (Text, String) -> Int -> Rule
go [(Text, String)]
daysOfWeek [Int
1..Int
7]
  where
    go :: (Text, String) -> Int -> Rule
go (Text
name, String
regexPattern) Int
i = Rule :: Text -> Pattern -> Production -> Rule
Rule
      { name :: Text
name = Text
name
      , pattern :: Pattern
pattern = [String -> PatternItem
regex String
regexPattern]
      , prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production)
-> (TimeData -> Maybe Token) -> TimeData -> Production
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkOkForThisNext (TimeData -> Production) -> TimeData -> Production
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
dayOfWeek Int
i
      }

months :: [(Text, String)]
months :: [(Text, String)]
months =
  [ ( Text
"January"  , String
"ιαν(ου[αά]ρ[ιί]ο[υς]?)?|γενάρης?"    )
  , ( Text
"February" , String
"φεβ(ρου[αά]ρ[ιί]ο[υς]?)?|φλεβάρης?"  )
  , ( Text
"March"    , String
"μ[αά]ρ(τ([ιί]ο([νυ]?)|η)ς?)?"        )
  , ( Text
"April"    , String
"απρ([ιί]λ([ιί]ο([νυ]?)|η)ς?)?"       )
  , ( Text
"May"      , String
"μ[αά]([ιίϊΐ]ο[νυ]?|η)ς?"             )
  , ( Text
"June"     , String
"ιο[υύ]ν([ιί]ο[υν]?|η)?ς?"            )
  , ( Text
"July"     , String
"ιο[υύ]λ([ιί]ο[υν]?|η)?ς?"            )
  , ( Text
"August"   , String
"α[υύ]γ(ο[υύ]στο(ν|υ|ς)?)?"           )
  , ( Text
"September", String
"σεπτ([εέ]μβρ([ιί]ο([νυ]?)|η)ς?)?"    )
  , ( Text
"October"  , String
"οκτ([ωώ]βρ([ιί]ο([νυ]?)|η)ς?)?"      )
  , ( Text
"November" , String
"νο[εέ](μ(βρ([ιί]ο([νυ]?)|η)ς?)?)?"   )
  , ( Text
"December" , String
"δεκ([εέ]μβρ([ιί]ο([νυ]?)|η)ς?)?"     )
  ]

ruleMonths :: [Rule]
ruleMonths :: [Rule]
ruleMonths = ((Text, String) -> Int -> Rule)
-> [(Text, String)] -> [Int] -> [Rule]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (Text, String) -> Int -> Rule
go [(Text, String)]
months [Int
1..Int
12]
  where
    go :: (Text, String) -> Int -> Rule
go (Text
name, String
regexPattern) Int
i = Rule :: Text -> Pattern -> Production -> Rule
Rule
      { name :: Text
name = Text
name
      , pattern :: Pattern
pattern = [String -> PatternItem
regex String
regexPattern]
      , prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production)
-> (TimeData -> Maybe Token) -> TimeData -> Production
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkOkForThisNext (TimeData -> Production) -> TimeData -> Production
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
month Int
i
      }

ruleSeasons :: [Rule]
ruleSeasons :: [Rule]
ruleSeasons = [(Text, String, TimeData, TimeData)] -> [Rule]
mkRuleSeasons
  [ ( Text
"summer" , String
"καλοκα[ιί]ρι(ού)?", Int -> Int -> TimeData
monthDay  Int
6 Int
21, Int -> Int -> TimeData
monthDay  Int
9 Int
23 )
  , ( Text
"fall"   , String
"φθιν[οό]π[ωώ]ρου?", Int -> Int -> TimeData
monthDay  Int
9 Int
23, Int -> Int -> TimeData
monthDay Int
12 Int
21 )
  , ( Text
"winter" , String
"χειμώνας?"        , Int -> Int -> TimeData
monthDay Int
12 Int
21, Int -> Int -> TimeData
monthDay  Int
3 Int
20 )
  , ( Text
"spring" , String
"άνοιξης?"         , Int -> Int -> TimeData
monthDay  Int
3 Int
20, Int -> Int -> TimeData
monthDay  Int
6 Int
21 )
  ]

ruleHolidays :: [Rule]
ruleHolidays :: [Rule]
ruleHolidays = ((Text, TimeData, String) -> Rule)
-> [(Text, TimeData, String)] -> [Rule]
forall a b. (a -> b) -> [a] -> [b]
map (Text, TimeData, String) -> Rule
go [(Text, TimeData, String)]
holidays
  where
    go :: (Text, TimeData, String) -> Rule
go (Text
name, TimeData
td, String
regexPattern) = Rule :: Text -> Pattern -> Production -> Rule
Rule
      { name :: Text
name = Text
name
      , pattern :: Pattern
pattern = [String -> PatternItem
regex String
regexPattern]
      , prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production)
-> (TimeData -> Maybe Token) -> TimeData -> Production
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> Maybe Token
tt (TimeData -> Production) -> TimeData -> Production
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
mkOkForThisNext TimeData
td
      }

holidays :: [(Text, TimeData, String)]
holidays :: [(Text, TimeData, String)]
holidays =
  [ (Text
"new year's day"   , Int -> Int -> TimeData
monthDay Int
1 Int
1, String
"πρωτοχρονιάς?")
  , (Text
"valentine's day"  , Int -> Int -> TimeData
monthDay Int
2 Int
14, String
"αγίου\\s+βαλεντίνου")
  , (Text
"halloween day"    , Int -> Int -> TimeData
monthDay Int
10 Int
31, String
"halloween")
  , (Text
"Epiphany"         , Int -> Int -> TimeData
monthDay Int
1 Int
6, String
"θεοφ(αά)νε[ιί](α|ων)|φ[ωώ]τ(α|ων)")
  , (Text
"annunciation day" , Int -> Int -> TimeData
monthDay Int
3 Int
25, String
"ευαγγελισμ(ός|ού)\\s+της\\s+θεοτόκου")
  , (Text
"revolution day"   , Int -> Int -> TimeData
monthDay Int
3 Int
25
                        , String
"η?μέρα\\s+(της\\s+)?(ελληνικής\\s+)?επανάστασης")
  , (Text
"assumption day"   , Int -> Int -> TimeData
monthDay  Int
8 Int
15
                        , String
"κο[ιί]μ[ηή]σ(η|ις|εως)\\s+της\\s+θεοτόκου")
  , (Text
"christmas eve"    , Int -> Int -> TimeData
monthDay Int
12 Int
24, String
"παραμν(ή|έ)ς?\\s+χριστουγέννων")
  , (Text
"christmas"        , Int -> Int -> TimeData
monthDay Int
12 Int
25, String
"χριστο[υύ]γ[εέ]νν(α|ων)")
  , (Text
"new year's eve"   , Int -> Int -> TimeData
monthDay Int
12 Int
31, String
"παραμον(ή|έ)ς?\\s+πρωτοχρονιάς")
  , (Text
"Mother's Day"     , Int -> Int -> Int -> TimeData
nthDOWOfMonth Int
2 Int
7 Int
5, String
"η?μέρας?\\s+της\\s+μητέρας")
  , (Text
"Father's Day"     , Int -> Int -> Int -> TimeData
nthDOWOfMonth Int
3 Int
7 Int
6
                        , String
"(γιορτής?|η?μέρας?)\\s+του\\s+πατέρα")
  ]

ruleRelativeIntegerToOrAfterIntegerPartOfDay :: Rule
ruleRelativeIntegerToOrAfterIntegerPartOfDay :: Rule
ruleRelativeIntegerToOrAfterIntegerPartOfDay = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"relative integer (minutes) to|till|before|after <integer> (time-of-day)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
30
    , String -> PatternItem
regex String
"(πριν|μετά)"
    , Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Numeral NumeralData{TNumeral.value = v}:
       Token Dimension a
RegexMatch (GroupMatch (match:_)):
       Token Dimension a
Time a
td:
       [Token]
_) -> case Text -> Text
Text.toLower Text
match of
        Text
"πριν" -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData -> TimeData
durationBefore (Grain -> Int -> DurationData
duration Grain
TG.Minute (Int -> DurationData) -> Int -> DurationData
forall a b. (a -> b) -> a -> b
$ Double -> Int
forall a b. (RealFrac a, Integral b) => a -> b
floor Double
v) a
TimeData
td
        Text
_      -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData -> TimeData
durationAfter (Grain -> Int -> DurationData
duration Grain
TG.Minute (Int -> DurationData) -> Int -> DurationData
forall a b. (a -> b) -> a -> b
$ Double -> Int
forall a b. (RealFrac a, Integral b) => a -> b
floor Double
v) a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleQuarterBeforeOrAfterIntegerHourofday :: Rule
ruleQuarterBeforeOrAfterIntegerHourofday :: Rule
ruleQuarterBeforeOrAfterIntegerHourofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"quarter to|past <integer> (hour-of-day)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"(παρά|και)\\s+τέταρτο"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:
       Token Dimension a
RegexMatch (GroupMatch (match:_)):
       [Token]
_) -> case Text -> Text
Text.toLower Text
match of
        Text
"παρά" -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
15 a
TimeData
td
        Text
_      -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> TimeData -> Maybe TimeData
minutesAfter  Int
15 a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHalfAfterIntegerHourofday :: Rule
ruleHalfAfterIntegerHourofday :: Rule
ruleHalfAfterIntegerHourofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"half after|past <integer> (hour-of-day)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"και μισή"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
       [Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
30
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHalfAfterIntegerHourofday2 :: Rule
ruleHalfAfterIntegerHourofday2 :: Rule
ruleHalfAfterIntegerHourofday2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<integer>-and-half (hour-of-day)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex (String -> PatternItem) -> String -> PatternItem
forall a b. (a -> b) -> a -> b
$ String
"(μιά|ενά|δυό|τρεισή|τεσσερι?σή|πεντέ|εξί|ε[πφ]τά|ο[κχ]τώ|εννιά|"
           String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"δεκά|εντεκά|δωδεκά)μισ[ιη]ς?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (num:_)):[Token]
_) ->
        case 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
num) HashMap Text Int
numeralMapEL of
          Just Int
hours -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
True Int
hours Int
30
          Maybe Int
_ -> Maybe Token
forall a. Maybe a
Nothing
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleOrdinalCycleOfTime :: Rule
ruleOrdinalCycleOfTime :: Rule
ruleOrdinalCycleOfTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<ordinal> <cycle> of <time>"
  , pattern :: Pattern
pattern =
    [ Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Ordinal a
od:Token Dimension a
TimeGrain a
grain:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
True a
Grain
grain (OrdinalData -> Int
TOrdinal.value a
OrdinalData
od Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleLastTime :: Rule
ruleLastTime :: Rule
ruleLastTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"last <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(τελευταί|περασμέν|προηγο[υύ]μ[εέ]ν)(α|ά|ο[υύ]?|η|ή|ε|έ|ω|ώ)ν?ς?"
    , Predicate -> PatternItem
Predicate Predicate
isOkWithThisNext
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth (-Int
1) Bool
False a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDatetimeDatetimeInterval :: Rule
ruleDatetimeDatetimeInterval :: Rule
ruleDatetimeDatetimeInterval = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<datetime> - <datetime> (interval)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , String -> PatternItem
regex String
"\\-|μ[εέ](χρι)?(\\s+τις)?"
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
notLatent (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleEvening :: Rule
ruleEvening :: Rule
ruleEvening = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"evening"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"βράδυ"
    ]
  , prod :: Production
prod = \[Token]
_ ->
      let from :: TimeData
from = Bool -> Int -> TimeData
hour Bool
False Int
18
          to :: TimeData
to = Bool -> Int -> TimeData
hour Bool
False Int
0
      in Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> TimeData)
-> (TimeData -> TimeData) -> TimeData -> TimeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
           TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
from TimeData
to
  }

ruleTheDayofmonthNonOrdinal :: Rule
ruleTheDayofmonthNonOrdinal :: Rule
ruleTheDayofmonthNonOrdinal = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"the <day-of-month> (non ordinal)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"τ?η[νς]?"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
31
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
token:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (Int -> TimeData) -> Int -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> TimeData
dayOfMonth (Int -> Token) -> Maybe Int -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Token -> Maybe Int
getIntValue Token
token
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

rulePartOfMonth :: Rule
rulePartOfMonth :: Rule
rulePartOfMonth = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"part of <named-month>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(αρχ(?:ές|η)|μέσ[οα]υ?|τέλ(?:ου?ς|η))(?:\\s+του)?"
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (match:_)):Token Dimension a
Time a
td:[Token]
_) -> do
        (Int
sd, Int
ed) <- case Int -> Text -> Text
Text.take Int
3 (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Text
Text.toLower Text
match of
          Text
"αρχ" -> (Int, Int) -> Maybe (Int, Int)
forall a. a -> Maybe a
Just (Int
1, Int
10)
          Text
"μέσ" -> (Int, Int) -> Maybe (Int, Int)
forall a. a -> Maybe a
Just (Int
11, Int
20)
          Text
"τέλ" -> (Int, Int) -> Maybe (Int, Int)
forall a. a -> Maybe a
Just (Int
21, -Int
1)
          Text
_     -> Maybe (Int, Int)
forall a. Maybe a
Nothing
        TimeData
start <- TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td (TimeData -> Maybe TimeData) -> TimeData -> Maybe TimeData
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
dayOfMonth Int
sd
        TimeData
end <- if Int
ed Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= -Int
1
          then TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td (TimeData -> Maybe TimeData) -> TimeData -> Maybe TimeData
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
dayOfMonth Int
ed
          else TimeData -> Maybe TimeData
forall a. a -> Maybe a
Just (TimeData -> Maybe TimeData) -> TimeData -> Maybe TimeData
forall a b. (a -> b) -> a -> b
$ Grain -> TimeData -> TimeData
cycleLastOf Grain
TG.Day a
TimeData
td
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
start TimeData
end
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleInDuration :: Rule
ruleInDuration :: Rule
ruleInDuration = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"in <duration>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"σε"
    , Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Duration a
dd:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData
inDuration a
DurationData
dd
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleLastCycleOfTime :: Rule
ruleLastCycleOfTime :: Rule
ruleLastCycleOfTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"last <cycle> of <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"τελευταί(ο[ιυ]?ς?|α|ες|ων)"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"σ?τ(ο[υν]?|η[νς]?|ων)"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
TimeGrain a
grain:Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> TimeData -> TimeData
cycleLastOf a
Grain
grain a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleLastCycleOfTimeS :: Rule
ruleLastCycleOfTimeS :: Rule
ruleLastCycleOfTimeS = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"last <cycle> <time>'s'"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"τελευταί(ο[ιυ]?ς?|α|ες|ων)"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
TimeGrain a
grain:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> TimeData -> TimeData
cycleLastOf a
Grain
grain a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleFromDatetimeDatetimeInterval :: Rule
ruleFromDatetimeDatetimeInterval :: Rule
ruleFromDatetimeDatetimeInterval = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"from <datetime> - <datetime> (interval)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"από(\\s+τ(ις|η))?"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and ([Bool] -> Bool) -> (Token -> [Bool]) -> Predicate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Predicate] -> Token -> [Bool]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Predicate
isNotLatent, Predicate
isATimeOfDay]
    , String -> PatternItem
regex String
"\\-|μέχρι(\\s+τ(ις|η))?"
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

-- Specific for time-of-day, to help resolve ambiguities
ruleIntervalTODDash :: Rule
ruleIntervalTODDash :: Rule
ruleIntervalTODDash = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time-of-day> - <time-of-day> (interval)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and ([Bool] -> Bool) -> (Token -> [Bool]) -> Predicate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Predicate] -> Token -> [Bool]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Predicate
isNotLatent, Predicate
isATimeOfDay]
    , String -> PatternItem
regex String
"\\-|μέχρι"
    , Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleMonthDdddInterval :: Rule
ruleMonthDdddInterval :: Rule
ruleMonthDdddInterval = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"dd-dd <month> (interval)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(από\\s+)?(τ[ιη][νς]?\\s+)?([012]?\\d|30|31)η?ς?"
    , String -> PatternItem
regex String
"\\-|μ[εέ](χρι)?(?:\\s+τ[ιη][νς]?)?"
    , String -> PatternItem
regex String
"([012]?\\d|30|31)η?ς?"
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (_:_:m1:_)):
       Token
_:
       Token Dimension a
RegexMatch (GroupMatch (m2:_)):
       Token Dimension a
Time a
td:
       [Token]
_) -> do
        Int
v1 <- Text -> Maybe Int
parseInt Text
m1
        Int
v2 <- Text -> Maybe Int
parseInt Text
m2
        TimeData
from <- TimeData -> TimeData -> Maybe TimeData
intersect (Int -> TimeData
dayOfMonth Int
v1) a
TimeData
td
        TimeData
to <- TimeData -> TimeData -> Maybe TimeData
intersect (Int -> TimeData
dayOfMonth Int
v2) a
TimeData
td
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed TimeData
from TimeData
to
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTheCycleAfterTime :: Rule
ruleTheCycleAfterTime :: Rule
ruleTheCycleAfterTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"the <cycle> after <time>"
  , pattern :: Pattern
pattern =
    [ Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"μετά τ(ου?|η|ι|α|ου)ν?ς?"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
TimeGrain a
grain:Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False a
Grain
grain Int
1 a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTheCycleOfTime :: Rule
ruleTheCycleOfTime :: Rule
ruleTheCycleOfTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"the <cycle> of <time>"
  , pattern :: Pattern
pattern =
    [ Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"τ(ου|ης)"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
TimeGrain a
grain:Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
True a
Grain
grain Int
0 a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTheCycleBeforeTime :: Rule
ruleTheCycleBeforeTime :: Rule
ruleTheCycleBeforeTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"the <cycle> before <time>"
  , pattern :: Pattern
pattern =
    [ Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"πριν τ(ον?|ην?|α|ους)"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
TimeGrain a
grain:Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False a
Grain
grain (-Int
1) a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleYearLatent2 :: Rule
ruleYearLatent2 :: Rule
ruleYearLatent2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"year (latent)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
2101 Int
10000
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
year Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimeAfterNext :: Rule
ruleTimeAfterNext :: Rule
ruleTimeAfterNext = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time> after next"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"μεθεπ[οό]μ[εέ]ν(ο[ιυ]?ς?|ης?|ων)"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth Int
2 Bool
True a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleThisDayofWeek :: Rule
ruleThisDayofWeek :: Rule
ruleThisDayofWeek = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"this <day-of-week>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"αυτή[νς]? τη[νς]?"
    , Predicate -> PatternItem
Predicate Predicate
isADayOfWeek
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth Int
0 Bool
True a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTheDayOf :: Rule
ruleTheDayOf :: Rule
ruleTheDayOf = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"on the day of <day>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"ανήμερα"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Grain -> Predicate
isGrainOfTime Grain
TG.Day
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth Int
0 Bool
True a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleThisDayofWeek2 :: Rule
ruleThisDayofWeek2 :: Rule
ruleThisDayofWeek2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"(this) coming <day-of-week>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"ερχ[οό]μ[εέ]νη[ςν]?"
    , Predicate -> PatternItem
Predicate Predicate
isADayOfWeek
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth Int
0 Bool
True a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleBetweenTimeofdayAndTimeofdayInterval :: Rule
ruleBetweenTimeofdayAndTimeofdayInterval :: Rule
ruleBetweenTimeofdayAndTimeofdayInterval = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"between <time-of-day> and <time-of-day> (interval)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"μεταξύ|ανάμεσα"
    , Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"(και(\\s+τ(ου|ης))?|\\-)"
    , Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNextCycle :: Rule
ruleNextCycle :: Rule
ruleNextCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"next <cycle>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"ε(π|ρχ)[οό]μ[εέ]ν(ο[ιυ]?ς?|ης?|ες|ων)"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
TimeGrain a
grain:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth a
Grain
grain Int
1
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimeofdayApproximately :: Rule
ruleTimeofdayApproximately :: Rule
ruleTimeofdayApproximately = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time-of-day> approximately"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"περίπου|και κάτι"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
notLatent a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleInDurationFromTime :: Rule
ruleInDurationFromTime :: Rule
ruleInDurationFromTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"in <duration> from <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"σε"
    , Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    , String -> PatternItem
regex String
"(ξεκινώντας\\s+)?από"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Duration a
dd:Token
_:Token Dimension a
Time a
td1:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData -> TimeData
durationAfter a
DurationData
dd a
TimeData
td1
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}

ruleDurationFromNow :: Rule
ruleDurationFromNow :: Rule
ruleDurationFromNow = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<duration> from now"
  , pattern :: Pattern
pattern =
    [ Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    , String -> PatternItem
regex String
"από τώρα"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Duration a
dd:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData
inDuration a
DurationData
dd
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleLunch :: Rule
ruleLunch :: Rule
ruleLunch = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"lunch"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"μεσημεριαν(ό|ού)( γεύμα(τος)?)?"
    ]
  , prod :: Production
prod = \[Token]
_ ->
      let from :: TimeData
from = Bool -> Int -> TimeData
hour Bool
False Int
12
          to :: TimeData
to = Bool -> Int -> TimeData
hour Bool
False Int
14
      in Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> TimeData)
-> (TimeData -> TimeData) -> TimeData -> TimeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
           TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
from TimeData
to
  }

ruleLastCycle :: Rule
ruleLastCycle :: Rule
ruleLastCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"last <cycle>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"τελευταί(ου?|ας?)"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
TimeGrain a
grain:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (Int -> TimeData) -> Int -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Grain -> Int -> TimeData
cycleNth a
Grain
grain (Int -> Maybe Token) -> Int -> Maybe Token
forall a b. (a -> b) -> a -> b
$ - Int
1
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleAfternoon :: Rule
ruleAfternoon :: Rule
ruleAfternoon = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"afternoon"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"απ[οό]γε[υύ]μα(τος)?"
    ]
  , prod :: Production
prod = \[Token]
_ ->
      let from :: TimeData
from = Bool -> Int -> TimeData
hour Bool
False Int
12
          to :: TimeData
to = Bool -> Int -> TimeData
hour Bool
False Int
18
      in Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> TimeData)
-> (TimeData -> TimeData) -> TimeData -> TimeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
           TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
from TimeData
to
  }

ruleDayofmonthOrdinalNamedmonth :: Rule
ruleDayofmonthOrdinalNamedmonth :: Rule
ruleDayofmonthOrdinalNamedmonth = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<day-of-month> (ordinal or number) <named-month>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isDOMValue
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
day:Token Dimension a
Time a
month:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
month Token
day
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNamedmonthDayofmonth :: Rule
ruleNamedmonthDayofmonth :: Rule
ruleNamedmonthDayofmonth = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<named-month> <day-of-month> (ordinal or number)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAMonth
    , Predicate -> PatternItem
Predicate Predicate
isDOMValue
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
month:Token
day:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
month Token
day
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }


ruleInduringThePartofday :: Rule
ruleInduringThePartofday :: Rule
ruleInduringThePartofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"in|during the <part-of-day>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"κατά τη διάρκεια του|(μέσα )?σ?το"
    , Predicate -> PatternItem
Predicate Predicate
isAPartOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
notLatent a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayIntegerAsRelativeMinutes :: Rule
ruleHourofdayIntegerAsRelativeMinutes :: Rule
ruleHourofdayIntegerAsRelativeMinutes = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> <integer> (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and ([Bool] -> Bool) -> (Token -> [Bool]) -> Predicate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Predicate] -> Token -> [Bool]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Predicate
isNotLatent, Predicate
isAnHourOfDay]
    , String -> PatternItem
regex String
"και"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
59
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData
       {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:Token
_:
       Token
token:
       [Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
n
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNthTimeAfterTime :: Rule
ruleNthTimeAfterTime :: Rule
ruleNthTimeAfterTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"nth <time> after <time>"
  , pattern :: Pattern
pattern =
    [ Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or ([Bool] -> Bool) -> (Token -> [Bool]) -> Predicate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Predicate] -> Token -> [Bool]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence
        [ Predicate
isADayOfWeek
        , Predicate
isAMonth
        ]
    , String -> PatternItem
regex String
"μετά"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Ordinal OrdinalData{TOrdinal.value = v}:
       Token Dimension a
Time a
td1:
       Token
_:
       Token Dimension a
Time a
td2:
       [Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData -> TimeData -> TimeData
predNthAfter (Int
v Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleMmdd :: Rule
ruleMmdd :: Rule
ruleMmdd = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"dd/mm"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(3[01]|[12]\\d|0?[1-9])\\s?[/.-]\\s?(1[0-2]|0?[1-9])"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (m1:m2:_)):[Token]
_) -> do
        Int
d <- Text -> Maybe Int
parseInt Text
m1
        Int
m <- Text -> Maybe Int
parseInt Text
m2
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> TimeData
monthDay Int
m Int
d
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleAfterDuration :: Rule
ruleAfterDuration :: Rule
ruleAfterDuration = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"after <duration>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"μετά\\s+από"
    , Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Duration a
dd:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntervalDirection -> TimeData -> TimeData
withDirection IntervalDirection
TTime.After (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData
inDuration a
DurationData
dd
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimeofdayLatent :: Rule
ruleTimeofdayLatent :: Rule
ruleTimeofdayLatent = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"time-of-day (latent)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
0 Int
23
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:[Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> TimeData
hour (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
12) Int
n
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleExactlyTimeofday :: Rule
ruleExactlyTimeofday :: Rule
ruleExactlyTimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"exactly <time-of-day>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"ακριβώς"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
notLatent a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleBetweenDatetimeAndDatetimeInterval :: Rule
ruleBetweenDatetimeAndDatetimeInterval :: Rule
ruleBetweenDatetimeAndDatetimeInterval = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"between <datetime> and <datetime> (interval)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"μεταξύ|ανάμεσα"
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , String -> PatternItem
regex String
"(και|\\-)"
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDurationHenceAgo :: Rule
ruleDurationHenceAgo :: Rule
ruleDurationHenceAgo = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<duration> hence|ago"
  , pattern :: Pattern
pattern =
    [ Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    , String -> PatternItem
regex String
"(πριν|μετά)"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Duration a
dd:
       Token Dimension a
RegexMatch (GroupMatch (match:_)):
       [Token]
_) -> case Text -> Text
Text.toLower Text
match of
        Text
"πριν" -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData
durationAgo a
DurationData
dd
        Text
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData
inDuration a
DurationData
dd
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHenceAgoDuration :: Rule
ruleHenceAgoDuration :: Rule
ruleHenceAgoDuration = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"before <duration>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(πριν(\\s+από)?|εδώ και)"
    , Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (match:_)):
       Token Dimension a
Duration a
dd:
       [Token]
_) -> case Text -> Text
Text.toLower Text
match of
        Text
"εδώ και" -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData
inDuration a
DurationData
dd
        Text
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData
durationAgo a
DurationData
dd
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleIntervalUntilTOD :: Rule
ruleIntervalUntilTOD :: Rule
ruleIntervalUntilTOD = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"until <time-of-day>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"πριν"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ IntervalDirection -> TimeData -> TimeData
withDirection IntervalDirection
TTime.Before a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleByTheEndOfTime :: Rule
ruleByTheEndOfTime :: Rule
ruleByTheEndOfTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"by the end of <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"μέχρι το (τέλος|πέρας)"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed a
TimeData
td TimeData
now
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleAfterWork :: Rule
ruleAfterWork :: Rule
ruleAfterWork = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"after work"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"μετά τη δουλειά"
    ]
  , prod :: Production
prod = \[Token]
_ -> do
      TimeData
td2 <- TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open (Bool -> Int -> TimeData
hour Bool
False Int
17) (Bool -> Int -> TimeData
hour Bool
False Int
21)
      Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect TimeData
today TimeData
td2
  }

ruleLastNCycle :: Rule
ruleLastNCycle :: Rule
ruleLastNCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"last n <cycle>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(τελευταί|περασμέν)(ο[ιυ]?ς?|[εα]ς?|ων)"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
9999
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
token:Token Dimension a
TimeGrain a
grain:[Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData
cycleN Bool
True a
Grain
grain (- Int
n)
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleWithinDuration :: Rule
ruleWithinDuration :: Rule
ruleWithinDuration = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"within <duration>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"μέσα(\\s+σε)?"
    , Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Duration a
dd:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
        TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
now (DurationData -> TimeData
inDuration a
DurationData
dd)
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleMidnight :: Rule
ruleMidnight :: Rule
ruleMidnight = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"midnight"
  , pattern :: Pattern
pattern =
      [ String -> PatternItem
regex String
"μεσάνυχτα"
      ]
  , prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> TimeData
hour Bool
False Int
0
  }

ruleNoon :: Rule
ruleNoon :: Rule
ruleNoon = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"noon"
  , pattern :: Pattern
pattern =
      [ String -> PatternItem
regex String
"μεσημ[εέ]ρι(ού)?"
      ]
  , prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$ TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> TimeData
hour Bool
False Int
12
  }

ruleDayofmonthNonOrdinalNamedmonth :: Rule
ruleDayofmonthNonOrdinalNamedmonth :: Rule
ruleDayofmonthNonOrdinalNamedmonth = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<day-of-month> (non-ordinal) <named-month>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isDOMInteger
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:Token
token:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
td Token
token
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

rulePrecisionTimeofday :: Rule
rulePrecisionTimeofday :: Rule
rulePrecisionTimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"about <time-of-day>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"περίπου|ακριβώς"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Grain -> Predicate
isGrainFinerThan Grain
TG.Year
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
notLatent a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleIntervalBy :: Rule
ruleIntervalBy :: Rule
ruleIntervalBy = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"until <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"μέχρι"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
now a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleIntervalByTheEndOf :: Rule
ruleIntervalByTheEndOf :: Rule
ruleIntervalByTheEndOf = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"by the end of <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"μέχρι το τέλος"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed TimeData
now a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleUntilTimeofdayPostfix :: Rule
ruleUntilTimeofdayPostfix :: Rule
ruleUntilTimeofdayPostfix = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time-of-day> until"
  , pattern :: Pattern
pattern =
    [ Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    , String -> PatternItem
regex String
"το αργότερο"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ IntervalDirection -> TimeData -> TimeData
withDirection IntervalDirection
TTime.Before a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleAtTimeofday :: Rule
ruleAtTimeofday :: Rule
ruleAtTimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"at <time-of-day>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"στις|@"
    , Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
notLatent a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNthTimeOfTime :: Rule
ruleNthTimeOfTime :: Rule
ruleNthTimeOfTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"nth <time> of <time>"
  , pattern :: Pattern
pattern =
    [ Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , String -> PatternItem
regex String
"τ(ου|ης|ων)"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Ordinal OrdinalData{TOrdinal.value = v}:
       Token Dimension a
Time a
td1:
       Token
_:
       Token Dimension a
Time a
td2:
       [Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Bool -> TimeData -> TimeData
predNth (Int
v Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Bool
False (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td2 a
TimeData
td1
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimePartofday :: Rule
ruleTimePartofday :: Rule
ruleTimePartofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time> <part-of-day>"
  , pattern :: Pattern
pattern =
    [ Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    , Predicate -> PatternItem
Predicate Predicate
isAPartOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleWeekend :: Rule
ruleWeekend :: Rule
ruleWeekend = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"week-end"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"σαββατοκύριακ(ου?|α|ων)|σκ"
    ]
  , prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production)
-> (TimeData -> Maybe Token) -> TimeData -> Production
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkOkForThisNext (TimeData -> Production) -> TimeData -> Production
forall a b. (a -> b) -> a -> b
$ TimeData
weekend
  }

ruleLastWeekendOfMonth :: Rule
ruleLastWeekendOfMonth :: Rule
ruleLastWeekendOfMonth = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"last weekend of <named-month>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"τελευταίου?\\s+(σαββατοκύριακου?|σκ)\\s+"
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td2:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData -> TimeData
predLastOf TimeData
weekend a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNextDayofweek :: Rule
ruleNextDayofweek :: Rule
ruleNextDayofweek = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"next <day-of-week>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"επ[οό]μ[εέ]ν(ο[ιυ]?ς?|ης?|ες|ων)"
    , Predicate -> PatternItem
Predicate Predicate
isADayOfWeek
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth Int
1 Bool
False a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNextTime :: Rule
ruleNextTime :: Rule
ruleNextTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"next <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"επ[οό]μ[εέ]ν(ο[ιυ]?ς?|ης?|ες|ων)"
    , Predicate -> PatternItem
Predicate Predicate
isOkWithThisNext
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth Int
1 Bool
False a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }


ruleOrdinalQuarterYear :: Rule
ruleOrdinalQuarterYear :: Rule
ruleOrdinalQuarterYear = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<ordinal> quarter <year>"
  , pattern :: Pattern
pattern =
    [ Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Grain -> Predicate
isGrain Grain
TG.Quarter
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Ordinal a
od:Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Quarter (OrdinalData -> Int
TOrdinal.value a
OrdinalData
od Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleYyyymmdd :: Rule
ruleYyyymmdd :: Rule
ruleYyyymmdd = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"yyyy-mm-dd"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(\\d{2,4})[.-](1[0-2]|0?[1-9])[.-](3[01]|[12]\\d|0?[1-9])"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (m1:m2:m3:_)):[Token]
_) -> do
        Int
y <- Text -> Maybe Int
parseInt Text
m1
        Int
m <- Text -> Maybe Int
parseInt Text
m2
        Int
d <- Text -> Maybe Int
parseInt Text
m3
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int -> TimeData
yearMonthDay Int
y Int
m Int
d
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleOrdinalCycleAfterTime :: Rule
ruleOrdinalCycleAfterTime :: Rule
ruleOrdinalCycleAfterTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<ordinal> <cycle> after <time>"
  , pattern :: Pattern
pattern =
    [ Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"μετά"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Ordinal a
od:Token Dimension a
TimeGrain a
grain:Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
True a
Grain
grain (OrdinalData -> Int
TOrdinal.value a
OrdinalData
od Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleIntersect :: Rule
ruleIntersect :: Rule
ruleIntersect = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"intersect"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleIntersectBy :: Rule
ruleIntersectBy :: Rule
ruleIntersectBy = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"intersect by ','"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , String -> PatternItem
regex String
","
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleIntersectByOfFromS :: Rule
ruleIntersectByOfFromS :: Rule
ruleIntersectByOfFromS = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"intersect by 'of', 'from', 's"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , String -> PatternItem
regex String
"τ(ου|ης)"
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNextNCycle :: Rule
ruleNextNCycle :: Rule
ruleNextNCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"next n <cycle>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"επ[οό]μ[εέ]ν(ο[ιυ]?ς?|ης?|ες|ων|α)"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
9999
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
token:Token Dimension a
TimeGrain a
grain:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData
cycleN Bool
True a
Grain
grain Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleADuration :: Rule
ruleADuration :: Rule
ruleADuration = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"a <duration>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"[εέ]ν(ας?|ός|ν)|μίας?"
    , Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Duration a
dd:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData
inDuration a
DurationData
dd
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleMorning :: Rule
ruleMorning :: Rule
ruleMorning = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"morning"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(το\\s+)?πρωί"
    ]
  , prod :: Production
prod = \[Token]
_ ->
      let from :: TimeData
from = Bool -> Int -> TimeData
hour Bool
False Int
4
          to :: TimeData
to = Bool -> Int -> TimeData
hour Bool
False Int
12
      in Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> TimeData)
-> (TimeData -> TimeData) -> TimeData -> TimeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
           TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
from TimeData
to
  }

ruleEarlyMorning :: Rule
ruleEarlyMorning :: Rule
ruleEarlyMorning = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"early morning"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"νωρίς\\s+(το\\s+)πρωί"
    ]
  , prod :: Production
prod = \[Token]
_ -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> TimeData)
-> (TimeData -> TimeData) -> TimeData -> TimeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
      TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open (Bool -> Int -> TimeData
hour Bool
False Int
4) (Bool -> Int -> TimeData
hour Bool
False Int
9)
  }


ruleThisPartofday :: Rule
ruleThisPartofday :: Rule
ruleThisPartofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"this <part-of-day>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"αυτ([οό]ύ?|ή[νς]?) τ(ον?|η[νς]?)"
    , Predicate -> PatternItem
Predicate Predicate
isAPartOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect TimeData
today a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleThisCycle :: Rule
ruleThisCycle :: Rule
ruleThisCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"this <cycle>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"αυτ([οό][νύ]?|ή[νς]?)\\s+τ(ον?|η[νς]?)"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
TimeGrain a
grain:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth a
Grain
grain Int
0
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDayofmonthNonOrdinalOfNamedmonth :: Rule
ruleDayofmonthNonOrdinalOfNamedmonth :: Rule
ruleDayofmonthNonOrdinalOfNamedmonth = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<day-of-month> (ordinal or number) of <named-month>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isDOMValue
    , String -> PatternItem
regex String
"του"
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
day:Token
_:Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
td Token
day
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleYearLatent :: Rule
ruleYearLatent :: Rule
ruleYearLatent = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"year (latent)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$
        [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or ([Bool] -> Bool) -> (Token -> [Bool]) -> Predicate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Predicate] -> Token -> [Bool]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Int -> Int -> Predicate
isIntegerBetween (- Int
10000) Int
0, Int -> Int -> Predicate
isIntegerBetween Int
25 Int
999]
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:[Token]
_) -> do
        Int
y <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
year Int
y
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleAfterTimeofday :: Rule
ruleAfterTimeofday :: Rule
ruleAfterTimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"after <time-of-day>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"μετά"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ IntervalDirection -> TimeData -> TimeData
withDirection IntervalDirection
TTime.After a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleCycleThis :: Rule
ruleCycleThis :: Rule
ruleCycleThis = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"this <cycle>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex (String -> PatternItem) -> String -> PatternItem
forall a b. (a -> b) -> a -> b
$ String
"αυτ([οό][υύ]?|[ηή]|[εέ]|ώ|ά)ν?ς?|"
           String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"τρ[εέ]χ(ουσ)?(α|ε|ο|ω|ώ)ν?ς?"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth Int
0 Bool
False a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

cyclesMap :: HashMap Text Int
cyclesMap :: HashMap Text Int
cyclesMap = [(Text, Int)] -> HashMap Text Int
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
  [ (Text
"τρεχ"      , Int
0)
  , (Text
"τρέχ"      , Int
0)
  , (Text
"ερχόμεν"   , Int
0)
  , (Text
"ερχομέν"   , Int
0)
  , (Text
"επόμεν"    , Int
1)
  , (Text
"επομέν"    , Int
1)
  , (Text
"περασμέν"  , -Int
1)
  , (Text
"προηγούμεν", -Int
1)
  , (Text
"προηγουμέν", -Int
1)
  ]

ruleCycleCurrentLastNext :: Rule
ruleCycleCurrentLastNext :: Rule
ruleCycleCurrentLastNext = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"this|last|next <cycle>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex (String -> PatternItem) -> String -> PatternItem
forall a b. (a -> b) -> a -> b
$ String
"(τρ[εέ]χ|επ[οό]μ[εέ]ν|ερχ[οό]μ[εέ]ν|περασμέν|προηγο[υύ]μ[εέ]ν)"
           String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"(ουσ)?(α|ά|ο[υύ]?|η|ή|ε|έ|ω|ώ)ν?ς?"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (match:_)):Token Dimension a
TimeGrain a
grain:[Token]
_) ->
        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
cyclesMap Maybe Int -> (Int -> Maybe Token) -> Maybe Token
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (Int -> TimeData) -> Int -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Grain -> Int -> TimeData
cycleNth a
Grain
grain
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNight :: Rule
ruleNight :: Rule
ruleNight = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"night"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"νύχτα"
    ]
  , prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production) -> Maybe Token -> Production
forall a b. (a -> b) -> a -> b
$
      let from :: TimeData
from = Bool -> Int -> TimeData
hour Bool
False Int
20
          to :: TimeData
to = Bool -> Int -> TimeData
hour Bool
False Int
8
      in Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> TimeData)
-> (TimeData -> TimeData) -> TimeData -> TimeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
           TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
from TimeData
to
  }

ruleDayofmonthOrdinal :: Rule
ruleDayofmonthOrdinal :: Rule
ruleDayofmonthOrdinal = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<day-of-month> (ordinal)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isDOMOrdinal
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Ordinal OrdinalData{TOrdinal.value = v}:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
dayOfMonth Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimeofdayAmpm :: Rule
ruleTimeofdayAmpm :: Rule
ruleTimeofdayAmpm = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time-of-day> am|pm"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"([πμ])\\.?(μ\\.?)?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:Token Dimension a
RegexMatch (GroupMatch (ap:_)):[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> TimeData -> TimeData
timeOfDayAMPM (Text -> Text
Text.toLower Text
ap Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"π") a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimeofdayAmpmVerbose :: Rule
ruleTimeofdayAmpmVerbose :: Rule
ruleTimeofdayAmpmVerbose = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time-of-day> am|pm (verbose)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"το\\s+(πρωί|απόγευμα)"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:Token Dimension a
RegexMatch (GroupMatch (ap:_)):[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> TimeData -> TimeData
timeOfDayAMPM (Text -> Text
Text.toLower Text
ap Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"πρωί") a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleAfterNextTime :: Rule
ruleAfterNextTime :: Rule
ruleAfterNextTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"after next <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"μετά τ(ο|η)ν? επόμεν(ο|η)ν?"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth Int
1 Bool
True a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHhmm :: Rule
ruleHhmm :: Rule
ruleHhmm = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"hh:mm"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"((?:[01]?\\d)|(?:2[0-3]))[:ω]([0-5]\\d)ω?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (m1:m2:_)):[Token]
_) -> do
        Int
h <- Text -> Maybe Int
parseInt Text
m1
        Int
m <- Text -> Maybe Int
parseInt Text
m2
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
True Int
h Int
m
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHHMMSS :: Rule
ruleHHMMSS :: Rule
ruleHHMMSS = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"hh:mm:ss"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"((?:[01]?\\d)|(?:2[0-3]))[:.]([0-5]\\d)[:.]([0-5]\\d)"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (hh:mm:ss:_)):[Token]
_) -> do
        Int
h <- Text -> Maybe Int
parseInt Text
hh
        Int
m <- Text -> Maybe Int
parseInt Text
mm
        Int
s <- Text -> Maybe Int
parseInt Text
ss
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> Int -> TimeData
hourMinuteSecond Bool
True Int
h Int
m Int
s
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

-- We can't take generic TOD (e.g. "6:30am - 9pm").
-- Those are handled by other rules.
ruleIntervalTODAMPM :: Rule
ruleIntervalTODAMPM :: Rule
ruleIntervalTODAMPM = Rule :: Text -> Pattern -> Production -> Rule
Rule
 { name :: Text
name = Text
"hh(:mm) - <time-of-day> am|pm"
 , pattern :: Pattern
pattern =
   [ String -> PatternItem
regex String
"(?:από )?((?:[01]?\\d)|(?:2[0-3]))([:.]([0-5]\\d))?"
   , String -> PatternItem
regex String
"\\-|:|μέχρι"
   , Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
   , String -> PatternItem
regex String
"([πμ])(\\s|\\.)?(μ\\.?)?"
   ]
 , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
     (Token Dimension a
RegexMatch (GroupMatch (hh:_:mm:_)):
      Token
_:
      Token Dimension a
Time a
td2:
      Token Dimension a
RegexMatch (GroupMatch (ap:_)):
      [Token]
_) -> do
       Int
h <- Text -> Maybe Int
parseInt Text
hh
       let ampm :: Bool
ampm = Text -> Text
Text.toLower Text
ap Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"π"
           td1 :: TimeData
td1 = TimeData -> (Int -> TimeData) -> Maybe Int -> TimeData
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Bool -> Int -> TimeData
hour Bool
True Int
h) (Bool -> Int -> Int -> TimeData
hourMinute Bool
True Int
h) (Text -> Maybe Int
parseInt Text
mm)
       Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
         TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed (Bool -> TimeData -> TimeData
timeOfDayAMPM Bool
ampm TimeData
td1) (Bool -> TimeData -> TimeData
timeOfDayAMPM Bool
ampm a
TimeData
td2)
     [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
 }

-- We can't take generic TOD (e.g. "6:30am - 9pm").
-- Those are handled by other rules.
ruleIntervalTODAMPMverbose :: Rule
ruleIntervalTODAMPMverbose :: Rule
ruleIntervalTODAMPMverbose = Rule :: Text -> Pattern -> Production -> Rule
Rule
 { name :: Text
name = Text
"hh(:mm) - <time-of-day> am|pm (verbose)"
 , pattern :: Pattern
pattern =
   [ String -> PatternItem
regex String
"(?:από\\s+)?((?:[01]?\\d)|(?:2[0-3]))([:.]([0-5]\\d))?"
   , String -> PatternItem
regex String
"\\-|:|μέχρι"
   , Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
   , String -> PatternItem
regex String
"(?:το\\s+)?(πρωί|απόγευμα)"
   ]
 , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
     (Token Dimension a
RegexMatch (GroupMatch (hh:_:mm:_)):
      Token
_:
      Token Dimension a
Time a
td2:
      Token Dimension a
RegexMatch (GroupMatch (ap:_)):
      [Token]
_) -> do
       Int
h <- Text -> Maybe Int
parseInt Text
hh
       let ampm :: Bool
ampm = Text -> Text
Text.toLower Text
ap Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"πρωί"
           td1 :: TimeData
td1 = TimeData -> (Int -> TimeData) -> Maybe Int -> TimeData
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Bool -> Int -> TimeData
hour Bool
True Int
h) (Bool -> Int -> Int -> TimeData
hourMinute Bool
True Int
h) (Text -> Maybe Int
parseInt Text
mm)
       Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
         TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed (Bool -> TimeData -> TimeData
timeOfDayAMPM Bool
ampm TimeData
td1) (Bool -> TimeData -> TimeData
timeOfDayAMPM Bool
ampm a
TimeData
td2)
     [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
 }

ruleTonight :: Rule
ruleTonight :: Rule
ruleTonight = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"tonight"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"απόψε"
    ]
  , prod :: Production
prod = \[Token]
_ -> do
      TimeData
td2 <- TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open (Bool -> Int -> TimeData
hour Bool
False Int
18) (Bool -> Int -> TimeData
hour Bool
False Int
0)
      Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect TimeData
today TimeData
td2
  }

ruleTomorrowNight :: Rule
ruleTomorrowNight :: Rule
ruleTomorrowNight = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"tomorrownight"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"αύριο\\s+(το\\s+)?βράδυ"
    ]
  , prod :: Production
prod = \[Token]
_ -> do
      let td1 :: TimeData
td1 = Grain -> Int -> TimeData
cycleNth Grain
TG.Day Int
1
      TimeData
td2 <- TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open (Bool -> Int -> TimeData
hour Bool
False Int
18) (Bool -> Int -> TimeData
hour Bool
False Int
0)
      Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect TimeData
td1 TimeData
td2
  }

ruleLastNight :: Rule
ruleLastNight :: Rule
ruleLastNight = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"lastnight"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"ε?χ[θτ][εέ]ς\\s+(το\\s+)?βράδυ"
    ]
  , prod :: Production
prod = \[Token]
_ -> do
      let td1 :: TimeData
td1 = Grain -> Int -> TimeData
cycleNth Grain
TG.Day (Int -> TimeData) -> Int -> TimeData
forall a b. (a -> b) -> a -> b
$ - Int
1
      TimeData
td2 <- TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open (Bool -> Int -> TimeData
hour Bool
False Int
18) (Bool -> Int -> TimeData
hour Bool
False Int
0)
      Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect TimeData
td1 TimeData
td2
  }

ruleYear :: Rule
ruleYear :: Rule
ruleYear = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"year"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1000 Int
2100
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:[Token]
_) -> do
        Int
y <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
year Int
y
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleThisYear :: Rule
ruleThisYear :: Rule
ruleThisYear = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"this year"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"ε?φ[εέ]τος?"
    ]
  , prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production)
-> (TimeData -> Maybe Token) -> TimeData -> Production
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> Maybe Token
tt (TimeData -> Production) -> TimeData -> Production
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth Grain
TG.Year Int
0
  }

ruleLastYear :: Rule
ruleLastYear :: Rule
ruleLastYear = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"Last year"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"π[εέ]ρ(υ?σιν|ασμέν)[οόηή]ς?\\s+(έτου?ς|χρ[οό]ν(ου|ιάς?))"
    ]
  , prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production)
-> (Int -> Maybe Token) -> Int -> Production
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (Int -> TimeData) -> Int -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Grain -> Int -> TimeData
cycleNth Grain
TG.Year (Int -> Production) -> Int -> Production
forall a b. (a -> b) -> a -> b
$ - Int
1
  }

ruleLastYearOneWord :: Rule
ruleLastYearOneWord :: Rule
ruleLastYearOneWord = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"Last year"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"π[εέ]ρυ?σι"
    ]
  , prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production)
-> (Int -> Maybe Token) -> Int -> Production
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (Int -> TimeData) -> Int -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Grain -> Int -> TimeData
cycleNth Grain
TG.Year (Int -> Production) -> Int -> Production
forall a b. (a -> b) -> a -> b
$ - Int
1
  }

ruleNextYear :: Rule
ruleNextYear :: Rule
ruleNextYear = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"Last year"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"του\\s*χρόνου"
    ]
  , prod :: Production
prod = Maybe Token -> Production
forall a b. a -> b -> a
const (Maybe Token -> Production)
-> (TimeData -> Maybe Token) -> TimeData -> Production
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> Maybe Token
tt (TimeData -> Production) -> TimeData -> Production
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth Grain
TG.Year Int
1
  }

ruleHhmmMilitary :: Rule
ruleHhmmMilitary :: Rule
ruleHhmmMilitary = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"hhmm (military)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"((?:[01]?\\d)|(?:2[0-3]))([0-5]\\d)"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (h:m:_)):[Token]
_) -> do
        Int
hh <- Text -> Maybe Int
parseInt Text
h
        Int
mm <- Text -> Maybe Int
parseInt Text
m
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
False Int
hh Int
mm
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleAbsorptionOfAfterNamedDay :: Rule
ruleAbsorptionOfAfterNamedDay :: Rule
ruleAbsorptionOfAfterNamedDay = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"absorption of , after named day"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isADayOfWeek
    , String -> PatternItem
regex String
","
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
x:[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just Token
x
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleAbsorptionOfArticleBeforeTime :: Rule
ruleAbsorptionOfArticleBeforeTime :: Rule
ruleAbsorptionOfArticleBeforeTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"absorption of article before time"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"σ?τ?(α|η|ι|ο[ιυ]?|ω)ν?ς?"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
notLatent a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleLastDayofweekOfTime :: Rule
ruleLastDayofweekOfTime :: Rule
ruleLastDayofweekOfTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"last <day-of-week> of <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"τελευταί(ου?|ας?)"
    , Predicate -> PatternItem
Predicate Predicate
isADayOfWeek
    , String -> PatternItem
regex String
"τ(ου|ης)"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData -> TimeData
predLastOf a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHhmmMilitaryAmpm :: Rule
ruleHhmmMilitaryAmpm :: Rule
ruleHhmmMilitaryAmpm = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"hhmm (military) am|pm"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"((?:1[012]|0?\\d))([0-5]\\d)"
    , String -> PatternItem
regex String
"([πμ])\\.?(μ\\.?)?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      ( Token Dimension a
RegexMatch (GroupMatch (hh:mm:_)):
        Token Dimension a
RegexMatch (GroupMatch (ap:_)):[Token]
_) -> do
        Int
h <- Text -> Maybe Int
parseInt Text
hh
        Int
m <- Text -> Maybe Int
parseInt Text
mm
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> TimeData -> TimeData
timeOfDayAMPM (Text -> Text
Text.toLower Text
ap Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"π") (Bool -> Int -> Int -> TimeData
hourMinute Bool
True Int
h Int
m)
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimeofdayTimeofdayInterval :: Rule
ruleTimeofdayTimeofdayInterval :: Rule
ruleTimeofdayTimeofdayInterval = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time-of-day> - <time-of-day> (interval)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and ([Bool] -> Bool) -> (Token -> [Bool]) -> Predicate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Predicate] -> Token -> [Bool]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Predicate
isNotLatent, Predicate
isATimeOfDay]
    , String -> PatternItem
regex String
"\\-|μέχρι"
    , Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDurationAfterTime :: Rule
ruleDurationAfterTime :: Rule
ruleDurationAfterTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<duration> after <time>"
  , pattern :: Pattern
pattern =
    [ Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    , String -> PatternItem
regex String
"μετά(\\s+από)?|από"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Duration a
dd:Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData -> TimeData
durationAfter a
DurationData
dd a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleOrdinalQuarter :: Rule
ruleOrdinalQuarter :: Rule
ruleOrdinalQuarter = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<ordinal> quarter"
  , pattern :: Pattern
pattern =
    [ Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Grain -> Predicate
isGrain Grain
TG.Quarter
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Ordinal OrdinalData{TOrdinal.value = v}:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Quarter (Int
v Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth Grain
TG.Year Int
0
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDurationBeforeTime :: Rule
ruleDurationBeforeTime :: Rule
ruleDurationBeforeTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<duration> before <time>"
  , pattern :: Pattern
pattern =
    [ Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    , String -> PatternItem
regex String
"πριν"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Duration a
dd:Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData -> TimeData
durationBefore a
DurationData
dd a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

rulePartofdayOfTime :: Rule
rulePartofdayOfTime :: Rule
rulePartofdayOfTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<part-of-day> of <time>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAPartOfDay
    , String -> PatternItem
regex String
"τ(ου|ης)"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleMmddyyyy :: Rule
ruleMmddyyyy :: Rule
ruleMmddyyyy = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"dd/mm/yyyy"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(3[01]|[12]\\d|0?[1-9])[/.-](1[0-2]|0?[1-9])[/.-](\\d{2,4})"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (m1:m2:m3:_)):[Token]
_) -> do
        Int
y <- Text -> Maybe Int
parseInt Text
m3
        Int
m <- Text -> Maybe Int
parseInt Text
m2
        Int
d <- Text -> Maybe Int
parseInt Text
m1
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int -> TimeData
yearMonthDay Int
y Int
m Int
d
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimeofdayOclock :: Rule
ruleTimeofdayOclock :: Rule
ruleTimeofdayOclock = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time-of-day>  o'clock"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"η ώρα"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
notLatent a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDayofmonthordinalNamedmonthYear :: Rule
ruleDayofmonthordinalNamedmonthYear :: Rule
ruleDayofmonthordinalNamedmonthYear = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<day-of-month> ( ordinal) <named-month> year"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isDOMOrdinal
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    , String -> PatternItem
regex String
"(\\d{2,4})"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
dd:Token Dimension a
Time a
mm:Token Dimension a
RegexMatch (GroupMatch (yy:_)):[Token]
_) -> do
        Int
y <- Text -> Maybe Int
parseInt Text
yy
        TimeData
dom <- TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
mm Token
dd
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect TimeData
dom (Int -> TimeData
year Int
y)
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleIntervalForDurationFrom :: Rule
ruleIntervalForDurationFrom :: Rule
ruleIntervalForDurationFrom = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"for <duration> from <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"για"
    , Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    , String -> PatternItem
regex String
"(ξεκινώντας\\s+)?(μετά(\\s+από)?|από)"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Duration a
dd:Token
_:Token Dimension a
Time a
td1:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open a
TimeData
td1 (DurationData -> TimeData -> TimeData
durationAfter a
DurationData
dd a
TimeData
td1)
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}

ruleTimezone :: Rule
ruleTimezone :: Rule
ruleTimezone = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time> timezone"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and ([Bool] -> Bool) -> (Token -> [Bool]) -> Predicate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Predicate] -> Token -> [Bool]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Predicate
isNotLatent, Predicate
isATimeOfDay]
    , String -> PatternItem
regex String
"\\b(YEKT|YEKST|YAKT|YAKST|WITA|WIT|WIB|WGT|WGST|WFT|WET|WEST|WAT|WAST|VUT|VLAT|VLAST|VET|UZT|UYT|UYST|UTC|ULAT|TVT|TMT|TLT|TKT|TJT|TFT|TAHT|SST|SRT|SGT|SCT|SBT|SAST|SAMT|RET|PYT|PYST|PWT|PST|PONT|PMST|PMDT|PKT|PHT|PHOT|PGT|PETT|PETST|PET|PDT|OMST|OMSST|NZST|NZDT|NUT|NST|NPT|NOVT|NOVST|NFT|NDT|NCT|MYT|MVT|MUT|MST|MSK|MSD|MMT|MHT|MDT|MAWT|MART|MAGT|MAGST|LINT|LHST|LHDT|KUYT|KST|KRAT|KRAST|KGT|JST|IST|IRST|IRKT|IRKST|IRDT|IOT|IDT|ICT|HOVT|HKT|GYT|GST|GMT|GILT|GFT|GET|GAMT|GALT|FNT|FKT|FKST|FJT|FJST|EST|EGT|EGST|EET|EEST|EDT|ECT|EAT|EAST|EASST|DAVT|ChST|CXT|CVT|CST|COT|CLT|CLST|CKT|CHAST|CHADT|CET|CEST|CDT|CCT|CAT|CAST|BTT|BST|BRT|BRST|BOT|BNT|AZT|AZST|AZOT|AZOST|AWST|AWDT|AST|ART|AQTT|ANAT|ANAST|AMT|AMST|ALMT|AKST|AKDT|AFT|AEST|AEDT|ADT|ACST|ACDT)\\b"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:
       Token Dimension a
RegexMatch (GroupMatch (tz:_)):
       [Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> TimeData -> Maybe TimeData
inTimezone (Text -> Text
Text.toUpper Text
tz) a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

rules :: [Rule]
rules :: [Rule]
rules =
  [ Rule
ruleADuration
  , Rule
ruleAbsorptionOfAfterNamedDay
  , Rule
ruleAbsorptionOfArticleBeforeTime
  , Rule
ruleAfterDuration
  , Rule
ruleAfterNextTime
  , Rule
ruleAfterTimeofday
  , Rule
ruleAfterWork
  , Rule
ruleAfternoon
  , Rule
ruleAtTimeofday
  , Rule
ruleBetweenDatetimeAndDatetimeInterval
  , Rule
ruleBetweenTimeofdayAndTimeofdayInterval
  , Rule
ruleByTheEndOfTime
  , Rule
ruleCycleCurrentLastNext
  , Rule
ruleCycleThis
  , Rule
ruleDatetimeDatetimeInterval
  , Rule
ruleDayofmonthNonOrdinalNamedmonth
  , Rule
ruleDayofmonthNonOrdinalOfNamedmonth
  , Rule
ruleDayofmonthOrdinal
  , Rule
ruleDayofmonthOrdinalNamedmonth
  , Rule
ruleDayofmonthordinalNamedmonthYear
  , Rule
ruleDurationAfterTime
  , Rule
ruleDurationBeforeTime
  , Rule
ruleDurationFromNow
  , Rule
ruleDurationHenceAgo
  , Rule
ruleEarlyMorning
  , Rule
ruleEvening
  , Rule
ruleExactlyTimeofday
  , Rule
ruleFromDatetimeDatetimeInterval
  , Rule
ruleHHMMSS
  , Rule
ruleHalfAfterIntegerHourofday
  , Rule
ruleHalfAfterIntegerHourofday2
  , Rule
ruleHenceAgoDuration
  , Rule
ruleHhmm
  , Rule
ruleHhmmMilitary
  , Rule
ruleHhmmMilitaryAmpm
  , Rule
ruleHourofdayIntegerAsRelativeMinutes
  , Rule
ruleInDuration
  , Rule
ruleInDurationFromTime
  , Rule
ruleInduringThePartofday
  , Rule
ruleIntersect
  , Rule
ruleIntersectBy
  , Rule
ruleIntersectByOfFromS
  , Rule
ruleIntervalBy
  , Rule
ruleIntervalByTheEndOf
  , Rule
ruleIntervalForDurationFrom
  , Rule
ruleIntervalTODAMPM
  , Rule
ruleIntervalTODAMPMverbose
  , Rule
ruleIntervalTODDash
  , Rule
ruleIntervalUntilTOD
  , Rule
ruleLastCycle
  , Rule
ruleLastCycleOfTime
  , Rule
ruleLastCycleOfTimeS
  , Rule
ruleLastDayofweekOfTime
  , Rule
ruleLastNCycle
  , Rule
ruleLastNight
  , Rule
ruleLastTime
  , Rule
ruleLastWeekendOfMonth
  , Rule
ruleLastYear
  , Rule
ruleLastYearOneWord
  , Rule
ruleLunch
  , Rule
ruleMidnight
  , Rule
ruleMmdd
  , Rule
ruleMmddyyyy
  , Rule
ruleMonthDdddInterval
  , Rule
ruleMorning
  , Rule
ruleNamedmonthDayofmonth
  , Rule
ruleNextCycle
  , Rule
ruleNextDayofweek
  , Rule
ruleNextNCycle
  , Rule
ruleNextTime
  , Rule
ruleNextYear
  , Rule
ruleNight
  , Rule
ruleNoon
  , Rule
ruleNthTimeAfterTime
  , Rule
ruleNthTimeOfTime
  , Rule
ruleOrdinalCycleAfterTime
  , Rule
ruleOrdinalCycleOfTime
  , Rule
ruleOrdinalQuarter
  , Rule
ruleOrdinalQuarterYear
  , Rule
rulePartOfMonth
  , Rule
rulePartofdayOfTime
  , Rule
rulePrecisionTimeofday
  , Rule
ruleQuarterBeforeOrAfterIntegerHourofday
  , Rule
ruleRelativeIntegerToOrAfterIntegerPartOfDay
  , Rule
ruleTheCycleAfterTime
  , Rule
ruleTheCycleBeforeTime
  , Rule
ruleTheCycleOfTime
  , Rule
ruleTheDayOf
  , Rule
ruleTheDayofmonthNonOrdinal
  , Rule
ruleThisCycle
  , Rule
ruleThisDayofWeek
  , Rule
ruleThisDayofWeek2
  , Rule
ruleThisPartofday
  , Rule
ruleThisYear
  , Rule
ruleTimeAfterNext
  , Rule
ruleTimePartofday
  , Rule
ruleTimeofdayAmpm
  , Rule
ruleTimeofdayAmpmVerbose
  , Rule
ruleTimeofdayApproximately
  , Rule
ruleTimeofdayLatent
  , Rule
ruleTimeofdayOclock
  , Rule
ruleTimeofdayTimeofdayInterval
  , Rule
ruleTimezone
  , Rule
ruleTomorrowNight
  , Rule
ruleTonight
  , Rule
ruleUntilTimeofdayPostfix
  , Rule
ruleWeekend
  , Rule
ruleWithinDuration
  , Rule
ruleYear
  , Rule
ruleYearLatent
  , Rule
ruleYearLatent2
  , Rule
ruleYyyymmdd
  ]
  [Rule] -> [Rule] -> [Rule]
forall a. [a] -> [a] -> [a]
++ [Rule]
ruleDaysOfWeek
  [Rule] -> [Rule] -> [Rule]
forall a. [a] -> [a] -> [a]
++ [Rule]
ruleHolidays
  [Rule] -> [Rule] -> [Rule]
forall a. [a] -> [a] -> [a]
++ [Rule]
ruleInstants
  [Rule] -> [Rule] -> [Rule]
forall a. [a] -> [a] -> [a]
++ [Rule]
ruleMonths
  [Rule] -> [Rule] -> [Rule]
forall a. [a] -> [a] -> [a]
++ [Rule]
ruleSeasons