{-# LANGUAGE GADTs #-}
{-# LANGUAGE NoRebindableSyntax #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Time.ZH.Rules
( rules
) where
import Prelude
import qualified Data.Text as Text
import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Numeral.Types (NumeralData(..))
import Duckling.Regex.Types
import Duckling.Time.Computed
import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..))
import Duckling.Types
import qualified Duckling.Ordinal.Types as TOrdinal
import qualified Duckling.Time.Types as TTime
import qualified Duckling.TimeGrain.Types as TG
import qualified Duckling.Numeral.Types as TNumeral
ruleTheDayAfterTomorrow :: Rule
ruleTheDayAfterTomorrow :: Rule
ruleTheDayAfterTomorrow = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"the day after tomorrow"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"后天|後天|後日"
]
, prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth Grain
TG.Day Int
2
}
ruleTwoDaysAfterTomorrow :: Rule
ruleTwoDaysAfterTomorrow :: Rule
ruleTwoDaysAfterTomorrow = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"two days after tomorrow"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"大后天|大後天|大後日"
]
, prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth Grain
TG.Day Int
3
}
ruleRelativeMinutesTotillbeforeIntegerHourofday :: Rule
ruleRelativeMinutesTotillbeforeIntegerHourofday :: Rule
ruleRelativeMinutesTotillbeforeIntegerHourofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"relative minutes to|till|before <integer> (hour-of-day)"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate 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 a
td:Token
_:Token
token:[Token]
_) -> do
Int
n <- Token -> Maybe Int
getIntValue 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
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
n a
TimeData
td
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleRelativeMinutesTotillbeforeNoonmidnight :: Rule
ruleRelativeMinutesTotillbeforeNoonmidnight :: Rule
ruleRelativeMinutesTotillbeforeNoonmidnight = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"relative minutes to|till|before noon|midnight"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isMidnightOrNoon
, 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 a
td:Token
_:Token
token:[Token]
_) -> do
Int
n <- Token -> Maybe Int
getIntValue 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
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
n a
TimeData
td
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleRelativeMinutesAfterpastIntegerHourofday :: Rule
ruleRelativeMinutesAfterpastIntegerHourofday :: Rule
ruleRelativeMinutesAfterpastIntegerHourofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"relative (10-59) minutes after|past <integer> (hour-of-day)"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate 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
10 Int
59
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) _)}:
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
True Int
hours Int
n
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleRelativeMinutesAfterpastIntegerHourofday2 :: Rule
ruleRelativeMinutesAfterpastIntegerHourofday2 :: Rule
ruleRelativeMinutesAfterpastIntegerHourofday2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"relative (10-59) minutes after|past <integer> (hour-of-day)"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate 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
10 Int
59
, 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) _)}:
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
True Int
hours Int
n
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleRelativeMinutesAfterpastIntegerHourofday3 :: Rule
ruleRelativeMinutesAfterpastIntegerHourofday3 :: Rule
ruleRelativeMinutesAfterpastIntegerHourofday3 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"relative (1-9) minutes after|past <integer> (hour-of-day)"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate 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
9
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) _)}:
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
True Int
hours Int
n
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleRelativeMinutesAfterpastIntegerHourofday4 :: Rule
ruleRelativeMinutesAfterpastIntegerHourofday4 :: Rule
ruleRelativeMinutesAfterpastIntegerHourofday4 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"relative (1-9) minutes after|past <integer> (hour-of-day)"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate 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
9
, 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) _)}:
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
True Int
hours Int
n
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleRelativeMinutesAfterpastIntegerHourofday5 :: Rule
ruleRelativeMinutesAfterpastIntegerHourofday5 :: Rule
ruleRelativeMinutesAfterpastIntegerHourofday5 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"number of 5 minutes after|past <integer> (hour-of-day)"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate 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
11
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) _)}:
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
True Int
hours (Int
5Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
n)
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleRelativeMinutesAfterpastIntegerHourofday6 :: Rule
ruleRelativeMinutesAfterpastIntegerHourofday6 :: Rule
ruleRelativeMinutesAfterpastIntegerHourofday6 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"number of 5 minutes after|past <integer> (hour-of-day)"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate 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
9
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) _)}:
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
True Int
hours (Int
5Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
n)
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleRelativeMinutesAfterpastIntegerHourofday7 :: Rule
ruleRelativeMinutesAfterpastIntegerHourofday7 :: Rule
ruleRelativeMinutesAfterpastIntegerHourofday7 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"number of 5 minutes after|past <integer> (hour-of-day)"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate 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
11
, 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) _)}:
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
True Int
hours (Int
5Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
n)
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleRelativeMinutesAfterpastNoonmidnight :: Rule
ruleRelativeMinutesAfterpastNoonmidnight :: Rule
ruleRelativeMinutesAfterpastNoonmidnight = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"relative minutes after|past noon|midnight"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isMidnightOrNoon
, String -> PatternItem
regex String
"过|\x904e"
, 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) _)}:
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
True Int
hours Int
n
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleQuarterTotillbeforeIntegerHourofday :: Rule
ruleQuarterTotillbeforeIntegerHourofday :: Rule
ruleQuarterTotillbeforeIntegerHourofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"quarter to|till|before <integer> (hour-of-day)"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
, String -> PatternItem
regex String
"(点|點)差"
, String -> PatternItem
regex String
"一刻"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(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
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
15 a
TimeData
td
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleQuarterTotillbeforeNoonmidnight :: Rule
ruleQuarterTotillbeforeNoonmidnight :: Rule
ruleQuarterTotillbeforeNoonmidnight = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"quarter to|till|before noon|midnight"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isMidnightOrNoon
, String -> PatternItem
regex String
"差"
, String -> PatternItem
regex String
"一刻"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(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
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
15 a
TimeData
td
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleQuarterAfterpastIntegerHourofday :: Rule
ruleQuarterAfterpastIntegerHourofday :: Rule
ruleQuarterAfterpastIntegerHourofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"quarter after|past <integer> (hour-of-day)"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
, String -> PatternItem
regex String
"点|點"
, 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) _)}:
[Token]
_) -> 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
15
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleQuarterAfterpastNoonmidnight :: Rule
ruleQuarterAfterpastNoonmidnight :: Rule
ruleQuarterAfterpastNoonmidnight = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"quarter after|past noon|midnight"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isMidnightOrNoon
, String -> PatternItem
regex String
"过"
, 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) _)}:
[Token]
_) -> 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
15
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleHalfTotillbeforeIntegerHourofday :: Rule
ruleHalfTotillbeforeIntegerHourofday :: Rule
ruleHalfTotillbeforeIntegerHourofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"half to|till|before <integer> (hour-of-day)"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
, String -> PatternItem
regex String
"(点|點)差"
, String -> PatternItem
regex String
"半"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(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
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
30 a
TimeData
td
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleHalfTotillbeforeNoonmidnight :: Rule
ruleHalfTotillbeforeNoonmidnight :: Rule
ruleHalfTotillbeforeNoonmidnight = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"half to|till|before noon|midnight"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isMidnightOrNoon
, String -> PatternItem
regex String
"差"
, String -> PatternItem
regex String
"半"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(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
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
30 a
TimeData
td
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleHalfAfterpastIntegerHourofday :: Rule
ruleHalfAfterpastIntegerHourofday :: Rule
ruleHalfAfterpastIntegerHourofday = 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
"(点|點)(踏|搭)?"
, 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) _)}:
[Token]
_) -> 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
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleHalfAfterpastNoonmidnight :: Rule
ruleHalfAfterpastNoonmidnight :: Rule
ruleHalfAfterpastNoonmidnight = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"half after|past noon|midnight"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isMidnightOrNoon
, String -> PatternItem
regex String
"过"
, 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) _)}:
[Token]
_) -> 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
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleHhmmTimeofday :: Rule
ruleHhmmTimeofday :: Rule
ruleHhmmTimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"hh:mm (time-of-day)"
, 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 (hh:mm:_)):[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 -> Int -> Int -> TimeData
hourMinute Bool
True Int
h Int
m
[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
False a
TimeData
td
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleNthTimeOfTime2 :: Rule
ruleNthTimeOfTime2 :: Rule
ruleNthTimeOfTime2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"nth <time> of <time>"
, pattern :: Pattern
pattern =
[ Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
, String -> PatternItem
regex String
"的"
, Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
, 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
Ordinal a
od: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 (OrdinalData -> Int
TOrdinal.value a
OrdinalData
od 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
}
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
}
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
}
ruleNow :: Rule
ruleNow :: Rule
ruleNow = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"now"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"现在|此时|此刻|当前|現在|此時|當前|\x5b9c\x5bb6|\x800c\x5bb6|\x4f9d\x5bb6"
]
, prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt TimeData
now
}
ruleTheCycleAfterTime :: Rule
ruleTheCycleAfterTime :: Rule
ruleTheCycleAfterTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"the <cycle> after <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
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False a
Grain
grain Int
1 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 =
[ 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
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False a
Grain
grain (-Int
1) a
TimeData
td
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
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 = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
mkOkForThisNext (TimeData -> TimeData) -> TimeData -> TimeData
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> TimeData
hour Bool
False Int
12
}
ruleToday :: Rule
ruleToday :: Rule
ruleToday = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"today"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"今天|今日"
]
, prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt TimeData
today
}
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
0 Bool
True a
TimeData
td
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleTheDayBeforeYesterday :: Rule
ruleTheDayBeforeYesterday :: Rule
ruleTheDayBeforeYesterday = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"the day before yesterday"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"前天|前日"
]
, prod :: Production
prod = \[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 Grain
TG.Day (Int -> Maybe Token) -> Int -> Maybe Token
forall a b. (a -> b) -> a -> b
$ - Int
2
}
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
}
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
}
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
}
ruleLastDuration :: Rule
ruleLastDuration :: Rule
ruleLastDuration = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"last <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
durationAgo a
DurationData
dd
[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
"下午|中午|\x664f\x665d"
]
, 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
19
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
}
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 = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
mkOkForThisNext (TimeData -> TimeData) -> TimeData -> TimeData
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> TimeData
hour Bool
False Int
0
}
ruleInduringThePartofday :: Rule
ruleInduringThePartofday :: Rule
ruleInduringThePartofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"in|during the <part-of-day>"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isAPartOfDay
, 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
}
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
}
ruleMmdd :: Rule
ruleMmdd :: Rule
ruleMmdd = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"mm/dd"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(0?[1-9]|1[0-2])/(3[01]|[12]\\d|0?[1-9])"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (mm:dd:_)):[Token]
_) -> do
Int
m <- Text -> Maybe Int
parseInt Text
mm
Int
d <- Text -> Maybe Int
parseInt Text
dd
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
}
ruleIntegerLatentTimeofday :: Rule
ruleIntegerLatentTimeofday :: Rule
ruleIntegerLatentTimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<integer> (latent 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
0 Int
23
]
, 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
$ Bool -> Int -> TimeData
hour Bool
True Int
v
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleYearNumericWithYearSymbol :: Rule
ruleYearNumericWithYearSymbol :: Rule
ruleYearNumericWithYearSymbol = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"year (numeric with year symbol)"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1000 Int
9999
, String -> PatternItem
regex String
"年"
]
, 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 -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
year Int
v
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleYearNumericWithYearSymbol2 :: Rule
ruleYearNumericWithYearSymbol2 :: Rule
ruleYearNumericWithYearSymbol2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"xxxx year"
, pattern :: Pattern
pattern =
[ Dimension NumeralData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension NumeralData
Numeral
, Dimension NumeralData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension NumeralData
Numeral
, Dimension NumeralData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension NumeralData
Numeral
, Dimension NumeralData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension NumeralData
Numeral
, String -> PatternItem
regex String
"年"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Numeral NumeralData{TNumeral.value = y1}:
Token Dimension a
Numeral NumeralData{TNumeral.value = y2}:
Token Dimension a
Numeral NumeralData{TNumeral.value = y3}:
Token Dimension a
Numeral NumeralData{TNumeral.value = y4}:
[Token]
_) -> do
let v :: Int
v = Double -> Int
forall a b. (RealFrac a, Integral b) => a -> b
floor(Double
y1Double -> Double -> Double
forall a. Num a => a -> a -> a
*Double
1000 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
y2Double -> Double -> Double
forall a. Num a => a -> a -> a
*Double
100 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
y3Double -> Double -> Double
forall a. Num a => a -> a -> a
*Double
10 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
y4)
TimeData -> Maybe Token
tt (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
}
ruleDurationAgo :: Rule
ruleDurationAgo :: Rule
ruleDurationAgo = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<duration> 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]
_) ->
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
}
ruleHhmmMilitaryTimeofday :: Rule
ruleHhmmMilitaryTimeofday :: Rule
ruleHhmmMilitaryTimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"hhmm (military time-of-day)"
, 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 (hh:mm:_)):[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 -> 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
h Int
m
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
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
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
}
ruleNCycleLast :: Rule
ruleNCycleLast :: Rule
ruleNCycleLast = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"n <cycle> last"
, pattern :: Pattern
pattern =
[ 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
, String -> PatternItem
regex String
"(之)?前"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(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
}
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
}
ruleNthTimeOfTime :: Rule
ruleNthTimeOfTime :: Rule
ruleNthTimeOfTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"nth <time> of <time>"
, pattern :: Pattern
pattern =
[ Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
, Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
, 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 Dimension a
Ordinal a
od: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 (OrdinalData -> Int
TOrdinal.value a
OrdinalData
od 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
}
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 = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
mkOkForThisNext TimeData
weekend
}
ruleLastYear :: Rule
ruleLastYear :: Rule
ruleLastYear = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"last year"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"去年|上年"
]
, prod :: Production
prod = \[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 Grain
TG.Year (Int -> Maybe Token) -> Int -> Maybe Token
forall a b. (a -> b) -> a -> b
$ - Int
1
}
ruleDimTimePartofday :: Rule
ruleDimTimePartofday :: Rule
ruleDimTimePartofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<dim 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
}
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
}
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})-(0?[1-9]|1[0-2])-(3[01]|[12]\\d|0?[1-9])"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (yy:mm:dd:_)):[Token]
_) -> do
Int
y <- Text -> Maybe Int
parseInt Text
yy
Int
m <- Text -> Maybe Int
parseInt Text
mm
Int
d <- Text -> Maybe Int
parseInt Text
dd
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
}
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
}
ruleNCycleNext :: Rule
ruleNCycleNext :: Rule
ruleNCycleNext = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"next n <cycle>"
, pattern :: Pattern
pattern =
[ 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
, String -> PatternItem
regex String
"下|(之)?后|(之)?後"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(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
}
ruleMorning :: Rule
ruleMorning :: Rule
ruleMorning = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"morning"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"早上|早晨|\x671d(\x982d)?早"
]
, 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
}
ruleNextYear :: Rule
ruleNextYear :: Rule
ruleNextYear = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"next year"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"明年|下年"
]
, prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth Grain
TG.Year Int
1
}
ruleThisCycle :: Rule
ruleThisCycle :: Rule
ruleThisCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"this <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
0
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleThisTime :: Rule
ruleThisTime :: Rule
ruleThisTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"this <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
0 Bool
False a
TimeData
td
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleYesterday :: Rule
ruleYesterday :: Rule
ruleYesterday = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"yesterday"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"昨天|昨日|\x5c0b日"
]
, prod :: Production
prod = \[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 Grain
TG.Day (Int -> Maybe Token) -> Int -> Maybe Token
forall a b. (a -> b) -> a -> b
$ - Int
1
}
ruleLastNight :: Rule
ruleLastNight :: Rule
ruleLastNight = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"last night"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"昨晚|昨天晚上|\x5c0b晚"
]
, 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
}
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
"([ap])(\\s|\\.)?m?\\.?"
]
, 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") a
TimeData
td
[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>"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isAMonth
, Dimension NumeralData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension NumeralData
Numeral
, String -> PatternItem
regex String
"号|號|日"
]
, 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
}
ruleDayOfMonth :: Rule
ruleDayOfMonth :: Rule
ruleDayOfMonth = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<time> <day-of-month>"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
31
, String -> PatternItem
regex String
"号|號|日"
]
, 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 -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
dayOfMonth Int
v
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rulePartofdayDimTime :: Rule
rulePartofdayDimTime :: Rule
rulePartofdayDimTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<part-of-day> <dim time>"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate Predicate
isAPartOfDay
, 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 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
}
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
"tomorrow night"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"明晚|明天晚上|\x807d晚"
]
, 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
}
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 = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth Grain
TG.Year Int
0
}
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
}
ruleEveningnight :: Rule
ruleEveningnight :: Rule
ruleEveningnight = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"evening|night"
, 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
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 TimeData
from TimeData
to
}
ruleMmddyyyy :: Rule
ruleMmddyyyy :: Rule
ruleMmddyyyy = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"mm/dd/yyyy"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(0?[1-9]|1[0-2])/(3[01]|[12]\\d|0?[1-9])/(\\d{2,4})"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (mm:dd:yy:_)):[Token]
_) -> do
Int
y <- Text -> Maybe Int
parseInt Text
yy
Int
m <- Text -> Maybe Int
parseInt Text
mm
Int
d <- Text -> Maybe Int
parseInt Text
dd
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
}
ruleTomorrow :: Rule
ruleTomorrow :: Rule
ruleTomorrow = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"tomorrow"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"明天|明日|\x807d日"
]
, prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth Grain
TG.Day Int
1
}
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
}
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
}
ruleDaysOfWeek :: [Rule]
ruleDaysOfWeek :: [Rule]
ruleDaysOfWeek = [(Text, String)] -> [Rule]
mkRuleDaysOfWeek
[ ( Text
"Monday", String
"星期一|周一|礼拜一|禮拜一|週一" )
, ( Text
"Tuesday", String
"星期二|周二|礼拜二|禮拜二|週二" )
, ( Text
"Wednesday", String
"星期三|周三|礼拜三|禮拜三|週三" )
, ( Text
"Thursday", String
"星期四|周四|礼拜四|禮拜四|週四" )
, ( Text
"Friday", String
"星期五|周五|礼拜五|禮拜五|週五" )
, ( Text
"Saturday", String
"星期六|周六|礼拜六|禮拜六|週六" )
, ( Text
"Sunday", String
"星期日|星期天|礼拜天|周日|禮拜天|週日|禮拜日" )
]
ruleMonths :: [Rule]
ruleMonths :: [Rule]
ruleMonths = [(Text, String)] -> [Rule]
mkRuleMonths
[ ( Text
"January", String
"(一|1)月(份)?" )
, ( Text
"February", String
"(二|2)月(份)?" )
, ( Text
"March", String
"(三|3)月(份)?" )
, ( Text
"April", String
"(四|4)月(份)?" )
, ( Text
"May", String
"(五|5)月(份)?" )
, ( Text
"June", String
"(六|6)月(份)?" )
, ( Text
"July", String
"(七|7)月(份)?" )
, ( Text
"August", String
"(八|8)月(份)?" )
, ( Text
"September", String
"(九|9)月(份)?" )
, ( Text
"October", String
"(十|10)月(份)?" )
, ( Text
"November", String
"(十一|11)月(份)?" )
, ( Text
"December", String
"(十二|12)月(份)?" )
]
rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays :: [Rule]
rulePeriodicHolidays = [(Text, String, TimeData)] -> [Rule]
mkRuleHolidays
[ ( Text
"中国共产党的生日", String
"中(国共产党诞|國共產黨誕)生日|(党|黨)的生日", Int -> Int -> TimeData
monthDay Int
7 Int
1 )
, ( Text
"愚人节", String
"愚人(节|節)", Int -> Int -> TimeData
monthDay Int
4 Int
1 )
, ( Text
"建军节", String
"(中国人民解放(军|軍)|八一)?建(军节|軍節)", Int -> Int -> TimeData
monthDay Int
8 Int
1 )
, ( Text
"植树节", String
"中(国植树节|國植樹節)", Int -> Int -> TimeData
monthDay Int
3 Int
12 )
, ( Text
"五四青年节", String
"(中(国|國))?(五四|54)?青年(节|節)", Int -> Int -> TimeData
monthDay Int
5 Int
4 )
, ( Text
"圣诞节", String
"(圣诞|聖誕)(节|節)?", Int -> Int -> TimeData
monthDay Int
12 Int
25 )
, ( Text
"平安夜", String
"(平安|聖誕)夜", Int -> Int -> TimeData
monthDay Int
12 Int
24 )
, ( Text
"哥伦布日", String
"哥(伦|倫)布日", Int -> Int -> TimeData
monthDay Int
10 Int
12 )
, ( Text
"双十一", String
"(双|雙)(十一|11)", Int -> Int -> TimeData
monthDay Int
11 Int
11 )
, ( Text
"万圣节", String
"万圣节|萬聖節", Int -> Int -> TimeData
monthDay Int
10 Int
31 )
, ( Text
"香港回归纪念日", String
"香港回(归纪|歸紀)念日", Int -> Int -> TimeData
monthDay Int
7 Int
1 )
, ( Text
"人权日", String
"人(权|權)日", Int -> Int -> TimeData
monthDay Int
12 Int
10 )
, ( Text
"美国独立日", String
"(美国)?(独|獨)立日", Int -> Int -> TimeData
monthDay Int
7 Int
4 )
, ( Text
"儿童节", String
"(国际|國際)?(六一|61)?(儿|兒)童(节|節)", Int -> Int -> TimeData
monthDay Int
6 Int
1 )
, ( Text
"国际慈善日", String
"(国际|國際)慈善日", Int -> Int -> TimeData
monthDay Int
9 Int
5 )
, ( Text
"国际瑜伽日", String
"(国际|國際)瑜伽日", Int -> Int -> TimeData
monthDay Int
6 Int
21 )
, ( Text
"国际爵士日", String
"(国际|國際)爵士日", Int -> Int -> TimeData
monthDay Int
4 Int
30 )
, ( Text
"国际奥林匹克日", String
"(国际|國際)奥林匹克日", Int -> Int -> TimeData
monthDay Int
6 Int
23 )
, ( Text
"妇女节", String
"(国际劳动|國際勞動|三八)?(妇|婦)女(节|節)", Int -> Int -> TimeData
monthDay Int
3 Int
8 )
, ( Text
"劳动节", String
"(五一|51)?(国际|國際)?(劳动|勞動)(节|節)", Int -> Int -> TimeData
monthDay Int
5 Int
1 )
, ( Text
"国际青年节", String
"(国际|國際)青年(节|節)", Int -> Int -> TimeData
monthDay Int
8 Int
12 )
, ( Text
"澳门回归纪念日", String
"澳(门|門)回(归纪|歸紀)念日", Int -> Int -> TimeData
monthDay Int
12 Int
20 )
, ( Text
"全国爱牙日", String
"全(国爱|國愛)牙日", Int -> Int -> TimeData
monthDay Int
9 Int
20 )
, ( Text
"全国爱耳日", String
"全(国爱|國愛)耳日", Int -> Int -> TimeData
monthDay Int
3 Int
3 )
, ( Text
"全国爱眼日", String
"全(国爱|國愛)眼日", Int -> Int -> TimeData
monthDay Int
6 Int
6 )
, ( Text
"南京大屠杀纪念日", String
"南京大屠(杀纪|殺紀)念日", Int -> Int -> TimeData
monthDay Int
12 Int
13 )
, ( Text
"辛亥革命纪念日", String
"辛亥革命(纪|紀)念日", Int -> Int -> TimeData
monthDay Int
10 Int
10 )
, ( Text
"元旦", String
"元旦(节|節)?|((公|(阳|陽))(历|曆))?新年", Int -> Int -> TimeData
monthDay Int
1 Int
1 )
, ( Text
"新年夜", String
"新年夜", Int -> Int -> TimeData
monthDay Int
12 Int
31 )
, ( Text
"情人节", String
"(情人|(圣瓦伦丁|聖瓦倫丁))(节|節)", Int -> Int -> TimeData
monthDay Int
2 Int
14 )
, ( Text
"清明节", String
"清明(节|節)", Int -> Int -> TimeData
monthDay Int
4 Int
5 )
, ( Text
"光棍节", String
"光棍(节|節)", Int -> Int -> TimeData
monthDay Int
11 Int
11 )
, ( Text
"圣帕特里克节", String
"圣帕特里克节|聖帕特裏克節", Int -> Int -> TimeData
monthDay Int
3 Int
17 )
, ( Text
"教师节", String
"(中(国|國))?教师(节|節)", Int -> Int -> TimeData
monthDay Int
9 Int
10 )
, ( Text
"退伍军人节", String
"(退伍(军|軍)人|老兵)(节|節)", Int -> Int -> TimeData
monthDay Int
11 Int
11 )
, ( Text
"白色情人节", String
"白色情人(节|節)", Int -> Int -> TimeData
monthDay Int
3 Int
14 )
, ( Text
"世界艾滋病日", String
"世界艾滋病日", Int -> Int -> TimeData
monthDay Int
12 Int
1 )
, ( Text
"世界献血日", String
"世界(献|獻)血日", Int -> Int -> TimeData
monthDay Int
6 Int
14 )
, ( Text
"世界癌症日", String
"世界癌(症|癥)日", Int -> Int -> TimeData
monthDay Int
2 Int
4 )
, ( Text
"国际消费者权益日", String
"(国际|世界)?(消费者权益|消費者權益)日|三一五", Int -> Int -> TimeData
monthDay Int
3 Int
15 )
, ( Text
"世界糖尿病日", String
"世界糖尿病日", Int -> Int -> TimeData
monthDay Int
11 Int
14 )
, ( Text
"世界环境日", String
"世界(环|環)境日", Int -> Int -> TimeData
monthDay Int
6 Int
5 )
, ( Text
"世界粮食日", String
"世界((粮|糧)食|食物)日", Int -> Int -> TimeData
monthDay Int
10 Int
16 )
, ( Text
"世界心脏日", String
"世界心(脏|臟)日", Int -> Int -> TimeData
monthDay Int
9 Int
29 )
, ( Text
"世界海洋日", String
"世界海洋日", Int -> Int -> TimeData
monthDay Int
6 Int
8 )
, ( Text
"世界诗歌日", String
"世界(诗|詩)歌日", Int -> Int -> TimeData
monthDay Int
3 Int
21 )
, ( Text
"世界人口日", String
"世界人口日", Int -> Int -> TimeData
monthDay Int
7 Int
11 )
, ( Text
"世界难民日", String
"世界(难|難)民日", Int -> Int -> TimeData
monthDay Int
6 Int
20 )
, ( Text
"世界教师日", String
"世界教师日", Int -> Int -> TimeData
monthDay Int
10 Int
5 )
, ( Text
"世界旅游日", String
"世界旅游日", Int -> Int -> TimeData
monthDay Int
9 Int
27 )
, ( Text
"父亲节", String
"父(亲节|親節)", Int -> Int -> Int -> TimeData
nthDOWOfMonth Int
3 Int
7 Int
6 )
, ( Text
"马丁路德金日", String
"(马|馬)丁路德金((纪|紀)念)?日", Int -> Int -> Int -> TimeData
nthDOWOfMonth Int
3 Int
1 Int
1)
, ( Text
"母亲节", String
"母(亲节|親節)", Int -> Int -> Int -> TimeData
nthDOWOfMonth Int
2 Int
7 Int
5 )
]
ruleComputedHolidays :: [Rule]
ruleComputedHolidays :: [Rule]
ruleComputedHolidays = [(Text, String, TimeData)] -> [Rule]
mkRuleHolidays
[ ( Text
"耶稣升天节", String
"耶(稣|穌)升天(节|節|日)"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
39 TimeData
easterSunday )
, ( Text
"大斋首日", String
"大(斋|齋)首日|(圣|聖)灰((礼仪|禮儀)?日|星期三)|灰日"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
46) TimeData
easterSunday )
, ( Text
"阿舒拉节", String
"阿舒拉(节|節)"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
9 TimeData
muharram )
, ( Text
"克哈特普迦节", String
"克哈特普迦(节|節)"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
8 TimeData
dhanteras )
, ( Text
"春节", String
"春(节|節)|(农历|農曆|唐人)新年|新(正|春)|正月(正(时|時)|朔日)|岁首"
, TimeData
chineseNewYear )
, ( Text
"基督圣体节", String
"基督(圣体|聖體)((圣|聖)血)?((节|節)|瞻(礼|禮))"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
60 TimeData
easterSunday )
, ( Text
"排灯节", String
"(排|万|萬|印度)(灯节|燈節)"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
2 TimeData
dhanteras )
, ( Text
"复活节星期一", String
"(复|復)活(节|節)星期一"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
1 TimeData
easterSunday )
, ( Text
"复活节", String
"(复|復)活(节|節)|主(复|復)活日", TimeData
easterSunday )
, ( Text
"古尔邦节", String
"古(尔|爾)邦(节|節)|宰牲(节|節)"
, TimeData
eidalAdha )
, ( Text
"开斋节", String
"(开斋|開齋|肉孜|(尔|爾)代)(节|節)", TimeData
eidalFitr )
, ( Text
"耶稣受难日", String
"(耶(稣|穌)|主)受(难|難)(节|節|日)|(圣|聖|沈默)(周|週)五"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
2) TimeData
easterSunday )
, ( Text
"侯丽节", String
"((侯|荷)(丽|麗)|洒红|灑紅|欢悦|歡悅|五彩|胡里|好利|霍利)(节|節)"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
39 TimeData
vasantPanchami )
, ( Text
"圣周六"
, String
"神?(圣周|聖週)六|(耶(稣|穌)|主)受(难|難)(节|節|日)翌日|(复|復)活(节|節)前夜|黑色星期六"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
1) TimeData
easterSunday )
, ( Text
"伊斯兰新年", String
"伊斯兰(教)?(历)?新年"
, TimeData
muharram )
, ( Text
"登霄节"
, String
"(夜行)?登霄(节|節)"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
26 TimeData
rajab
)
, ( Text
"印度丰收节第四天", String
"(印度(丰|豐)收|(庞|龐)格(尔|爾))(节|節)第四天"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
2 TimeData
thaiPongal )
, ( Text
"篝火节", String
"((犹|猶)太教)?篝火(节|節)", TimeData
lagBaOmer )
, ( Text
"法令之夜"
, String
"(法令|命运|权力)之夜"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
26 TimeData
ramadan )
, ( Text
"拉撒路圣周六", String
"拉撒路(圣周|聖週)六|拉匝路(周|週)六"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
8) TimeData
orthodoxEaster )
, ( Text
"印度丰收节第三天", String
"(印度(丰|豐)收|(庞|龐)格(尔|爾))(节|節)第三天"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
1 TimeData
thaiPongal )
, ( Text
"神圣星期四"
, String
"濯足(节|節)|神(圣|聖)星期四|(圣周|聖週)(星期)?四|(设|設)立(圣|聖)餐日"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
3) TimeData
easterSunday )
, ( Text
"圣纪节" , String
"圣纪节|聖紀節", TimeData
mawlid )
, ( Text
"东正教复活节星期一", String
"(东|東)正教(复|復)活(节|節)星期一"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
1 TimeData
orthodoxEaster )
, ( Text
"东正教复活节", String
"(东|東)正教((复|復)活(节|節)|主(复|復)活日)"
, TimeData
orthodoxEaster )
, ( Text
"东正教圣周六"
, String
"(东|東)正教(神?(圣周|聖週)六|(耶(稣|穌)|主)受(难|難)(节|節|日)翌日|(复|復)活(节|節)前夜)"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
1) TimeData
orthodoxEaster )
, ( Text
"东正教耶稣受难日", String
"(东|東)正教((耶(稣|穌)|主)受(难|難)(节|節|日)|(圣|聖|沈默)(周|週)五)"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
2) TimeData
orthodoxEaster )
, ( Text
"东正教棕枝主日", String
"(东|東)正教((棕|圣|聖)枝|圣树|聖樹|基督苦(难|難))主日"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
7) TimeData
orthodoxEaster )
, ( Text
"棕枝主日", String
"((棕|圣|聖)枝|圣树|聖樹|基督苦(难|難))主日"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
7) TimeData
easterSunday )
, ( Text
"五旬节", String
"五旬(节|節)|(圣灵|聖靈)降(临|臨)(日|节|節)"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
49 TimeData
easterSunday )
, ( Text
"印度兄妹节", String
"(印度兄妹|拉克沙班丹)(节|節)", TimeData
rakshaBandhan )
, ( Text
"圣会节", String
"(圣|聖)会(节|節)"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
21 TimeData
roshHashana )
, ( Text
"忏悔节", String
"忏悔(节|節|火曜日)|煎(饼|餅)星期二"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
47) TimeData
easterSunday )
, ( Text
"西赫托拉节", String
"(西赫(托拉|妥拉)|诵经|誦經|转经|轉經|律法|(欢庆圣|歡慶聖)法)(节|節)"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
22 TimeData
roshHashana )
, ( Text
"印度丰收节", String
"(印度|淡米(尔|爾))(丰|豐)收(节|節)", TimeData
thaiPongal )
, ( Text
"欧南节", String
"欧南(节|節)", TimeData
thiruOnam )
, ( Text
"圣殿被毁日", String
"((圣|聖)殿被毁|禁食)日", TimeData
tishaBAv )
, ( Text
"圣三一主日", String
"((天主)?(圣|聖)?三一|(圣|聖)三)(主日|节|節)"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
56 TimeData
easterSunday )
, ( Text
"十胜节", String
"(十(胜|勝)|(凯|凱)旋|(圣|聖)母)(节|節)"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
9 TimeData
navaratri )
, ( Text
"犹太植树节", String
"((犹|猶)太植(树|樹)|(图|圖)比舍巴特)(节|節)|(树|樹)木新年", TimeData
tuBishvat )
, ( Text
"卫塞节", String
"((卫|衛)塞|威瑟|比(萨宝|薩寶)蕉)(节|節)", TimeData
vesak )
, ( Text
"以色列独立日", String
"以色列((独|獨)立日|国庆节|國慶節)", TimeData
yomHaatzmaut )
, ( Text
"赎罪日", String
"(赎|贖)罪日", Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
9 TimeData
roshHashana )
, ( Text
"圣灵节庆日", String
"(圣灵节庆|聖靈節慶)日"
, Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
50 TimeData
easterSunday )
, ( Text
"老板节", String
"老(板节|闆節)"
, Int -> TimeData -> TimeData -> TimeData
predNthClosest Int
0 TimeData
weekday (Int -> Int -> TimeData
monthDay Int
10 Int
16) )
]
ruleComputedHolidays' :: [Rule]
ruleComputedHolidays' :: [Rule]
ruleComputedHolidays' = [(Text, String, Maybe TimeData)] -> [Rule]
mkRuleHolidays'
[ ( Text
"全球青年服务日", String
"全球青年服(务|務)日"
, let start :: TimeData
start = TimeData
globalYouthServiceDay
end :: TimeData
end = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
2 TimeData
globalYouthServiceDay
in TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
start TimeData
end )
, ( Text
"四旬节", String
"四旬(节|節)"
, let start :: TimeData
start = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
48) TimeData
orthodoxEaster
end :: TimeData
end = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
9) TimeData
orthodoxEaster
in TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
start TimeData
end )
, ( Text
"光明节", String
"(光明|修殿|(献|獻)殿|(烛|燭)光|哈努卡|(马|馬)加比)(节|節)"
, let start :: TimeData
start = TimeData
chanukah
end :: TimeData
end = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
7 TimeData
chanukah
in TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
start TimeData
end )
, ( Text
"大斋期", String
"大(斋|齋)(期|节|節)"
, let start :: TimeData
start = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
46) TimeData
easterSunday
end :: TimeData
end = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
1) TimeData
easterSunday
in TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
start TimeData
end )
, ( Text
"九夜节", String
"(九夜|(难|難)近母)(节|節)"
, let start :: TimeData
start = TimeData
navaratri
end :: TimeData
end = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
9 TimeData
navaratri
in TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
start TimeData
end )
, ( Text
"逾越节", String
"逾越(节|節)"
, let start :: TimeData
start = TimeData
passover
end :: TimeData
end = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
8 TimeData
passover
in TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
start TimeData
end )
, ( Text
"斋月", String
"(穆斯林)?(斋|齋)月"
, let start :: TimeData
start = TimeData
ramadan
end :: TimeData
end = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
1) TimeData
eidalFitr
in TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
start TimeData
end )
, ( Text
"犹太新年", String
"(犹|猶)太新年"
, let start :: TimeData
start = TimeData
roshHashana
end :: TimeData
end = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
2 TimeData
roshHashana
in TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
start TimeData
end )
, ( Text
"七七节", String
"(七七|沙夫幼特|(周|週)日|收(获|穫)|新果(实|實))(节|節)"
, let start :: TimeData
start = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
50 TimeData
passover
end :: TimeData
end = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
52 TimeData
passover
in TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
start TimeData
end )
, ( Text
"住棚节", String
"住棚(节|節)"
, let start :: TimeData
start = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
14 TimeData
roshHashana
end :: TimeData
end = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day Int
22 TimeData
roshHashana
in TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
start TimeData
end )
, ( Text
"地球一小时", String
"地球一小(时|時)"
, let holySaturday :: TimeData
holySaturday = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
1) TimeData
easterSunday
tentative :: TimeData
tentative = TimeData -> TimeData -> TimeData
predLastOf (Int -> TimeData
dayOfWeek Int
6) (Int -> TimeData
month Int
3)
alternative :: TimeData
alternative = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Day (-Int
7) TimeData
tentative
in do
TimeData
day <- TimeData -> TimeData -> TimeData -> Maybe TimeData
intersectWithReplacement TimeData
holySaturday TimeData
tentative TimeData
alternative
TimeData
start <- TimeData -> TimeData -> Maybe TimeData
intersect TimeData
day (TimeData -> Maybe TimeData) -> TimeData -> Maybe TimeData
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
True Int
20 Int
30
TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed TimeData
start (TimeData -> Maybe TimeData) -> TimeData -> Maybe TimeData
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Minute Int
60 TimeData
start )
]
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleAbsorptionOfAfterNamedDay
, Rule
ruleAfternoon
, Rule
ruleDimTimePartofday
, Rule
ruleDurationAgo
, Rule
ruleDurationFromNow
, Rule
ruleEveningnight
, Rule
ruleHhmmMilitaryTimeofday
, Rule
ruleHhmmTimeofday
, Rule
ruleInDuration
, Rule
ruleInduringThePartofday
, Rule
ruleIntegerLatentTimeofday
, Rule
ruleIntersect
, Rule
ruleIntersectBy
, Rule
ruleLastCycle
, Rule
ruleLastNCycle
, Rule
ruleNCycleLast
, Rule
ruleLastNight
, Rule
ruleLastTime
, Rule
ruleLastYear
, Rule
ruleMidnight
, Rule
ruleMmdd
, Rule
ruleMmddyyyy
, Rule
ruleMorning
, Rule
ruleNamedmonthDayofmonth
, Rule
ruleNextCycle
, Rule
ruleNextNCycle
, Rule
ruleNCycleNext
, Rule
ruleNextTime
, Rule
ruleNextYear
, Rule
ruleNoon
, Rule
ruleNow
, Rule
ruleNthTimeOfTime
, Rule
ruleNthTimeOfTime2
, Rule
rulePartofdayDimTime
, Rule
ruleRelativeMinutesAfterpastIntegerHourofday
, Rule
ruleRelativeMinutesAfterpastNoonmidnight
, Rule
ruleRelativeMinutesTotillbeforeIntegerHourofday
, Rule
ruleRelativeMinutesTotillbeforeNoonmidnight
, Rule
ruleQuarterAfterpastIntegerHourofday
, Rule
ruleQuarterAfterpastNoonmidnight
, Rule
ruleQuarterTotillbeforeIntegerHourofday
, Rule
ruleQuarterTotillbeforeNoonmidnight
, Rule
ruleHalfAfterpastIntegerHourofday
, Rule
ruleHalfAfterpastNoonmidnight
, Rule
ruleHalfTotillbeforeIntegerHourofday
, Rule
ruleHalfTotillbeforeNoonmidnight
, Rule
ruleTheCycleAfterTime
, Rule
ruleTheCycleBeforeTime
, Rule
ruleTheDayAfterTomorrow
, Rule
ruleTwoDaysAfterTomorrow
, Rule
ruleTheDayBeforeYesterday
, Rule
ruleThisCycle
, Rule
ruleThisDayofweek
, Rule
ruleThisTime
, Rule
ruleThisYear
, Rule
ruleNextDayofweek
, Rule
ruleTimeofdayAmpm
, Rule
ruleTimeofdayOclock
, Rule
ruleToday
, Rule
ruleTomorrow
, Rule
ruleTomorrowNight
, Rule
ruleTonight
, Rule
ruleWeekend
, Rule
ruleYearNumericWithYearSymbol
, Rule
ruleYearNumericWithYearSymbol2
, Rule
ruleYesterday
, Rule
ruleYyyymmdd
, Rule
ruleTimezone
, Rule
ruleRelativeMinutesAfterpastIntegerHourofday2
, Rule
ruleRelativeMinutesAfterpastIntegerHourofday3
, Rule
ruleRelativeMinutesAfterpastIntegerHourofday4
, Rule
ruleRelativeMinutesAfterpastIntegerHourofday5
, Rule
ruleRelativeMinutesAfterpastIntegerHourofday6
, Rule
ruleRelativeMinutesAfterpastIntegerHourofday7
, Rule
ruleLastDuration
, Rule
ruleDayOfMonth
]
[Rule] -> [Rule] -> [Rule]
forall a. [a] -> [a] -> [a]
++ [Rule]
ruleDaysOfWeek
[Rule] -> [Rule] -> [Rule]
forall a. [a] -> [a] -> [a]
++ [Rule]
ruleMonths
[Rule] -> [Rule] -> [Rule]
forall a. [a] -> [a] -> [a]
++ [Rule]
ruleComputedHolidays
[Rule] -> [Rule] -> [Rule]
forall a. [a] -> [a] -> [a]
++ [Rule]
ruleComputedHolidays'
[Rule] -> [Rule] -> [Rule]
forall a. [a] -> [a] -> [a]
++ [Rule]
rulePeriodicHolidays