2017-04-28 19:54:35 +03:00
|
|
|
|
-- Copyright (c) 2016-present, Facebook, Inc.
|
|
|
|
|
-- All rights reserved.
|
|
|
|
|
--
|
|
|
|
|
-- This source code is licensed under the BSD-style license found in the
|
2019-05-22 20:36:43 +03:00
|
|
|
|
-- LICENSE file in the root directory of this source tree.
|
2017-04-28 19:54:35 +03:00
|
|
|
|
|
|
|
|
|
{-# LANGUAGE GADTs #-}
|
|
|
|
|
{-# LANGUAGE NoRebindableSyntax #-}
|
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
|
|
|
|
|
module Duckling.Time.HE.Rules
|
2019-12-11 23:19:11 +03:00
|
|
|
|
( rules
|
|
|
|
|
) where
|
2017-04-28 19:54:35 +03:00
|
|
|
|
|
|
|
|
|
import Data.Maybe
|
|
|
|
|
import Data.String
|
|
|
|
|
import Data.Text (Text)
|
|
|
|
|
import Prelude
|
|
|
|
|
import qualified Data.Text as Text
|
|
|
|
|
|
|
|
|
|
import Duckling.Dimensions.Types
|
2019-12-11 23:19:11 +03:00
|
|
|
|
import Duckling.Duration.Helpers (isGrain)
|
2017-04-28 19:54:35 +03:00
|
|
|
|
import Duckling.Numeral.Helpers (parseInt)
|
2019-12-11 23:19:11 +03:00
|
|
|
|
import Duckling.Numeral.Types (NumeralData(..))
|
|
|
|
|
import Duckling.Ordinal.Types (OrdinalData(..))
|
2017-04-28 19:54:35 +03:00
|
|
|
|
import Duckling.Regex.Types
|
|
|
|
|
import Duckling.Time.Helpers
|
2019-12-11 23:19:11 +03:00
|
|
|
|
import Duckling.Time.Types (TimeData(..))
|
2017-04-28 19:54:35 +03:00
|
|
|
|
import Duckling.Types
|
|
|
|
|
import qualified Duckling.Numeral.Types as TNumeral
|
|
|
|
|
import qualified Duckling.Ordinal.Types as TOrdinal
|
|
|
|
|
import qualified Duckling.TimeGrain.Types as TG
|
|
|
|
|
import qualified Duckling.Time.Types as TTime
|
|
|
|
|
|
|
|
|
|
ruleNextDayofweek :: Rule
|
|
|
|
|
ruleNextDayofweek = Rule
|
|
|
|
|
{ name = "next <day-of-week>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isADayOfWeek
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "(הבא(ה)?)"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td:_) ->
|
|
|
|
|
tt $ predNth 1 True td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNamedday :: Rule
|
|
|
|
|
ruleNamedday = Rule
|
|
|
|
|
{ name = "ב <named-day>"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "ב"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isADayOfWeek
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:x:_) -> Just x
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleAtHourTimeofday :: Rule
|
|
|
|
|
ruleAtHourTimeofday = Rule
|
|
|
|
|
{ name = "at hour <time-of-day>"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "בשעה"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isATimeOfDay
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token Time td:_) ->
|
|
|
|
|
tt $ notLatent td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleHourofdayAndInteger :: Rule
|
|
|
|
|
ruleHourofdayAndInteger = Rule
|
|
|
|
|
{ name = "<hour-of-day> and <integer>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isAnHourOfDay
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "ו"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate $ isIntegerBetween 1 59
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
|
|
|
|
|
_:
|
|
|
|
|
token:
|
|
|
|
|
_) -> do
|
|
|
|
|
n <- getIntValue token
|
|
|
|
|
tt $ hourMinute is12H hours n
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleHourofdayAndQuarter :: Rule
|
|
|
|
|
ruleHourofdayAndQuarter = Rule
|
|
|
|
|
{ name = "<hour-of-day> and quarter"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isAnHourOfDay
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "ו"
|
|
|
|
|
, regex "רבע(י)?"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:_) ->
|
|
|
|
|
tt $ hourMinute is12H hours 15
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleHourofdayAndHalf :: Rule
|
|
|
|
|
ruleHourofdayAndHalf = Rule
|
|
|
|
|
{ name = "<hour-of-day> and half"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isAnHourOfDay
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "ו"
|
|
|
|
|
, regex "חצי|מחצית"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:_) ->
|
|
|
|
|
tt $ hourMinute is12H hours 30
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleHourofdayInteger :: Rule
|
|
|
|
|
ruleHourofdayInteger = Rule
|
|
|
|
|
{ name = "<hour-of-day> <integer>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isAnHourOfDay
|
|
|
|
|
, Predicate $ isIntegerBetween 1 59
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
|
|
|
|
|
token:
|
|
|
|
|
_) -> do
|
|
|
|
|
n <- getIntValue token
|
|
|
|
|
tt $ hourMinute is12H hours n
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleHourofdayQuarter :: Rule
|
|
|
|
|
ruleHourofdayQuarter = Rule
|
|
|
|
|
{ name = "<hour-of-day> quarter"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isAnHourOfDay
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "רבע(י)?"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:_) ->
|
|
|
|
|
tt $ hourMinute is12H hours 15
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleHourofdayHalf :: Rule
|
|
|
|
|
ruleHourofdayHalf = Rule
|
|
|
|
|
{ name = "<hour-of-day> half"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isAnHourOfDay
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "חצי|מחצית"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:_) ->
|
|
|
|
|
tt $ hourMinute is12H hours 30
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleIntegerTotillbeforeIntegerHourofday :: Rule
|
|
|
|
|
ruleIntegerTotillbeforeIntegerHourofday = Rule
|
|
|
|
|
{ name = "<integer> to|till|before <integer> (hour-of-day)"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate $ isIntegerBetween 1 59
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "לפני|ל"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isAnHourOfDay
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(token:_:Token Time td:_) -> do
|
|
|
|
|
n <- getIntValue token
|
2018-08-15 22:43:25 +03:00
|
|
|
|
Token Time <$> minutesBefore n td
|
2017-04-28 19:54:35 +03:00
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleQuarterTotillbeforeIntegerHourofday :: Rule
|
|
|
|
|
ruleQuarterTotillbeforeIntegerHourofday = Rule
|
|
|
|
|
{ name = "quarter to|till|before <integer> (hour-of-day)"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "רבע(י)?"
|
|
|
|
|
, regex "לפני|ל"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isAnHourOfDay
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:_:Token Time td:_) -> Token Time <$> minutesBefore 15 td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleHalfTotillbeforeIntegerHourofday :: Rule
|
|
|
|
|
ruleHalfTotillbeforeIntegerHourofday = Rule
|
|
|
|
|
{ name = "half to|till|before <integer> (hour-of-day)"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "חצי|מחצית"
|
|
|
|
|
, regex "לפני|ל"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isAnHourOfDay
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:_:Token Time td:_) -> Token Time <$> minutesBefore 30 td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleIntegerAfterpastIntegerHourofday :: Rule
|
|
|
|
|
ruleIntegerAfterpastIntegerHourofday = Rule
|
|
|
|
|
{ name = "integer after|past <integer> (hour-of-day)"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate $ isIntegerBetween 1 59
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "אחרי"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isAnHourOfDay
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(token:_:Token Time td:_) -> do
|
|
|
|
|
n <- getIntValue token
|
2018-08-15 22:43:25 +03:00
|
|
|
|
Token Time <$> minutesAfter n td
|
2017-04-28 19:54:35 +03:00
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleQuarterAfterpastIntegerHourofday :: Rule
|
|
|
|
|
ruleQuarterAfterpastIntegerHourofday = Rule
|
|
|
|
|
{ name = "quarter after|past <integer> (hour-of-day)"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "רבע(י)?"
|
|
|
|
|
, regex "אחרי"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isAnHourOfDay
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:_:Token Time td:_) -> Token Time <$> minutesAfter 15 td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleHalfAfterpastIntegerHourofday :: Rule
|
|
|
|
|
ruleHalfAfterpastIntegerHourofday = Rule
|
|
|
|
|
{ name = "half after|past <integer> (hour-of-day)"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "חצי|מחצית"
|
|
|
|
|
, regex "אחרי"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isAnHourOfDay
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token Time td:_) -> Token Time <$> minutesAfter 30 td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNamedday2 :: Rule
|
|
|
|
|
ruleNamedday2 = Rule
|
|
|
|
|
{ name = "named-day"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "(יום )?שני"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \_ -> tt $ dayOfWeek 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleSinceTimeofday :: Rule
|
|
|
|
|
ruleSinceTimeofday = Rule
|
|
|
|
|
{ name = "since <time-of-day>"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "מ"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token Time td:_) -> tt $ withDirection TTime.After td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleLastTime :: Rule
|
|
|
|
|
ruleLastTime = Rule
|
|
|
|
|
{ name = "last <time>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension Time
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "שעבר|(ה)?קודם|(ה)?אחרון"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td:_) ->
|
|
|
|
|
tt $ predNth (-1) False td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNamedday6 :: Rule
|
|
|
|
|
ruleNamedday6 = Rule
|
|
|
|
|
{ name = "named-day"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "(יום )?שישי"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \_ -> tt $ dayOfWeek 5
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleDatetimeDatetimeInterval :: Rule
|
|
|
|
|
ruleDatetimeDatetimeInterval = Rule
|
|
|
|
|
{ name = "<datetime> - <datetime> (interval)"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isNotLatent
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "\\-|ע(ד)?"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isNotLatent
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td1:_:Token Time td2:_) ->
|
2017-05-11 01:41:26 +03:00
|
|
|
|
Token Time <$> interval TTime.Closed td1 td2
|
2017-04-28 19:54:35 +03:00
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleTheDayofmonthNonOrdinal :: Rule
|
|
|
|
|
ruleTheDayofmonthNonOrdinal = Rule
|
|
|
|
|
{ name = "the <day-of-month> (non ordinal)"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "ה/S"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isDOMInteger
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:token:_) -> do
|
|
|
|
|
n <- getIntValue token
|
|
|
|
|
tt . mkLatent $ dayOfMonth n
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleCycleAfterTime :: Rule
|
|
|
|
|
ruleCycleAfterTime = Rule
|
|
|
|
|
{ name = "<cycle> after <time>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension TimeGrain
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "אחרי"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token TimeGrain grain:_:Token Time td:_) ->
|
|
|
|
|
tt $ cycleNthAfter False grain 1 td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleInDuration :: Rule
|
|
|
|
|
ruleInDuration = Rule
|
|
|
|
|
{ name = "in <duration>"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "בעוד"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Duration
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token Duration dd:_) -> tt $ inDuration dd
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleInNamedmonth :: Rule
|
|
|
|
|
ruleInNamedmonth = Rule
|
|
|
|
|
{ name = "in <named-month>"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "ב"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isAMonth
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:x:_) -> Just x
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNow :: Rule
|
|
|
|
|
ruleNow = Rule
|
|
|
|
|
{ name = "now"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "עכשיו|מייד"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
2018-08-15 22:43:25 +03:00
|
|
|
|
, prod = \_ -> tt now
|
2017-04-28 19:54:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleCurrentDayofweek :: Rule
|
|
|
|
|
ruleCurrentDayofweek = Rule
|
|
|
|
|
{ name = "current <day-of-week>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isADayOfWeek
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "(הזה|הזאת|הקרוב(ה)?)"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td:_) ->
|
|
|
|
|
tt $ predNth 0 True td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleFromDatetimeDatetimeInterval :: Rule
|
|
|
|
|
ruleFromDatetimeDatetimeInterval = Rule
|
|
|
|
|
{ name = "from <datetime> - <datetime> (interval)"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "מ|משעה"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "\\-|עד"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token Time td1:_:Token Time td2:_) ->
|
2017-05-11 01:41:26 +03:00
|
|
|
|
Token Time <$> interval TTime.Closed td1 td2
|
2017-04-28 19:54:35 +03:00
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNamedday4 :: Rule
|
|
|
|
|
ruleNamedday4 = Rule
|
|
|
|
|
{ name = "named-day"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "(יום )?רביעי"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \_ -> tt $ dayOfWeek 3
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleTheCycleAfterTime :: Rule
|
|
|
|
|
ruleTheCycleAfterTime = Rule
|
|
|
|
|
{ name = "the <cycle> after <time>"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "ה"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension TimeGrain
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "אחרי"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token TimeGrain grain:_:Token Time td:_) ->
|
|
|
|
|
tt $ cycleNthAfter False grain 1 td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleTheCycleBeforeTime :: Rule
|
|
|
|
|
ruleTheCycleBeforeTime = Rule
|
|
|
|
|
{ name = "the <cycle> before <time>"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "ה"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension TimeGrain
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "לפני"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token TimeGrain grain:_:Token Time td:_) ->
|
|
|
|
|
tt $ cycleNthAfter False grain (-1) td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleLastDayofweek :: Rule
|
|
|
|
|
ruleLastDayofweek = Rule
|
|
|
|
|
{ name = "last <day-of-week>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isADayOfWeek
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "(שעבר(ה)?|הקודמת|הקודם)"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td:_) ->
|
|
|
|
|
tt $ predNth 0 True td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleTheIdesOfNamedmonth :: Rule
|
|
|
|
|
ruleTheIdesOfNamedmonth = Rule
|
|
|
|
|
{ name = "the ides of <named-month>"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "באמצע"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isAMonth
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token Time td@TimeData {TTime.form = Just (TTime.Month m)}:_) ->
|
|
|
|
|
Token Time <$>
|
|
|
|
|
intersect td (dayOfMonth $ if elem m [3, 5, 7, 10] then 15 else 13)
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNoon :: Rule
|
|
|
|
|
ruleNoon = Rule
|
|
|
|
|
{ name = "noon"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "(ב)?צהריים"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \_ -> tt $ hour False 12
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleToday :: Rule
|
|
|
|
|
ruleToday = Rule
|
|
|
|
|
{ name = "today"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "היום"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
2018-08-15 22:43:25 +03:00
|
|
|
|
, prod = \_ -> tt today
|
2017-04-28 19:54:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleBetweenTimeofdayAndTimeofdayInterval :: Rule
|
|
|
|
|
ruleBetweenTimeofdayAndTimeofdayInterval = Rule
|
|
|
|
|
{ name = "between <time-of-day> and <time-of-day> (interval)"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "בין"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isATimeOfDay
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "ל"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isATimeOfDay
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token Time td1:_:Token Time td2:_) ->
|
2017-05-11 01:41:26 +03:00
|
|
|
|
Token Time <$> interval TTime.Closed td1 td2
|
2017-04-28 19:54:35 +03:00
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNextCycle :: Rule
|
|
|
|
|
ruleNextCycle = Rule
|
|
|
|
|
{ name = "next <cycle>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension TimeGrain
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "הבא(ה)?"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token TimeGrain grain:_) -> tt $ cycleNth grain 1
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleForDuration :: Rule
|
|
|
|
|
ruleForDuration = Rule
|
|
|
|
|
{ name = "for <duration>"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "תוך"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Duration
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token Duration dd:_) ->
|
|
|
|
|
tt $ inDuration dd
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleDurationFromNow :: Rule
|
|
|
|
|
ruleDurationFromNow = Rule
|
|
|
|
|
{ name = "<duration> from now"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension Duration
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "מעכשיו"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Duration dd:_) ->
|
|
|
|
|
tt $ inDuration dd
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleLunch :: Rule
|
|
|
|
|
ruleLunch = Rule
|
|
|
|
|
{ name = "lunch"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "(ב)?צהריים"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
2017-05-11 01:41:26 +03:00
|
|
|
|
, prod = \_ -> Token Time . partOfDay . mkLatent <$>
|
|
|
|
|
interval TTime.Open (hour False 12) (hour False 14)
|
2017-04-28 19:54:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleLastCycle :: Rule
|
|
|
|
|
ruleLastCycle = Rule
|
|
|
|
|
{ name = "last <cycle>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension TimeGrain
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "האחרון|האחרונה|שעבר|שעברה"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token TimeGrain grain:_) ->
|
|
|
|
|
tt . cycleNth grain $ - 1
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleAfternoon :: Rule
|
|
|
|
|
ruleAfternoon = Rule
|
|
|
|
|
{ name = "afternoon"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "אחה(״)?צ|אחר הצהריים"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
2017-05-11 01:41:26 +03:00
|
|
|
|
, prod = \_ -> Token Time . partOfDay . mkLatent <$>
|
|
|
|
|
interval TTime.Open (hour False 12) (hour False 19)
|
2017-04-28 19:54:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNamedmonthDayofmonthOrdinal :: Rule
|
|
|
|
|
ruleNamedmonthDayofmonthOrdinal = Rule
|
|
|
|
|
{ name = "<named-month> <day-of-month> (ordinal)"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isAMonth
|
|
|
|
|
, Predicate isDOMOrdinal
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td:token:_) -> Token Time <$> intersectDOM td token
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNamedday5 :: Rule
|
|
|
|
|
ruleNamedday5 = Rule
|
|
|
|
|
{ name = "named-day"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "(יום )?חמישי"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \_ -> tt $ dayOfWeek 4
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleDayofmonthordinalNamedmonth :: Rule
|
|
|
|
|
ruleDayofmonthordinalNamedmonth = Rule
|
|
|
|
|
{ name = "<day-of-month>(ordinal) <named-month>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isDOMOrdinal
|
|
|
|
|
, Predicate isAMonth
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(token:Token Time td:_) -> Token Time <$> intersectDOM td token
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleIntersectBy :: Rule
|
|
|
|
|
ruleIntersectBy = Rule
|
|
|
|
|
{ name = "intersect by \",\""
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isNotLatent
|
|
|
|
|
, regex ","
|
|
|
|
|
, Predicate isNotLatent
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td1:_:Token Time td2:_) -> Token Time <$> intersect td1 td2
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNthTimeAfterTime :: Rule
|
|
|
|
|
ruleNthTimeAfterTime = Rule
|
|
|
|
|
{ name = "nth <time> after <time>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension Ordinal
|
|
|
|
|
, dimension Time
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "אחרי"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Ordinal od:Token Time td1:_:Token Time td2:_) ->
|
|
|
|
|
tt $ predNthAfter (TOrdinal.value od - 1) td1 td2
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleMmdd :: Rule
|
|
|
|
|
ruleMmdd = Rule
|
|
|
|
|
{ name = "mm/dd"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ regex "(0?[1-9]|1[0-2])/(3[01]|[12]\\d|0?[1-9])"
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token RegexMatch (GroupMatch (mm:dd:_)):_) -> do
|
|
|
|
|
m <- parseInt mm
|
|
|
|
|
d <- parseInt dd
|
|
|
|
|
tt $ monthDay m d
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleAfterDuration :: Rule
|
|
|
|
|
ruleAfterDuration = Rule
|
|
|
|
|
{ name = "after <duration>"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "אחרי"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Duration
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token Duration dd:_) -> tt . withDirection TTime.After $ inDuration dd
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleTimeofdayLatent :: Rule
|
|
|
|
|
ruleTimeofdayLatent = Rule
|
|
|
|
|
{ name = "time-of-day (latent)"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate $ isIntegerBetween 0 23
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(token:_) -> do
|
|
|
|
|
n <- getIntValue token
|
|
|
|
|
tt . mkLatent $ hour True n
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleDayofmonthOrdinalOfNamedmonth :: Rule
|
|
|
|
|
ruleDayofmonthOrdinalOfNamedmonth = Rule
|
|
|
|
|
{ name = "<day-of-month> (ordinal) of <named-month>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isDOMOrdinal
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "של|ב|ל"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isAMonth
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(token:_:Token Time td:_) -> Token Time <$> intersectDOM td token
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleThisEvening :: Rule
|
|
|
|
|
ruleThisEvening = Rule
|
|
|
|
|
{ name = "this evening"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "הערב"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
2017-05-11 01:41:26 +03:00
|
|
|
|
, prod = \_ -> do
|
|
|
|
|
td <- interval TTime.Open (hour False 18) (hour False 0)
|
2018-08-15 22:43:25 +03:00
|
|
|
|
Token Time . partOfDay <$> intersect today td
|
2017-04-28 19:54:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleBetweenDatetimeAndDatetimeInterval :: Rule
|
|
|
|
|
ruleBetweenDatetimeAndDatetimeInterval = Rule
|
|
|
|
|
{ name = "between <datetime> and <datetime> (interval)"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "בין"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "ל"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token Time td1:_:Token Time td2:_) ->
|
2017-05-11 01:41:26 +03:00
|
|
|
|
Token Time <$> interval TTime.Closed td1 td2
|
2017-04-28 19:54:35 +03:00
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleEndOfYear :: Rule
|
|
|
|
|
ruleEndOfYear = Rule
|
|
|
|
|
{ name = "End of year"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "סוף (ה)?שנה"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \_ -> tt $ cycleNth TG.Year 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleDurationAgo :: Rule
|
|
|
|
|
ruleDurationAgo = Rule
|
|
|
|
|
{ name = "<duration> ago"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "לפני"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Duration
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token Duration dd:_) ->
|
|
|
|
|
tt $ durationAgo dd
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleLastNCycle :: Rule
|
|
|
|
|
ruleLastNCycle = Rule
|
|
|
|
|
{ name = "last n <cycle>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate $ isIntegerBetween 1 9999
|
|
|
|
|
, dimension TimeGrain
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "אחרון|אחרונות|אחרונה|אחרונים"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(token:Token TimeGrain grain:_) -> do
|
|
|
|
|
v <- getIntValue token
|
|
|
|
|
tt . cycleN True grain $ - v
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleMidnighteodendOfDay :: Rule
|
|
|
|
|
ruleMidnighteodendOfDay = Rule
|
|
|
|
|
{ name = "midnight|EOD|end of day"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "(ב)?חצות"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \_ -> tt $ hour False 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleDayofmonthNonOrdinalNamedmonth :: Rule
|
|
|
|
|
ruleDayofmonthNonOrdinalNamedmonth = Rule
|
|
|
|
|
{ name = "<day-of-month> (non ordinal) <named-month>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isDOMInteger
|
|
|
|
|
, Predicate isAMonth
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(token:Token Time td:_) -> Token Time <$> intersectDOM td token
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleIntersect :: Rule
|
|
|
|
|
ruleIntersect = Rule
|
|
|
|
|
{ name = "intersect"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isNotLatent
|
|
|
|
|
, Predicate isNotLatent
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td1:Token Time td2:_) -> Token Time <$> intersect td1 td2
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleUntilTimeofday :: Rule
|
|
|
|
|
ruleUntilTimeofday = Rule
|
|
|
|
|
{ name = "until <time-of-day>"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "עד"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token Time td:_) ->
|
|
|
|
|
tt $ withDirection TTime.Before td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleAtTimeofday :: Rule
|
|
|
|
|
ruleAtTimeofday = Rule
|
|
|
|
|
{ name = "at <time-of-day>"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "ב"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isATimeOfDay
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token Time td:_) -> tt $ notLatent td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNthTimeOfTime :: Rule
|
|
|
|
|
ruleNthTimeOfTime = Rule
|
|
|
|
|
{ name = "nth <time> of <time>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension Time
|
|
|
|
|
, dimension Ordinal
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "של|ב"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td1:Token Ordinal od:_:Token Time td2:_) -> Token Time .
|
|
|
|
|
predNth (TOrdinal.value od - 1) False <$> intersect td2 td1
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleTimePartofday :: Rule
|
|
|
|
|
ruleTimePartofday = Rule
|
|
|
|
|
{ name = "<time> <part-of-day>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension Time
|
|
|
|
|
, Predicate isAPartOfDay
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td:Token Time pod:_) -> Token Time <$> intersect pod td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleWeekend :: Rule
|
|
|
|
|
ruleWeekend = Rule
|
|
|
|
|
{ name = "week-end"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "(סופ״ש|סוף השבוע)"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
2017-08-22 20:16:17 +03:00
|
|
|
|
, prod = \_ -> tt weekend
|
2017-04-28 19:54:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNameddayDayofmonthOrdinal :: Rule
|
|
|
|
|
ruleNameddayDayofmonthOrdinal = Rule
|
|
|
|
|
{ name = "<named-day> <day-of-month> (ordinal)"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isADayOfWeek
|
|
|
|
|
, Predicate isDOMOrdinal
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td:token:_) -> Token Time <$> intersectDOM td token
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleDate :: Rule
|
|
|
|
|
ruleDate = Rule
|
|
|
|
|
{ name = "ב <date>"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "ב"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:x:_) -> Just x
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNextTime :: Rule
|
|
|
|
|
ruleNextTime = Rule
|
|
|
|
|
{ name = "next <time>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isNotLatent
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "הבא(ה)?"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td:_) -> tt $ predNth 0 True td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleOrdinalQuarterYear :: Rule
|
|
|
|
|
ruleOrdinalQuarterYear = Rule
|
|
|
|
|
{ name = "<ordinal> quarter <year>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension Ordinal
|
|
|
|
|
, Predicate $ isGrain TG.Quarter
|
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Ordinal od:_:Token Time td:_) ->
|
|
|
|
|
tt $ cycleNthAfter False TG.Quarter (TOrdinal.value od - 1) td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleYyyymmdd :: Rule
|
|
|
|
|
ruleYyyymmdd = Rule
|
|
|
|
|
{ name = "yyyy-mm-dd"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ regex "(\\d{2,4})-(0?[1-9]|1[0-2])-(3[01]|[12]\\d|0?[1-9])"
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token RegexMatch (GroupMatch (yy:mm:dd:_)):_) -> do
|
|
|
|
|
y <- parseInt yy
|
|
|
|
|
m <- parseInt mm
|
|
|
|
|
d <- parseInt dd
|
|
|
|
|
tt $ yearMonthDay y m d
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleTheOrdinalCycleAfterTime :: Rule
|
|
|
|
|
ruleTheOrdinalCycleAfterTime = Rule
|
|
|
|
|
{ name = "the <ordinal> <cycle> after <time>"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "ה"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Ordinal
|
|
|
|
|
, dimension TimeGrain
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "אחרי|לאחר"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token Ordinal od:Token TimeGrain grain:_:Token Time td:_) ->
|
|
|
|
|
tt $ cycleNthAfter True grain (TOrdinal.value od - 1) td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNextNCycle :: Rule
|
|
|
|
|
ruleNextNCycle = Rule
|
|
|
|
|
{ name = "next n <cycle>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate $ isIntegerBetween 1 9999
|
|
|
|
|
, dimension TimeGrain
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "הבא|הבאה|הבאים|הבאות"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(token:Token TimeGrain grain:_) -> do
|
|
|
|
|
v <- getIntValue token
|
|
|
|
|
tt $ cycleN True grain v
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleMorning :: Rule
|
|
|
|
|
ruleMorning = Rule
|
|
|
|
|
{ name = "morning"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "(ב)?בוקר"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
2017-05-11 01:41:26 +03:00
|
|
|
|
, prod = \_ -> Token Time . partOfDay . mkLatent <$>
|
|
|
|
|
interval TTime.Open (hour False 4) (hour False 12)
|
2017-04-28 19:54:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleThisCycle :: Rule
|
|
|
|
|
ruleThisCycle = Rule
|
|
|
|
|
{ name = "this <cycle>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension TimeGrain
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "הקרו(ב)?ה|הזה|הזאת"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token TimeGrain grain:_) ->
|
|
|
|
|
tt $ cycleNth grain 0
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleThisTime :: Rule
|
|
|
|
|
ruleThisTime = Rule
|
|
|
|
|
{ name = "this <time>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension Time
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "הקרוב|הזה"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td:_) ->
|
|
|
|
|
tt $ predNth 0 False td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleDayofmonthNonOrdinalOfNamedmonth :: Rule
|
|
|
|
|
ruleDayofmonthNonOrdinalOfNamedmonth = Rule
|
|
|
|
|
{ name = "<day-of-month> (non ordinal) of <named-month>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isDOMInteger
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "של|ב|ל"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isAMonth
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(token:_:Token Time td:_) -> Token Time <$> intersectDOM td token
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleEndOfMonth :: Rule
|
|
|
|
|
ruleEndOfMonth = Rule
|
|
|
|
|
{ name = "End of month"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "סוף (ה)?חודש"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \_ -> tt $ cycleNth TG.Month 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleYesterday :: Rule
|
|
|
|
|
ruleYesterday = Rule
|
|
|
|
|
{ name = "yesterday"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "(אתמול|אמש)"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \_ -> tt . cycleNth TG.Day $ - 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleAfterTimeofday :: Rule
|
|
|
|
|
ruleAfterTimeofday = Rule
|
|
|
|
|
{ name = "after <time-of-day>"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "אחרי"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token Time td:_) -> tt $ withDirection TTime.After td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleDayofmonthOrdinal :: Rule
|
|
|
|
|
ruleDayofmonthOrdinal = Rule
|
|
|
|
|
{ name = "<day-of-month> (ordinal)"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isDOMOrdinal
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(token:_) -> do
|
|
|
|
|
n <- getIntValue token
|
|
|
|
|
tt . mkLatent $ dayOfMonth n
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleTimeofdayAmpm :: Rule
|
|
|
|
|
ruleTimeofdayAmpm = Rule
|
|
|
|
|
{ name = "<time-of-day> am|pm"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isATimeOfDay
|
|
|
|
|
, regex "(in the )?([ap])(\\s|\\.)?m?\\.?"
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td:Token RegexMatch (GroupMatch (_:ap:_)):_) ->
|
2017-11-14 23:01:46 +03:00
|
|
|
|
tt $ timeOfDayAMPM (Text.toLower ap == "a") td
|
2017-04-28 19:54:35 +03:00
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleOrdinalCycleAfterTime :: Rule
|
|
|
|
|
ruleOrdinalCycleAfterTime = Rule
|
|
|
|
|
{ name = "<ordinal> <cycle> after <time>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension Ordinal
|
|
|
|
|
, dimension TimeGrain
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "אחרי|לאחר"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Ordinal od:Token TimeGrain grain:_:Token Time td:_) ->
|
|
|
|
|
tt $ cycleNthAfter True grain (TOrdinal.value od - 1) td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNamedday7 :: Rule
|
|
|
|
|
ruleNamedday7 = Rule
|
|
|
|
|
{ name = "named-day"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "(יום )?שבת"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \_ -> tt $ dayOfWeek 6
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleHhmm :: Rule
|
|
|
|
|
ruleHhmm = Rule
|
|
|
|
|
{ name = "hh:mm"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ regex "((?:[01]?\\d)|(?:2[0-3]))[:.]([0-5]\\d)"
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token RegexMatch (GroupMatch (hh:mm:_)):_) -> do
|
|
|
|
|
h <- parseInt hh
|
|
|
|
|
m <- parseInt mm
|
|
|
|
|
tt $ hourMinute True h m
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleTimeOfPartofday :: Rule
|
|
|
|
|
ruleTimeOfPartofday = Rule
|
|
|
|
|
{ name = "<time> of <part-of-day>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension Time
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "ב"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isAPartOfDay
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td1:_:Token Time td2:_) -> Token Time <$> intersect td1 td2
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleYear :: Rule
|
|
|
|
|
ruleYear = Rule
|
|
|
|
|
{ name = "year"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate $ isIntegerBetween 1000 2100
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(token:_) -> do
|
|
|
|
|
n <- getIntValue token
|
|
|
|
|
tt $ year n
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNamedmonthDayofmonthNonOrdinal :: Rule
|
|
|
|
|
ruleNamedmonthDayofmonthNonOrdinal = Rule
|
|
|
|
|
{ name = "<named-month> <day-of-month> (non ordinal)"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isAMonth
|
|
|
|
|
, Predicate isDOMInteger
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td:token:_) -> Token Time <$> intersectDOM td token
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNamedday8 :: Rule
|
|
|
|
|
ruleNamedday8 = Rule
|
|
|
|
|
{ name = "named-day"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "(יום )?ראשון"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \_ -> tt $ dayOfWeek 7
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleAbsorptionOfAfterNamedDay :: Rule
|
|
|
|
|
ruleAbsorptionOfAfterNamedDay = Rule
|
|
|
|
|
{ name = "absorption of , after named day"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isADayOfWeek
|
|
|
|
|
, regex ","
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(x:_) -> Just x
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleLastDayofweekOfTime :: Rule
|
|
|
|
|
ruleLastDayofweekOfTime = Rule
|
|
|
|
|
{ name = "last <day-of-week> of <time>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isADayOfWeek
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "האחרון של"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td1:_:Token Time td2:_) ->
|
|
|
|
|
tt $ predLastOf td1 td2
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleHhmmMilitaryAmpm :: Rule
|
|
|
|
|
ruleHhmmMilitaryAmpm = Rule
|
|
|
|
|
{ name = "hhmm (military) am|pm"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ regex "((?:1[012]|0?\\d))([0-5]\\d)"
|
|
|
|
|
, regex "([ap])\\.?m?\\.?"
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token RegexMatch (GroupMatch (hh:mm:_)):Token RegexMatch (GroupMatch (ap:_)):_) -> do
|
|
|
|
|
h <- parseInt hh
|
|
|
|
|
m <- parseInt mm
|
2017-11-14 23:01:46 +03:00
|
|
|
|
tt . timeOfDayAMPM (Text.toLower ap == "a") $ hourMinute True h m
|
2017-04-28 19:54:35 +03:00
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleCycleBeforeTime :: Rule
|
|
|
|
|
ruleCycleBeforeTime = Rule
|
|
|
|
|
{ name = "<cycle> before <time>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension TimeGrain
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "לפני"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token TimeGrain grain:_:Token Time td:_) ->
|
|
|
|
|
tt $ cycleNthAfter False grain (-1) td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleDurationAfterTime :: Rule
|
|
|
|
|
ruleDurationAfterTime = Rule
|
|
|
|
|
{ name = "<duration> after <time>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension Duration
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "אחרי|לאחר"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Duration dd:_:Token Time td:_) ->
|
|
|
|
|
tt $ durationAfter dd td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleEveningnight :: Rule
|
|
|
|
|
ruleEveningnight = Rule
|
|
|
|
|
{ name = "evening|night"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "(ב)?ערב"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
2017-05-11 01:41:26 +03:00
|
|
|
|
, prod = \_ -> Token Time . partOfDay . mkLatent <$>
|
|
|
|
|
interval TTime.Open (hour False 18) (hour False 0)
|
2017-04-28 19:54:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleOrdinalQuarter :: Rule
|
|
|
|
|
ruleOrdinalQuarter = Rule
|
|
|
|
|
{ name = "<ordinal> quarter"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension Ordinal
|
|
|
|
|
, Predicate $ isGrain TG.Quarter
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(token:_) -> do
|
|
|
|
|
n <- getIntValue token
|
|
|
|
|
tt . cycleNthAfter True TG.Quarter (n - 1) $
|
|
|
|
|
cycleNth TG.Year 0
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleNamedday3 :: Rule
|
|
|
|
|
ruleNamedday3 = Rule
|
|
|
|
|
{ name = "named-day"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "(יום )?שלישי"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \_ -> tt $ dayOfWeek 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleTheDayofmonthOrdinal :: Rule
|
|
|
|
|
ruleTheDayofmonthOrdinal = Rule
|
|
|
|
|
{ name = "the <day-of-month> (ordinal)"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "ה"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isDOMOrdinal
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:
|
2018-01-30 03:41:23 +03:00
|
|
|
|
Token Ordinal OrdinalData{TOrdinal.value = v}:
|
2017-04-28 19:54:35 +03:00
|
|
|
|
_) -> tt $ dayOfMonth v
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleDurationBeforeTime :: Rule
|
|
|
|
|
ruleDurationBeforeTime = Rule
|
|
|
|
|
{ name = "<duration> before <time>"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ dimension Duration
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "לפני"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Duration dd:_:Token Time td:_) ->
|
|
|
|
|
tt $ durationBefore dd td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rulePartofdayOfTime :: Rule
|
|
|
|
|
rulePartofdayOfTime = Rule
|
|
|
|
|
{ name = "<part-of-day> of <time>"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "ב"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, Predicate isAPartOfDay
|
2017-09-07 22:33:31 +03:00
|
|
|
|
, regex "של"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
, dimension Time
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(_:Token Time td1:_:Token Time td2:_) -> Token Time <$> intersect td1 td2
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleMmddyyyy :: Rule
|
|
|
|
|
ruleMmddyyyy = Rule
|
|
|
|
|
{ name = "mm/dd/yyyy"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ regex "(0?[1-9]|1[0-2])[/-](3[01]|[12]\\d|0?[1-9])[-/](\\d{2,4})"
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token RegexMatch (GroupMatch (mm:dd:yy:_)):_) -> do
|
|
|
|
|
y <- parseInt yy
|
|
|
|
|
m <- parseInt mm
|
|
|
|
|
d <- parseInt dd
|
|
|
|
|
tt $ yearMonthDay y m d
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleTomorrow :: Rule
|
|
|
|
|
ruleTomorrow = Rule
|
|
|
|
|
{ name = "tomorrow"
|
|
|
|
|
, pattern =
|
2017-09-07 22:33:31 +03:00
|
|
|
|
[ regex "(מחר|למחרת)"
|
2017-04-28 19:54:35 +03:00
|
|
|
|
]
|
|
|
|
|
, prod = \_ -> tt $ cycleNth TG.Day 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleTimeofdayOclock :: Rule
|
|
|
|
|
ruleTimeofdayOclock = Rule
|
|
|
|
|
{ name = "<time-of-day> o'clock"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isATimeOfDay
|
|
|
|
|
, regex "o.?clock"
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token Time td:_) -> tt $ notLatent td
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleDayofmonthordinalNamedmonthYear :: Rule
|
|
|
|
|
ruleDayofmonthordinalNamedmonthYear = Rule
|
|
|
|
|
{ name = "<day-of-month>(ordinal) <named-month> year"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ Predicate isDOMOrdinal
|
|
|
|
|
, Predicate isAMonth
|
|
|
|
|
, regex "(\\d{2,4})"
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(token:Token Time td:Token RegexMatch (GroupMatch (match:_)):_) -> do
|
|
|
|
|
intVal <- parseInt match
|
|
|
|
|
dom <- intersectDOM td token
|
|
|
|
|
Token Time <$> intersect dom (year intVal)
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleHhmmss :: Rule
|
|
|
|
|
ruleHhmmss = Rule
|
|
|
|
|
{ name = "hh:mm:ss"
|
|
|
|
|
, pattern =
|
|
|
|
|
[ regex "((?:[01]?\\d)|(?:2[0-3]))[:.]([0-5]\\d)[:.]([0-5]\\d)"
|
|
|
|
|
]
|
|
|
|
|
, prod = \tokens -> case tokens of
|
|
|
|
|
(Token RegexMatch (GroupMatch (hh:mm:ss:_)):_) -> do
|
|
|
|
|
h <- parseInt hh
|
|
|
|
|
m <- parseInt mm
|
|
|
|
|
s <- parseInt ss
|
|
|
|
|
tt $ hourMinuteSecond True h m s
|
|
|
|
|
_ -> Nothing
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 01:39:29 +03:00
|
|
|
|
ruleMonths :: [Rule]
|
|
|
|
|
ruleMonths = mkRuleMonths
|
2017-09-27 01:56:22 +03:00
|
|
|
|
[ ( "ינואר", "ינואר" )
|
|
|
|
|
, ( "פברואר", "פברואר" )
|
|
|
|
|
, ( "מרץ", "מרץ" )
|
|
|
|
|
, ( "אפריל", "אפריל" )
|
|
|
|
|
, ( "מאי", "מאי" )
|
|
|
|
|
, ( "יוני", "יוני" )
|
|
|
|
|
, ( "יולי", "יולי" )
|
|
|
|
|
, ( "אוגוסט", "אוגוסט" )
|
|
|
|
|
, ( "ספטמבר", "ספטמבר" )
|
|
|
|
|
, ( "אוקטובר", "אוקטובר" )
|
|
|
|
|
, ( "נובמבר", "נובמבר" )
|
|
|
|
|
, ( "דצמבר", "דצמבר" )
|
|
|
|
|
]
|
|
|
|
|
|
2017-04-28 19:54:35 +03:00
|
|
|
|
rules :: [Rule]
|
|
|
|
|
rules =
|
|
|
|
|
[ ruleAbsorptionOfAfterNamedDay
|
|
|
|
|
, ruleAfterDuration
|
|
|
|
|
, ruleAfterTimeofday
|
|
|
|
|
, ruleAfternoon
|
|
|
|
|
, ruleAtHourTimeofday
|
|
|
|
|
, ruleAtTimeofday
|
|
|
|
|
, ruleBetweenDatetimeAndDatetimeInterval
|
|
|
|
|
, ruleBetweenTimeofdayAndTimeofdayInterval
|
|
|
|
|
, ruleCurrentDayofweek
|
|
|
|
|
, ruleCycleAfterTime
|
|
|
|
|
, ruleCycleBeforeTime
|
|
|
|
|
, ruleDate
|
|
|
|
|
, ruleDatetimeDatetimeInterval
|
|
|
|
|
, ruleDayofmonthNonOrdinalNamedmonth
|
|
|
|
|
, ruleDayofmonthNonOrdinalOfNamedmonth
|
|
|
|
|
, ruleDayofmonthOrdinal
|
|
|
|
|
, ruleDayofmonthOrdinalOfNamedmonth
|
|
|
|
|
, ruleDayofmonthordinalNamedmonth
|
|
|
|
|
, ruleDayofmonthordinalNamedmonthYear
|
|
|
|
|
, ruleDurationAfterTime
|
|
|
|
|
, ruleDurationAgo
|
|
|
|
|
, ruleDurationBeforeTime
|
|
|
|
|
, ruleDurationFromNow
|
|
|
|
|
, ruleEndOfMonth
|
|
|
|
|
, ruleEndOfYear
|
|
|
|
|
, ruleEveningnight
|
|
|
|
|
, ruleForDuration
|
|
|
|
|
, ruleFromDatetimeDatetimeInterval
|
|
|
|
|
, ruleHhmm
|
|
|
|
|
, ruleHhmmMilitaryAmpm
|
|
|
|
|
, ruleHhmmss
|
|
|
|
|
, ruleHourofdayAndInteger
|
|
|
|
|
, ruleHourofdayAndQuarter
|
|
|
|
|
, ruleHourofdayAndHalf
|
|
|
|
|
, ruleHourofdayInteger
|
|
|
|
|
, ruleHourofdayQuarter
|
|
|
|
|
, ruleHourofdayHalf
|
|
|
|
|
, ruleInDuration
|
|
|
|
|
, ruleInNamedmonth
|
|
|
|
|
, ruleIntersect
|
|
|
|
|
, ruleIntersectBy
|
|
|
|
|
, ruleLastCycle
|
|
|
|
|
, ruleLastDayofweek
|
|
|
|
|
, ruleLastDayofweekOfTime
|
|
|
|
|
, ruleLastNCycle
|
|
|
|
|
, ruleLastTime
|
|
|
|
|
, ruleLunch
|
|
|
|
|
, ruleMidnighteodendOfDay
|
|
|
|
|
, ruleMmdd
|
|
|
|
|
, ruleMmddyyyy
|
|
|
|
|
, ruleMorning
|
|
|
|
|
, ruleNamedday
|
|
|
|
|
, ruleNamedday2
|
|
|
|
|
, ruleNamedday3
|
|
|
|
|
, ruleNamedday4
|
|
|
|
|
, ruleNamedday5
|
|
|
|
|
, ruleNamedday6
|
|
|
|
|
, ruleNamedday7
|
|
|
|
|
, ruleNamedday8
|
|
|
|
|
, ruleNameddayDayofmonthOrdinal
|
|
|
|
|
, ruleNamedmonthDayofmonthNonOrdinal
|
|
|
|
|
, ruleNamedmonthDayofmonthOrdinal
|
|
|
|
|
, ruleNextCycle
|
|
|
|
|
, ruleNextDayofweek
|
|
|
|
|
, ruleNextNCycle
|
|
|
|
|
, ruleNextTime
|
|
|
|
|
, ruleNoon
|
|
|
|
|
, ruleNow
|
|
|
|
|
, ruleNthTimeAfterTime
|
|
|
|
|
, ruleNthTimeOfTime
|
|
|
|
|
, ruleOrdinalCycleAfterTime
|
|
|
|
|
, ruleOrdinalQuarter
|
|
|
|
|
, ruleOrdinalQuarterYear
|
|
|
|
|
, rulePartofdayOfTime
|
|
|
|
|
, ruleIntegerAfterpastIntegerHourofday
|
|
|
|
|
, ruleQuarterAfterpastIntegerHourofday
|
|
|
|
|
, ruleHalfAfterpastIntegerHourofday
|
|
|
|
|
, ruleIntegerTotillbeforeIntegerHourofday
|
|
|
|
|
, ruleQuarterTotillbeforeIntegerHourofday
|
|
|
|
|
, ruleHalfTotillbeforeIntegerHourofday
|
|
|
|
|
, ruleSinceTimeofday
|
|
|
|
|
, ruleTheCycleAfterTime
|
|
|
|
|
, ruleTheCycleBeforeTime
|
|
|
|
|
, ruleTheDayofmonthNonOrdinal
|
|
|
|
|
, ruleTheDayofmonthOrdinal
|
|
|
|
|
, ruleTheIdesOfNamedmonth
|
|
|
|
|
, ruleTheOrdinalCycleAfterTime
|
|
|
|
|
, ruleThisCycle
|
|
|
|
|
, ruleThisEvening
|
|
|
|
|
, ruleThisTime
|
|
|
|
|
, ruleTimeOfPartofday
|
|
|
|
|
, ruleTimePartofday
|
|
|
|
|
, ruleTimeofdayAmpm
|
|
|
|
|
, ruleTimeofdayLatent
|
|
|
|
|
, ruleTimeofdayOclock
|
|
|
|
|
, ruleToday
|
|
|
|
|
, ruleTomorrow
|
|
|
|
|
, ruleUntilTimeofday
|
|
|
|
|
, ruleWeekend
|
|
|
|
|
, ruleYear
|
|
|
|
|
, ruleYesterday
|
|
|
|
|
, ruleYyyymmdd
|
|
|
|
|
]
|
2017-09-27 01:56:22 +03:00
|
|
|
|
++ ruleMonths
|