From e472572150c467b862fd0a0630297a5a879c354a Mon Sep 17 00:00:00 2001 From: Ninglin Du Date: Mon, 4 Mar 2024 15:06:19 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E7=89=B9=E6=AE=8A=E8=AF=B4=E6=B3=95?= =?UTF-8?q?=E6=94=AF=E6=8C=81"=E6=98=8E=E5=90=8E=E5=A4=A7=E5=90=8E"=20(#21?= =?UTF-8?q?6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 支持"工作日的上午" --- .../duckling/dimension/time/date/Rules.scala | 8 ++++ .../dimension/time/repeat/Rules.scala | 44 ++++++++++++------- .../time/repeat/RepeatValueTest.scala | 1 + .../dimension/time/date/Examples.scala | 3 +- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/date/Rules.scala b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/date/Rules.scala index 89bf0e2d..dec0e0aa 100644 --- a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/date/Rules.scala +++ b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/date/Rules.scala @@ -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) diff --git a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/repeat/Rules.scala b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/repeat/Rules.scala index de6a63d1..12ce29be 100644 --- a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/repeat/Rules.scala +++ b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/repeat/Rules.scala @@ -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 = "