From 34398010894ad0aac9a7eaa5415a423fc8c017fb Mon Sep 17 00:00:00 2001 From: zhangsonglei Date: Tue, 30 Jan 2024 19:48:08 +0800 Subject: [PATCH] =?UTF-8?q?imp:=20=E6=9C=80=E8=BF=91=E4=B8=80=E5=91=A8?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E8=8C=83=E5=9B=B4=E7=94=B1=E6=9C=AC=E5=91=A8?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=9C=80=E8=BF=917=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xiaomi/duckling/dimension/time/Rules.scala | 2 ++ .../src/test/scala/com/xiaomi/duckling/ApiTest.scala | 2 +- .../com/xiaomi/duckling/dimension/time/Examples.scala | 10 +++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/Rules.scala b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/Rules.scala index 3b6c6f31..8cdda10c 100644 --- a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/Rules.scala +++ b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/Rules.scala @@ -255,6 +255,8 @@ trait Rules extends DimRules { case Week => (reset(Week) _ >>> tt)(td) case _ => tt(td) } + } else if (s != "这" && g == Week) { // 最?近一周,改为最近7天。 + cycleN(notImmediate = false, Day, 7 * v).map(t => tt(t.at(Hint.Recent))) } else tt(cycleNth(g, 0)) case "上" | "前" | "之前" | "往前" | "向前" | "过去" | "过去" => if (s == "上" && (g == Day || g == Year)) None diff --git a/duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/ApiTest.scala b/duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/ApiTest.scala index a60a6641..1764bc6c 100644 --- a/duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/ApiTest.scala +++ b/duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/ApiTest.scala @@ -47,7 +47,7 @@ class ApiTest extends UnitSpec { it("should date") { val options = testOptions.copy(targets = Set(Numeral, Time, Duration, Date), full = false) - println(Api.analyze("一年前的今天", testContext, options)) + println(Api.analyze("最近一周", testContext, options)) } it("should age") { diff --git a/duckling-fork-chinese/learning/src/main/scala/com/xiaomi/duckling/dimension/time/Examples.scala b/duckling-fork-chinese/learning/src/main/scala/com/xiaomi/duckling/dimension/time/Examples.scala index 0a5b284c..cb298d83 100644 --- a/duckling-fork-chinese/learning/src/main/scala/com/xiaomi/duckling/dimension/time/Examples.scala +++ b/duckling-fork-chinese/learning/src/main/scala/com/xiaomi/duckling/dimension/time/Examples.scala @@ -218,7 +218,15 @@ object Examples extends DimExamples { Minute ), List("未来一刻钟", "之后一刻钟", "向后一刻钟", "往后一刻钟", "一刻钟以内") - ) + ), + ( + localDateTimeInterval( + LocalDateTime.of(2013, 2, 12, 0, 0, 0), + LocalDateTime.of(2013, 2, 19, 0, 0, 0), + Day + ), + List("最近一周", "最近一星期", "近七天") + ) ) val weeks = List(