Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DUCK] 时间支持更多说法 #216

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ trait Rules extends DimRules {
for (td <- interval(Open, from, to, options.timeOptions.beforeEndOfInterval)) yield Token(Date, td)
})

val ruleSpecial5 = Rule(name = "date - special days: 明天后天大后天", pattern = List("(明后大后|明天后天大后天)(三天)?".regex),
prod = {
case (options, _) =>
val from = cycleNth(Day, 1, Day)
val to = cycleNth(Day, 3, Day)
for (td <- interval(Open, from, to, options.timeOptions.beforeEndOfInterval)) yield Token(Date, td)
})

val ruleEndOfMonth = Rule(name = "date - 月底", pattern = List("月(底|末)".regex), prod = tokens {
case _ =>
val td1 = TimeData(EndOfGrainPredicate, timeGrain = Day)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,37 @@ trait Rules extends DimRules with LazyLogging {
}
)

val ruleWorkDaysTime = Rule(
def workdaysTime(rd: RepeatData, td: TimeData) = {
// 工作日八点应该就是上午八点,不是晚上八点
val _form = td.form match {
case Some(form.TimeOfDay(h, true)) => Some(form.TimeOfDay(h, false))
case _ => td.form
}
val timePred = td.timePred match {
case tdp: TimeDatePredicate =>
val _hour = tdp.hour match {
case Some((true, h)) => Some((false, h))
case _ => tdp.hour
}
tdp.copy(hour = _hour)
case _ => td.timePred
}
Token(Repeat, RepeatData(workdayType = rd.workdayType, start = td.copy(timePred = timePred, form = _form)))
}

val ruleWorkDaysTime1 = Rule(
name = "<work/non-workday> <time>",
pattern = List(isOnlyWorkdaysType.predicate, isHourTimes.predicate),
prod = tokens { case Token(Repeat, rd: RepeatData) :: Token(Time, td: TimeData) :: _ =>
// 工作日八点应该就是上午八点,不是晚上八点
val _form = td.form match {
case Some(form.TimeOfDay(h, true)) => Some(form.TimeOfDay(h, false))
case _ => td.form
}
val timePred = td.timePred match {
case tdp: TimeDatePredicate =>
val _hour = tdp.hour match {
case Some((true, h)) => Some((false, h))
case _ => tdp.hour
}
tdp.copy(hour = _hour)
case _ => td.timePred
}
Token(Repeat, RepeatData(workdayType = rd.workdayType, start = td.copy(timePred = timePred, form = _form)))
workdaysTime(rd, td)
}
)

val ruleWorkDaysTime2 = Rule(
name = "<work/non-workday> 的 <time>",
pattern = List(isOnlyWorkdaysType.predicate, "的".regex, isHourTimes.predicate),
prod = tokens { case Token(Repeat, rd: RepeatData) :: _ :: Token(Time, td: TimeData) :: _ =>
workdaysTime(rd, td)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class RepeatValueTest extends UnitSpec {

val cases = Table(("query", "schema")
, ("每个工作日上午", "Repeat_Hour_08:00/12:00_Workday")
, ("每个工作日的上午", "Repeat_Hour_08:00/12:00_Workday")
, ("每个非工作日上午八点", "Repeat_Hour_08:00_NonWorkday")
, ("每月2号下午2点", "Repeat_Hour_2013-03-02T14:00_P1M")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ object Examples extends DimExamples {
(ymd(2013, 12, 10, calendar = Lunar(false)), List("农历十二月初十", "腊月初十")),
(ymd(2013, 12, 13, calendar = Lunar(false)), List("农历十二月十三", "腊月十三")),
(ymd(2013, 8, 8, calendar = Lunar(false)), List("农历八月初八", "农历2013年八月八日", "八月初八")),
(localDateTimeInterval(LocalDateTime.of(2013, 2, 12, 0, 0), LocalDateTime.of(2013, 2, 15, 0, 0), Grain.Day), List("今明后三天", "今天明天后天三天"))
(localDateTimeInterval(LocalDateTime.of(2013, 2, 12, 0, 0), LocalDateTime.of(2013, 2, 15, 0, 0), Grain.Day), List("今明后三天", "今天明天后天三天")),
(localDateTimeInterval(LocalDateTime.of(2013, 2, 13, 0, 0), LocalDateTime.of(2013, 2, 16, 0, 0), Grain.Day), List("明后大后三天", "明天后天大后天三天"))
)

override val dimension: Dimension = Date
Expand Down
Loading