Time: Add "today" helper + reuse "tt" helper

Summary: Instead of `cycleNth TG.Day 0` and `Just . Token Time`.

Reviewed By: chinmay87

Differential Revision: D9344258

fbshipit-source-id: 1731c19f0d83640c5716757c70fcefea4655172f
This commit is contained in:
Julien Odent 2018-08-15 12:43:25 -07:00 committed by Facebook Github Bot
parent a3e87589a1
commit 546fa113a6
21 changed files with 154 additions and 240 deletions

View File

@ -691,8 +691,7 @@ ruleHODAndNumeralAfter = Rule
, prod = \tokens -> case tokens of
(Token Time td:token:_) -> do
n <- getIntValue token
t <- minutesAfter n td
Just $ Token Time t
Token Time <$> minutesAfter n td
_ -> Nothing
}
@ -707,8 +706,7 @@ ruleNumeralAfterHOD = Rule
, prod = \tokens -> case tokens of
(token:_:Token Time td:_) -> do
n <- getIntValue token
t <- minutesAfter n td
Just $ Token Time t
Token Time <$> minutesAfter n td
_ -> Nothing
}
@ -905,7 +903,7 @@ rulePODThis = Rule
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Token Time . partOfDay . notLatent <$>
intersect (cycleNth TG.Day 0) td
intersect today td
_ -> Nothing
}
@ -914,7 +912,6 @@ ruleTonight = Rule
{ name = "tonight"
, pattern = [regex "(هذه )?الليل[ةه]"]
, prod = \_ -> do
let today = cycleNth TG.Day 0
evening <- interval TTime.Open (hour False 18) (hour False 0)
Token Time . partOfDay . notLatent <$> intersect today evening
}
@ -933,8 +930,7 @@ ruleAfterPartofday = Rule
"(ال)?مدرس[ةه]" -> Just (hour False 15, hour False 21)
_ -> Nothing
td <- interval TTime.Open start end
Token Time . partOfDay . notLatent <$>
intersect (cycleNth TG.Day 0) td
Token Time . partOfDay . notLatent <$> intersect today td
_ -> Nothing
}

View File

@ -77,8 +77,7 @@ ruleRelativeMinutesTotillbeforeIntegerHourofday = Rule
, prod = \tokens -> case tokens of
(token:_:Token Time td:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
@ -90,9 +89,7 @@ ruleQuarterTotillbeforeIntegerHourofday = Rule
, Predicate isAnHourOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> do
t <- minutesBefore 15 td
Just $ Token Time t
(_:Token Time td:_) -> Token Time <$> minutesBefore 15 td
_ -> Nothing
}
@ -104,9 +101,7 @@ ruleHalfTotillbeforeIntegerHourofday = Rule
, Predicate isAnHourOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> do
t <- minutesBefore 30 td
Just $ Token Time t
(_:Token Time td:_) -> Token Time <$> minutesBefore 30 td
_ -> Nothing
}
@ -456,7 +451,7 @@ ruleToday = Rule
, pattern =
[ regex "i dag|idag"
]
, prod = \_ -> tt $ cycleNth TG.Day 0
, prod = \_ -> tt today
}
ruleThisnextDayofweek :: Rule
@ -906,9 +901,8 @@ ruleAfterWork = Rule
[ regex "efter arbejde"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 17) (hour False 21)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleLastNCycle :: Rule
@ -1223,8 +1217,7 @@ ruleThisPartofday = Rule
, Predicate isAPartOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) ->
Token Time . partOfDay <$> intersect (cycleNth TG.Day 0) td
(_:Token Time td:_) -> Token Time . partOfDay <$> intersect today td
_ -> Nothing
}
@ -1287,9 +1280,8 @@ ruleAfterLunch = Rule
[ regex "efter (frokost|middag)"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 13) (hour False 17)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleOnANamedday :: Rule
@ -1436,9 +1428,8 @@ ruleTonight = Rule
[ regex "i aften"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 18) (hour False 0)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleYear :: Rule

View File

@ -121,8 +121,7 @@ ruleRelativeMinutesTotillbeforeIntegerHourofday = Rule
, prod = \tokens -> case tokens of
(token:_:Token Time td:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
@ -134,9 +133,7 @@ ruleQuarterTotillbeforeIntegerHourofday = Rule
, Predicate isAnHourOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> do
t <- minutesBefore 15 td
Just $ Token Time t
(_:Token Time td:_) -> Token Time <$> minutesBefore 15 td
_ -> Nothing
}
@ -148,9 +145,7 @@ ruleHalfTotillbeforeIntegerHourofday = Rule
, Predicate isAnHourOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> do
t <- minutesBefore 30 td
Just $ Token Time t
(_:Token Time td:_) -> Token Time <$> minutesBefore 30 td
_ -> Nothing
}
@ -838,9 +833,8 @@ ruleAfterWork = Rule
[ regex "nach (der)? arbeit|(am)? feier ?abend"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 17) (hour False 21)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleLastNCycle :: Rule
@ -1146,8 +1140,7 @@ ruleThisPartofday = Rule
, Predicate isAPartOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Token Time . partOfDay <$>
intersect (cycleNth TG.Day 0) td
(_:Token Time td:_) -> Token Time . partOfDay <$> intersect today td
_ -> Nothing
}
@ -1210,9 +1203,8 @@ ruleAfterLunch = Rule
[ regex "nach dem mittagessen|nachmittags?"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 13) (hour False 17)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleOnANamedday :: Rule
@ -1298,9 +1290,7 @@ ruleHalfIntegerGermanStyleHourofday = Rule
, Predicate isAnHourOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> do
t <- minutesBefore 30 td
Just $ Token Time t
(_:Token Time td:_) -> Token Time <$> minutesBefore 30 td
_ -> Nothing
}
@ -1368,9 +1358,8 @@ ruleTonight = Rule
[ regex "heute? (am)? abends?"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 18) (hour False 0)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleYear :: Rule

View File

@ -525,7 +525,7 @@ ruleInDurationFromTime = Rule
]
, prod = \tokens -> case tokens of
(_:Token Duration dd:_:Token Time td1:_) ->
Just . Token Time $ durationAfter dd td1
tt $ durationAfter dd td1
_ -> Nothing
}
@ -785,9 +785,8 @@ ruleAfterWork = Rule
[ regex "μετά τη δουλειά"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 17) (hour False 21)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleLastNCycle :: Rule
@ -1129,8 +1128,7 @@ ruleThisPartofday = Rule
, Predicate isAPartOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Token Time . partOfDay <$>
intersect (cycleNth TG.Day 0) td
(_:Token Time td:_) -> Token Time . partOfDay <$> intersect today td
_ -> Nothing
}
@ -1374,9 +1372,8 @@ ruleTonight = Rule
[ regex "απόψε"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 18) (hour False 0)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleTomorrowNight :: Rule

View File

@ -256,9 +256,8 @@ ruleLastNight = Rule
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) ->
let hours = if Text.toLower match == "late " then 3 else 6
start = durationBefore (DurationData hours TG.Hour) end
end = cycleNth TG.Day 0
in Token Time . partOfDay . notLatent <$> interval TTime.Open start end
start = durationBefore (DurationData hours TG.Hour) today
in Token Time . partOfDay . notLatent <$> interval TTime.Open start today
_ -> Nothing
}
@ -695,8 +694,7 @@ ruleNumeralToHOD = Rule
, prod = \tokens -> case tokens of
(token:_:Token Time td:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
@ -735,8 +733,7 @@ ruleNumeralAfterHOD = Rule
, prod = \tokens -> case tokens of
(token:_:Token Time td:_) -> do
n <- getIntValue token
t <- minutesAfter n td
Just $ Token Time t
Token Time <$> minutesAfter n td
_ -> Nothing
}
@ -896,7 +893,7 @@ rulePODThis = Rule
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Token Time . partOfDay . notLatent <$>
intersect (cycleNth TG.Day 0) td
intersect today td
_ -> Nothing
}
@ -906,8 +903,7 @@ ruleTonight = Rule
, pattern = [regex "(late )?toni(ght|gth|te)s?"]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
let today = cycleNth TG.Day 0
h = if Text.toLower match == "late " then 21 else 18
let h = if Text.toLower match == "late " then 21 else 18
evening <- interval TTime.Open (hour False h) (hour False 0)
Token Time . partOfDay . notLatent <$> intersect today evening
_ -> Nothing
@ -927,8 +923,7 @@ ruleAfterPartofday = Rule
"school" -> Just (hour False 15, hour False 21)
_ -> Nothing
td <- interval TTime.Open start end
Token Time . partOfDay . notLatent <$>
intersect (cycleNth TG.Day 0) td
Token Time . partOfDay . notLatent <$> intersect today td
_ -> Nothing
}
@ -973,10 +968,10 @@ ruleWeek = Rule
, pattern = [regex "(all|rest of the) week"]
, prod = \case
(Token RegexMatch (GroupMatch (match:_)):_) ->
let end = cycleNthAfter True TG.Day (-2) (cycleNth TG.Week 1)
let end = cycleNthAfter True TG.Day (-2) $ cycleNth TG.Week 1
period = case Text.toLower match of
"all" -> interval Closed (cycleNth TG.Week 0) end
"rest of the" -> interval Open (cycleNth TG.Day 0) end
"rest of the" -> interval Open today end
_ -> Nothing
in Token Time <$> period
_ -> Nothing

View File

@ -157,7 +157,7 @@ ruleNow = Rule
, pattern =
[ regex "(hoy)|(en este momento)"
]
, prod = \_ -> tt $ cycleNth TG.Day 0
, prod = \_ -> tt today
}
ruleUltimoDayofweekDeTime :: Rule
@ -342,8 +342,7 @@ ruleHourofdayMinusIntegerAsRelativeMinutes = Rule
, prod = \tokens -> case tokens of
(Token Time td:_:token:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
@ -359,8 +358,7 @@ ruleHourofdayMinusIntegerAsRelativeMinutes2 = Rule
, prod = \tokens -> case tokens of
(Token Time td:_:token:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
@ -372,9 +370,7 @@ ruleHourofdayMinusQuarter = Rule
, regex "menos\\s? cuarto"
]
, prod = \tokens -> case tokens of
(Token Time td:_) -> do
t <- minutesBefore 15 td
Just $ Token Time t
(Token Time td:_) -> Token Time <$> minutesBefore 15 td
_ -> Nothing
}
@ -386,9 +382,7 @@ ruleHourofdayMinusHalf = Rule
, regex "menos\\s? media"
]
, prod = \tokens -> case tokens of
(Token Time td:_) -> do
t <- minutesBefore 30 td
Just $ Token Time t
(Token Time td:_) -> Token Time <$> minutesBefore 30 td
_ -> Nothing
}
@ -400,9 +394,7 @@ ruleHourofdayMinusThreeQuarter = Rule
, regex "menos\\s? (3|tres) cuartos?"
]
, prod = \tokens -> case tokens of
(Token Time td:_) -> do
t <- minutesBefore 45 td
Just $ Token Time t
(Token Time td:_) -> Token Time <$> minutesBefore 45 td
_ -> Nothing
}
@ -962,8 +954,7 @@ ruleThisPartofday = Rule
, Predicate isAPartOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Token Time . partOfDay <$>
intersect (cycleNth TG.Day 0) td
(_:Token Time td:_) -> Token Time . partOfDay <$> intersect today td
_ -> Nothing
}

View File

@ -34,7 +34,7 @@ ruleAujourdhui = Rule
, pattern =
[ regex "(aujourd'? ?hui)|(ce jour)|(dans la journ(é|e)e?)|(en ce moment)"
]
, prod = \_ -> tt $ cycleNth TG.Day 0
, prod = \_ -> tt today
}
ruleDayofmonthNamedmonth :: Rule
@ -220,7 +220,7 @@ ruleCePartofday = Rule
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Token Time . partOfDay . notLatent <$>
intersect (cycleNth TG.Day 0) td
intersect today td
_ -> Nothing
}
@ -765,8 +765,7 @@ ruleHourofdayMoinsIntegerAsRelativeMinutes = Rule
, prod = \tokens -> case tokens of
(Token Time td:_:token:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
@ -778,9 +777,7 @@ ruleHourofdayMoinsQuart = Rule
, regex "moins( le)? quart"
]
, prod = \tokens -> case tokens of
(Token Time td:_) -> do
t <- minutesBefore 15 td
Just $ Token Time t
(Token Time td:_) -> Token Time <$> minutesBefore 15 td
_ -> Nothing
}
@ -1123,9 +1120,8 @@ ruleAprsLeDjeuner = Rule
[ regex "apr(e|è)s (le )?d(e|é|è)jeuner"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 13) (hour False 17)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleIntersect :: Rule
@ -1209,9 +1205,8 @@ ruleAprsLeTravail = Rule
[ regex "apr(e|è)s (le )?travail"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 17) (hour False 21)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleLeDayofmonthDatetime :: Rule
@ -1288,9 +1283,8 @@ ruleAvantLeDjeuner = Rule
[ regex "avant (le )?d(e|é|è)jeuner"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 10) (hour False 12)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleDernierWeekendDeTime :: Rule

View File

@ -48,7 +48,7 @@ ruleInniu = Rule
, pattern =
[ regex "inniu"
]
, prod = \_ -> tt $ cycleNth TG.Day 0
, prod = \_ -> tt today
}
ruleAnOrdinalCycleINdiaidhTime :: Rule

View File

@ -168,8 +168,7 @@ ruleIntegerTotillbeforeIntegerHourofday = Rule
, prod = \tokens -> case tokens of
(token:_:Token Time td:_) -> do
n <- getIntValue token
t <- minutesBefore n td
tt t
Token Time <$> minutesBefore n td
_ -> Nothing
}
@ -210,8 +209,7 @@ ruleIntegerAfterpastIntegerHourofday = Rule
, prod = \tokens -> case tokens of
(token:_:Token Time td:_) -> do
n <- getIntValue token
t <- minutesAfter n td
tt t
Token Time <$> minutesAfter n td
_ -> Nothing
}
@ -468,7 +466,7 @@ ruleToday = Rule
, pattern =
[ regex "היום"
]
, prod = \_ -> tt $ cycleNth TG.Day 0
, prod = \_ -> tt today
}
ruleBetweenTimeofdayAndTimeofdayInterval :: Rule
@ -678,7 +676,7 @@ ruleThisEvening = Rule
]
, prod = \_ -> do
td <- interval TTime.Open (hour False 18) (hour False 0)
Token Time . partOfDay <$> intersect (cycleNth TG.Day 0) td
Token Time . partOfDay <$> intersect today td
}
ruleBetweenDatetimeAndDatetimeInterval :: Rule

View File

@ -82,8 +82,7 @@ ruleNumeralTotillbeforeIntegerHourofday = Rule
, prod = \tokens -> case tokens of
(token:_:Token Time td:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
@ -122,8 +121,7 @@ ruleNumeralAfterpastHourofday = Rule
, prod = \tokens -> case tokens of
(token:_:Token Time td:_) -> do
n <- getIntValue token
t <- minutesAfter n td
Just $ Token Time t
Token Time <$> minutesAfter n td
_ -> Nothing
}
@ -245,7 +243,7 @@ ruleValentinesDay = Rule
, pattern =
[ regex "valentinov(og?|a|)"
]
, prod = \_ -> Just . Token Time $ monthDay 2 14
, prod = \_ -> tt $ monthDay 2 14
}
ruleSinceTimeofday :: Rule
@ -266,7 +264,7 @@ ruleNewYearsDay = Rule
, pattern =
[ regex "nov(a|u|e) godin(a|e|u)"
]
, prod = \_ -> Just . Token Time $ monthDay 1 1
, prod = \_ -> tt $ monthDay 1 1
}
ruleLastTime :: Rule
@ -278,7 +276,7 @@ ruleLastTime = Rule
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) ->
Just . Token Time $ predNth (-1) False td
tt $ predNth (-1) False td
_ -> Nothing
}
@ -306,7 +304,7 @@ ruleCycleAfterTime = Rule
]
, prod = \tokens -> case tokens of
(Token TimeGrain grain:_:Token Time td:_) ->
Just . Token Time $ cycleNthAfter False grain 1 td
tt $ cycleNthAfter False grain 1 td
_ -> Nothing
}
@ -318,7 +316,7 @@ ruleInDuration = Rule
, dimension Duration
]
, prod = \tokens -> case tokens of
(_:Token Duration dd:_) -> Just . Token Time $ inDuration dd
(_:Token Duration dd:_) -> tt $ inDuration dd
_ -> Nothing
}
@ -342,7 +340,7 @@ ruleLastCycleOfTime = Rule
]
, prod = \tokens -> case tokens of
(_:Token TimeGrain grain:_:Token Time td:_) ->
Just . Token Time $ cycleLastOf grain td
tt $ cycleLastOf grain td
_ -> Nothing
}
@ -415,7 +413,7 @@ ruleTimeAfterNext = Rule
, regex "nakon sljede(ć|c)(i|e|a)(ga?)?"
]
, prod = \tokens -> case tokens of
(Token Time td:_) -> Just . Token Time $ predNth 1 True td
(Token Time td:_) -> tt $ predNth 1 True td
_ -> Nothing
}
@ -425,7 +423,7 @@ ruleNoon = Rule
, pattern =
[ regex "(u )?podne(va)?"
]
, prod = \_ -> Just . Token Time $ hour False 12
, prod = \_ -> tt $ hour False 12
}
ruleEarlyMorning :: Rule
@ -444,7 +442,7 @@ ruleToday = Rule
, pattern =
[ regex "danas?|(dana(s|š)nj(i|eg) dana?) "
]
, prod = \_ -> Just . Token Time $ cycleNth TG.Day 0
, prod = \_ -> tt today
}
ruleThisnextDayofweek :: Rule
@ -455,7 +453,7 @@ ruleThisnextDayofweek = Rule
, Predicate isADayOfWeek
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Just . Token Time $ predNth 0 True td
(_:Token Time td:_) -> tt $ predNth 0 True td
_ -> Nothing
}
@ -482,7 +480,7 @@ ruleNextCycle = Rule
, dimension TimeGrain
]
, prod = \tokens -> case tokens of
(_:Token TimeGrain grain:_) -> Just . Token Time $ cycleNth grain 1
(_:Token TimeGrain grain:_) -> tt $ cycleNth grain 1
_ -> Nothing
}
@ -506,7 +504,7 @@ ruleForDuration = Rule
, dimension Duration
]
, prod = \tokens -> case tokens of
(_:Token Duration dd:_) -> Just . Token Time $ inDuration dd
(_:Token Duration dd:_) -> tt $ inDuration dd
_ -> Nothing
}
@ -521,7 +519,7 @@ ruleLastDayofweekTime = Rule
]
, prod = \tokens -> case tokens of
(_:Token Time td1:_:Token Time td2:_) ->
Just . Token Time $ predLastOf td1 td2
tt $ predLastOf td1 td2
_ -> Nothing
}
@ -533,7 +531,7 @@ ruleDurationFromNow = Rule
, regex "od (sada?|ovog trenutka|dana(s|š)nj(i|eg) dana?)"
]
, prod = \tokens -> case tokens of
(Token Duration dd:_) -> Just . Token Time $ inDuration dd
(Token Duration dd:_) -> tt $ inDuration dd
_ -> Nothing
}
@ -555,7 +553,7 @@ ruleLastCycle = Rule
, dimension TimeGrain
]
, prod = \tokens -> case tokens of
(_:Token TimeGrain grain:_) -> Just . Token Time . cycleNth grain $ - 1
(_:Token TimeGrain grain:_) -> tt . cycleNth grain $ - 1
_ -> Nothing
}
@ -592,7 +590,7 @@ ruleTimeBeforeLast = Rule
]
, prod = \tokens -> case tokens of
(Token Time td:_) ->
Just . Token Time $ predNth (-2) False td
tt $ predNth (-2) False td
_ -> Nothing
}
@ -624,7 +622,7 @@ ruleChristmasEve = Rule
, pattern =
[ regex "badnjaka?"
]
, prod = \_ -> Just . Token Time $ monthDay 12 24
, prod = \_ -> tt $ monthDay 12 24
}
ruleInduringThePartofday :: Rule
@ -635,7 +633,7 @@ ruleInduringThePartofday = Rule
, Predicate isAPartOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Just . Token Time $ notLatent td
(_:Token Time td:_) -> tt $ notLatent td
_ -> Nothing
}
@ -797,7 +795,7 @@ ruleNewYearsEve = Rule
, pattern =
[ regex "star(a|u|e) godin(a|e|u)"
]
, prod = \_ -> Just . Token Time $ monthDay 12 31
, prod = \_ -> tt $ monthDay 12 31
}
ruleByTheEndOfTime :: Rule
@ -820,8 +818,7 @@ ruleAfterWork = Rule
]
, prod = \_ -> do
td <- interval TTime.Open (hour False 17) (hour False 21)
Token Time . partOfDay . notLatent <$>
intersect (cycleNth TG.Day 0) td
Token Time . partOfDay . notLatent <$> intersect today td
}
ruleLastDayofweekTime2 :: Rule
@ -834,7 +831,7 @@ ruleLastDayofweekTime2 = Rule
]
, prod = \tokens -> case tokens of
(_:Token Time td1:Token Time td2:_) ->
Just . Token Time $ predLastOf td1 td2
tt $ predLastOf td1 td2
_ -> Nothing
}
@ -872,7 +869,7 @@ ruleMidnighteodendOfDay = Rule
, pattern =
[ regex "(u )?pono(c|ć)i?|(the )?(EOD|((do )? kraja? dana))"
]
, prod = \_ -> Just . Token Time $ hour False 0
, prod = \_ -> tt $ hour False 0
}
ruleDayofmonthNonOrdinalNamedmonth :: Rule
@ -919,7 +916,7 @@ ruleUntilTimeofday = Rule
, Predicate isATimeOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Just . Token Time $ withDirection TTime.Before td
(_:Token Time td:_) -> tt $ withDirection TTime.Before td
_ -> Nothing
}
@ -931,7 +928,7 @@ ruleAtTimeofday = Rule
, Predicate isATimeOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Just . Token Time $ notLatent td
(_:Token Time td:_) -> tt $ notLatent td
_ -> Nothing
}
@ -979,7 +976,7 @@ rulePrijeDuration = Rule
, dimension Duration
]
, prod = \tokens -> case tokens of
(_:Token Duration dd:_) -> Just . Token Time $ durationAgo dd
(_:Token Duration dd:_) -> tt $ durationAgo dd
_ -> Nothing
}
@ -991,7 +988,7 @@ ruleAboutDuration = Rule
, dimension Duration
]
, prod = \tokens -> case tokens of
(_:Token Duration dd:_) -> Just . Token Time $ inDuration dd
(_:Token Duration dd:_) -> tt $ inDuration dd
_ -> Nothing
}
@ -1001,7 +998,7 @@ ruleEomendOfMonth = Rule
, pattern =
[ regex "(the )?(EOM|(do )? kraja mjeseca)"
]
, prod = \_ -> Just . Token Time $ cycleNth TG.Month 1
, prod = \_ -> tt $ cycleNth TG.Month 1
}
ruleNameddayDayofmonthOrdinal :: Rule
@ -1024,7 +1021,7 @@ ruleNextTime = Rule
, Predicate isNotLatent
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Just . Token Time $ predNth 0 True td
(_:Token Time td:_) -> tt $ predNth 0 True td
_ -> Nothing
}
@ -1092,7 +1089,7 @@ ruleThisPartofday = Rule
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Token Time . partOfDay . notLatent <$>
intersect (cycleNth TG.Day 0) td
intersect today td
_ -> Nothing
}
@ -1104,7 +1101,7 @@ ruleThisCycle = Rule
, dimension TimeGrain
]
, prod = \tokens -> case tokens of
(_:Token TimeGrain grain:_) -> Just . Token Time $ cycleNth grain 0
(_:Token TimeGrain grain:_) -> tt $ cycleNth grain 0
_ -> Nothing
}
@ -1128,7 +1125,7 @@ ruleThisTime = Rule
, dimension Time
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Just . Token Time $ predNth 0 False td
(_:Token Time td:_) -> tt $ predNth 0 False td
_ -> Nothing
}
@ -1165,7 +1162,7 @@ ruleDayBeforeYesterday = Rule
, pattern =
[ regex "(prekju(c|č)er)"
]
, prod = \_ -> Just . Token Time . cycleNth TG.Day $ - 2
, prod = \_ -> tt . cycleNth TG.Day $ - 2
}
ruleAfterLunch :: Rule
@ -1176,8 +1173,7 @@ ruleAfterLunch = Rule
]
, prod = \_ -> do
td <- interval TTime.Open (hour False 13) (hour False 17)
Token Time . partOfDay . notLatent <$>
intersect (cycleNth TG.Day 0) td
Token Time . partOfDay . notLatent <$> intersect today td
}
ruleYearLatent :: Rule
@ -1200,7 +1196,7 @@ ruleYesterday = Rule
, pattern =
[ regex "(ju(c|č)er)"
]
, prod = \_ -> Just . Token Time . cycleNth TG.Day $ - 1
, prod = \_ -> tt . cycleNth TG.Day $ - 1
}
ruleSeason2 :: Rule
@ -1221,7 +1217,7 @@ ruleAfterTimeofday = Rule
, dimension Time
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Just . Token Time $ withDirection TTime.After td
(_:Token Time td:_) -> tt $ withDirection TTime.After td
_ -> Nothing
}
@ -1231,7 +1227,7 @@ ruleChristmas = Rule
, pattern =
[ regex "(zi(c|ć)bo|bo(z|ž)i(c|ć))(a|u|ni|na)?"
]
, prod = \_ -> Just . Token Time $ monthDay 12 25
, prod = \_ -> tt $ monthDay 12 25
}
ruleDayofmonthOrdinal :: Rule
@ -1259,7 +1255,7 @@ ruleOrdinalCycleAfterTime = Rule
]
, prod = \tokens -> case tokens of
(Token Ordinal od:Token TimeGrain grain:_:Token Time td:_) ->
Just . Token Time $ cycleNthAfter True grain (TOrdinal.value od - 1) td
tt $ cycleNthAfter True grain (TOrdinal.value od - 1) td
_ -> Nothing
}
@ -1274,7 +1270,7 @@ ruleOrdinalCycleOfTime = Rule
]
, prod = \tokens -> case tokens of
(Token Ordinal od:Token TimeGrain grain:_:Token Time td:_) ->
Just . Token Time $ cycleNthAfter True grain (TOrdinal.value od - 1) td
tt $ cycleNthAfter True grain (TOrdinal.value od - 1) td
_ -> Nothing
}
@ -1286,7 +1282,7 @@ ruleAfterNextTime = Rule
, dimension Time
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Just . Token Time $ predNth 1 True td
(_:Token Time td:_) -> tt $ predNth 1 True td
_ -> Nothing
}
@ -1296,7 +1292,7 @@ ruleDayAfterTomorrow = Rule
, pattern =
[ regex "(preko?sutra)"
]
, prod = \_ -> Just . Token Time $ cycleNth TG.Day 2
, prod = \_ -> tt $ cycleNth TG.Day 2
}
ruleHhmm :: Rule
@ -1320,7 +1316,6 @@ ruleTonight = Rule
[ regex "(na)?ve(c|č)er(as)?"
]
, prod = \_ -> do
let today = cycleNth TG.Day 0
evening <- interval TTime.Open (hour False 18) (hour False 0)
Token Time . partOfDay . notLatent <$> intersect today evening
}
@ -1333,7 +1328,7 @@ ruleBeforeLasttime = Rule
, dimension Time
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Just . Token Time $ predNth (-2) False td
(_:Token Time td:_) -> tt $ predNth (-2) False td
_ -> Nothing
}
@ -1370,7 +1365,7 @@ ruleHalloweenDay = Rule
, pattern =
[ regex "no(c|ć) vje(s|š)tica"
]
, prod = \_ -> Just . Token Time $ monthDay 10 31
, prod = \_ -> tt $ monthDay 10 31
}
ruleNamedmonthDayofmonthNonOrdinal :: Rule
@ -1428,7 +1423,7 @@ ruleCycleBeforeTime = Rule
]
, prod = \tokens -> case tokens of
(Token TimeGrain grain:_:Token Time td:_) ->
Just . Token Time $ cycleNthAfter False grain (-1) td
tt $ cycleNthAfter False grain (-1) td
_ -> Nothing
}
@ -1471,7 +1466,7 @@ ruleDurationAfterTime = Rule
]
, prod = \tokens -> case tokens of
(Token Duration dd:_:Token Time td:_) ->
Just . Token Time $ durationAfter dd td
tt $ durationAfter dd td
_ -> Nothing
}
@ -1506,7 +1501,7 @@ ruleDayBeforeDayBeforeYesterday = Rule
, pattern =
[ regex "(prek\\s?prekju(c|č)er)"
]
, prod = \_ -> Just . Token Time . cycleNth TG.Day $ - 3
, prod = \_ -> tt . cycleNth TG.Day $ - 3
}
ruleDurationBeforeTime :: Rule
@ -1519,7 +1514,7 @@ ruleDurationBeforeTime = Rule
]
, prod = \tokens -> case tokens of
(Token Duration dd:_:Token Time td:_) ->
Just . Token Time $ durationBefore dd td
tt $ durationBefore dd td
_ -> Nothing
}
@ -1529,7 +1524,7 @@ ruleEoyendOfYear = Rule
, pattern =
[ regex "(the )?(EOY|(do )? kraja? godine)"
]
, prod = \_ -> Just . Token Time $ cycleNth TG.Year 1
, prod = \_ -> tt $ cycleNth TG.Year 1
}
ruleTomorrow :: Rule
@ -1538,7 +1533,7 @@ ruleTomorrow = Rule
, pattern =
[ regex "(sutra(dan)?)"
]
, prod = \_ -> Just . Token Time $ cycleNth TG.Day 1
, prod = \_ -> tt $ cycleNth TG.Day 1
}
ruleMothersDay :: Rule
@ -1558,7 +1553,7 @@ ruleTimeofdayOclock = Rule
, regex "sat(i|a)?"
]
, prod = \tokens -> case tokens of
(Token Time td:_) -> Just . Token Time $ notLatent td
(Token Time td:_) -> tt $ notLatent td
_ -> Nothing
}

View File

@ -15,7 +15,7 @@ module Duckling.Time.Helpers
hasNoDirection, isADayOfWeek, isAMonth, isAnHourOfDay, isAPartOfDay
, isATimeOfDay, isDOMInteger, isDOMOrdinal, isDOMValue, isGrain
, isGrainFinerThan, isGrainOfTime, isIntegerBetween, isNotLatent
, isOrdinalBetween, isMidnightOrNoon, isOkWithThisNext, sameGrain
, isOrdinalBetween, isMidnightOrNoon, isOkWithThisNext, sameGrain, today
-- Production
, cycleLastOf, cycleN, cycleNth, cycleNthAfter, dayOfMonth, dayOfWeek
, durationAfter, durationAgo, durationBefore, mkOkForThisNext, form, hour
@ -392,6 +392,9 @@ now = td {TTime.timeGrain = TG.NoGrain}
where
td = cycleNth TG.Second 0
today :: TimeData
today = cycleNth TG.Day 0
hour :: Bool -> Int -> TimeData
hour is12H n = timeOfDay (Just n) is12H $ TTime.timedata'
{TTime.timePred = timeHour is12H n, TTime.timeGrain = TG.Hour}

View File

@ -161,9 +161,8 @@ ruleStamattina = Rule
[ regex "stamattina"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 4) (hour False 12)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleYearNotLatent :: Rule
@ -471,7 +470,7 @@ ruleToday = Rule
, pattern =
[ regex "(di )?oggi|in giornata"
]
, prod = \_ -> tt $ cycleNth TG.Day 0
, prod = \_ -> tt today
}
ruleLastCycleOfTime :: Rule
@ -551,8 +550,7 @@ ruleRelativeMinutesToIntegerAsHourofday = Rule
, prod = \tokens -> case tokens of
(token:_:Token Time td:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
ruleHourofdayMinusIntegerAsRelativeMinutes :: Rule
@ -566,8 +564,7 @@ ruleHourofdayMinusIntegerAsRelativeMinutes = Rule
, prod = \tokens -> case tokens of
(Token Time td:_:token:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
ruleHhRelativeminutesDelPomeriggiotimeofday :: Rule
@ -653,8 +650,7 @@ ruleMinutesToIntegerAsHourofday = Rule
, prod = \tokens -> case tokens of
(token:_:Token Time td:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
ruleHourofdayMinusIntegerMinutes :: Rule
@ -1306,9 +1302,8 @@ ruleStasera = Rule
[ regex "stasera"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 18) (hour False 0)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleSeason3 :: Rule
@ -1822,8 +1817,7 @@ ruleThisPartofday = Rule
, Predicate isAPartOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) ->
Token Time . partOfDay <$> intersect (cycleNth TG.Day 0) td
(_:Token Time td:_) -> Token Time . partOfDay <$> intersect today td
_ -> Nothing
}

View File

@ -245,7 +245,7 @@ ruleToday = Rule
, pattern =
[ regex "오늘|당일|금일"
]
, prod = \_ -> tt $ cycleNth TG.Day 0
, prod = \_ -> tt today
}
ruleIntegerHourofdayRelativeMinutes :: Rule
@ -259,8 +259,7 @@ ruleIntegerHourofdayRelativeMinutes = Rule
, prod = \tokens -> case tokens of
(Token Time td:token:_) -> do
v <- getIntValue token
t <- minutesBefore v td
Just $ Token Time t
Token Time <$> minutesBefore v td
_ -> Nothing
}
@ -990,8 +989,7 @@ ruleAfterPartofday = Rule
, regex "지나서|후에"
]
, prod = \tokens -> case tokens of
(Token Time td:_) ->
Token Time . partOfDay <$> intersect (cycleNth TG.Day 0) td
(Token Time td:_) -> Token Time . partOfDay <$> intersect today td
_ -> Nothing
}

View File

@ -48,8 +48,7 @@ ruleRelativeMinutesTotillbeforeIntegerHourofday = Rule
, prod = \tokens -> case tokens of
(token:_:Token Time td:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
@ -451,7 +450,7 @@ ruleToday = Rule
, pattern =
[ regex "i dag|idag"
]
, prod = \_ -> tt $ cycleNth TG.Day 0
, prod = \_ -> tt today
}
ruleThisnextDayofweek :: Rule
@ -872,9 +871,8 @@ ruleAfterWork = Rule
[ regex "etter jobb"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 17) (hour False 21)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleLastNCycle :: Rule
@ -1191,8 +1189,7 @@ ruleThisPartofday = Rule
, Predicate isAPartOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Token Time . partOfDay <$>
intersect (cycleNth TG.Day 0) td
(_:Token Time td:_) -> Token Time . partOfDay <$> intersect today td
_ -> Nothing
}
@ -1242,9 +1239,8 @@ ruleAfterLunch = Rule
[ regex "etter (frokost|middag|lunsj|lunch)"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 13) (hour False 17)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleOnANamedday :: Rule
@ -1392,9 +1388,8 @@ ruleTonight = Rule
[ regex "i kveld"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 18) (hour False 0)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleYear :: Rule

View File

@ -221,7 +221,7 @@ ruleEvenings = Rule
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
td1 <- case Text.toLower match of
"van" -> Just $ cycleNth TG.Day 0
"van" -> Just today
"morgen" -> Just $ cycleNth TG.Day 1
_ -> Just $ cycleNth TG.Day $ - 1
td2 <- interval TTime.Open (hour False 18) (hour False 0)
@ -502,7 +502,7 @@ ruleAfternoons = Rule
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
td1 <- case Text.toLower match of
"vanmiddag" -> Just $ cycleNth TG.Day 0
"vanmiddag" -> Just today
"morgenmiddag" -> Just $ cycleNth TG.Day 1
"morgenmiddags" -> Just $ cycleNth TG.Day 1
_ -> Just . cycleNth TG.Day $ - 1
@ -713,9 +713,8 @@ ruleAfterWork = Rule
[ regex "na het werk"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 17) (hour False 21)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleLastNCycle :: Rule
@ -1021,7 +1020,7 @@ ruleMornings = Rule
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
td1 <- case Text.toLower match of
"vanmorgen" -> Just $ cycleNth TG.Day 0
"vanmorgen" -> Just today
"morgenochtend" -> Just $ cycleNth TG.Day 1
_ -> Just . cycleNth TG.Day $ - 1
td2 <- interval TTime.Open (hour False 0) (hour False 12)
@ -1037,8 +1036,7 @@ ruleThisPartofday = Rule
, Predicate isAPartOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) -> Token Time . partOfDay <$>
intersect (cycleNth TG.Day 0) td
(_:Token Time td:_) -> Token Time . partOfDay <$> intersect today td
_ -> Nothing
}
@ -1086,9 +1084,8 @@ ruleAfterLunch = Rule
[ regex "na de lunch|na het middageten"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 13) (hour False 17)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleOnANamedday :: Rule

View File

@ -79,8 +79,7 @@ ruleRelativeMinutesTotillbeforeIntegerHourofday = Rule
, prod = \tokens -> case tokens of
(token:_:Token Time td:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
@ -400,7 +399,7 @@ ruleToday = Rule
, pattern =
[ regex "dzisiejszy|dzisiaj|dziś|dzis|w ten dzień|w ten dzien|w obecny dzień|w obecny dzien|obecnego dnia"
]
, prod = \_ -> tt $ cycleNth TG.Day 0
, prod = \_ -> tt today
}
ruleThisnextDayofweek :: Rule
@ -1107,8 +1106,7 @@ ruleThisPartofday = Rule
, Predicate isAPartOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) ->
Token Time . partOfDay <$> intersect (cycleNth TG.Day 0) td
(_:Token Time td:_) -> Token Time . partOfDay <$> intersect today td
_ -> Nothing
}

View File

@ -151,7 +151,7 @@ ruleNow = Rule
, pattern =
[ regex "(hoje)|(neste|nesse) momento"
]
, prod = \_ -> tt $ cycleNth TG.Day 0
, prod = \_ -> tt today
}
ruleDimTimeDaMadrugada :: Rule
@ -366,8 +366,7 @@ ruleIntegerParaAsHourofdayAsRelativeMinutes = Rule
, prod = \tokens -> case tokens of
(token:_:Token Time td:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
@ -417,8 +416,7 @@ ruleIntegerParaAsHourofdayAsRelativeMinutes2 = Rule
, prod = \tokens -> case tokens of
(token:_:_:Token Time td:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
@ -560,8 +558,7 @@ rulePartofdayDessaSemana = Rule
, regex "(d?es[ts]a semana)|agora"
]
, prod = \tokens -> case tokens of
(Token Time td:_) ->
Token Time . partOfDay <$> intersect (cycleNth TG.Day 0) td
(Token Time td:_) -> Token Time . partOfDay <$> intersect today td
_ -> Nothing
}
@ -1080,8 +1077,7 @@ ruleThisPartofday = Rule
, Predicate isAPartOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) ->
Token Time . partOfDay <$> intersect (cycleNth TG.Day 0) td
(_:Token Time td:_) -> Token Time . partOfDay <$> intersect today td
_ -> Nothing
}

View File

@ -204,7 +204,7 @@ ruleAzi = Rule
, pattern =
[ regex "a(st(a|ă))?zi"
]
, prod = \_ -> tt $ cycleNth TG.Day 0
, prod = \_ -> tt today
}
ruleNoon :: Rule
@ -408,9 +408,8 @@ ruleDiseara = Rule
[ regex "disear(a|ă)|((i|î)n aceas(a|ă) )?sear(a|ă)"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 18) (hour False 0)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleIntersectBy :: Rule
@ -740,7 +739,7 @@ rulePartofdayAsta = Rule
]
, prod = \tokens -> case tokens of
(Token Time td:_) ->
Token Time . partOfDay <$> intersect (cycleNth TG.Day 0) td
Token Time . partOfDay <$> intersect today td
_ -> Nothing
}

View File

@ -75,8 +75,7 @@ ruleRelativeMinutesTotillbeforeIntegerHourofday = Rule
, prod = \tokens -> case tokens of
(token:_:Token Time td:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
@ -470,7 +469,7 @@ ruleToday = Rule
, pattern =
[ regex "i dag|idag"
]
, prod = \_ -> tt $ cycleNth TG.Day 0
, prod = \_ -> tt today
}
ruleThisnextDayofweek :: Rule
@ -879,9 +878,8 @@ ruleAfterWork = Rule
[ regex "efter jobbet"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 17) (hour False 21)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleLastNCycle :: Rule
@ -1195,8 +1193,7 @@ ruleThisPartofday = Rule
, Predicate isAPartOfDay
]
, prod = \tokens -> case tokens of
(_:Token Time td:_) ->
Token Time . partOfDay <$> intersect (cycleNth TG.Day 0) td
(_:Token Time td:_) -> Token Time . partOfDay <$> intersect today td
_ -> Nothing
}
@ -1246,9 +1243,8 @@ ruleAfterLunch = Rule
[ regex "efter (lunch)"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 13) (hour False 17)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleOnANamedday :: Rule
@ -1395,9 +1391,8 @@ ruleTonight = Rule
[ regex "ikväll"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 18) (hour False 0)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleYear :: Rule

View File

@ -162,8 +162,7 @@ rulePartofdayHmNay = Rule
, regex "(h(ô)m )?nay"
]
, prod = \tokens -> case tokens of
(Token Time td:_) ->
Token Time . partOfDay <$> intersect (cycleNth TG.Day 0) td
(Token Time td:_) -> Token Time . partOfDay <$> intersect today td
_ -> Nothing
}
@ -330,7 +329,7 @@ ruleHmNay = Rule
, pattern =
[ regex "((ngay )?h(ô)m|b(ữ)a) nay"
]
, prod = \_ -> tt $ cycleNth TG.Day 0
, prod = \_ -> tt today
}
ruleAtHhmm :: Rule
@ -521,8 +520,7 @@ ruleAfterWork = Rule
]
, prod = \_ -> do
td <- interval TTime.Open (hour False 17) (hour False 21)
Token Time . partOfDay . notLatent <$>
intersect (cycleNth TG.Day 0) td
Token Time . partOfDay . notLatent <$> intersect today td
}
ruleLastNCycle :: Rule
@ -733,8 +731,7 @@ ruleAfterLunch = Rule
]
, prod = \_ -> do
td <- interval TTime.Open (hour False 13) (hour False 17)
Token Time . partOfDay . notLatent <$>
intersect (cycleNth TG.Day 0) td
Token Time . partOfDay . notLatent <$> intersect today td
}
ruleSeason2 :: Rule
@ -831,7 +828,6 @@ ruleTonight = Rule
[ regex "(t(ố)i|(đ)(ê)m)( h(ô)m)? nay"
]
, prod = \_ -> do
let today = cycleNth TG.Day 0
evening <- interval TTime.Open (hour False 18) (hour False 0)
Token Time . partOfDay . notLatent <$> intersect today evening
}

View File

@ -48,8 +48,7 @@ ruleRelativeMinutesTotillbeforeIntegerHourofday = Rule
, prod = \tokens -> case tokens of
(Token Time td:_:token:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
@ -64,8 +63,7 @@ ruleRelativeMinutesTotillbeforeNoonmidnight = Rule
, prod = \tokens -> case tokens of
(Token Time td:_:token:_) -> do
n <- getIntValue token
t <- minutesBefore n td
Just $ Token Time t
Token Time <$> minutesBefore n td
_ -> Nothing
}
@ -326,7 +324,7 @@ ruleToday = Rule
, pattern =
[ regex "今天|今日"
]
, prod = \_ -> tt $ cycleNth TG.Day 0
, prod = \_ -> tt today
}
ruleNextDayofweek :: Rule
@ -782,9 +780,8 @@ ruleTonight = Rule
[ regex "今晚|今天晚上"
]
, prod = \_ -> do
let td1 = cycleNth TG.Day 0
td2 <- interval TTime.Open (hour False 18) (hour False 0)
Token Time . partOfDay <$> intersect td1 td2
Token Time . partOfDay <$> intersect today td2
}
ruleTomorrowNight :: Rule