From 8e91e928567ef0e3c700893822b3ae6e05d26b2c Mon Sep 17 00:00:00 2001 From: Sonly Date: Fri, 20 Oct 2023 10:39:04 +0800 Subject: [PATCH] =?UTF-8?q?IMP=E4=BF=AE=E6=94=B9=E3=80=90duration+?= =?UTF-8?q?=E5=86=85=E3=80=91interval=E8=8C=83=E5=9B=B4=E7=AD=89=E5=90=8C?= =?UTF-8?q?=E3=80=90=E6=9C=AA=E6=9D=A5+duration=E3=80=91=20(#208)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: zhangsonglei --- .../scala/com/xiaomi/duckling/dimension/time/Rules.scala | 9 +++++++-- .../com/xiaomi/duckling/dimension/time/Examples.scala | 8 ++++---- 2 files changed, 11 insertions(+), 6 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 fe4968dd..3b6c6f31 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 @@ -458,10 +458,15 @@ trait Rules extends DimRules { */ val ruleInAInterval = Rule( name = "in a ", - pattern = List(isNotLatentDuration.predicate, "内".regex), + pattern = List(isNotLatentDuration.predicate, "[之以]?内".regex), prod = tokens { case Token(Duration, DurationData(value, grain, _, _, _)) :: _ => - tt(cycleN(notImmediate = false, grain, value, NoGrain)) + val (g, v) = grain match { + case Month => (Day, value * 30) + case Week => (Day, value * 7) + case _ => (grain, value) + } + tt(cycleN(notImmediate = false, g, v)) } ) 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 e5dc845b..8dc4ed42 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 @@ -106,7 +106,7 @@ object Examples extends DimExamples { LocalDateTime.of(2016, 1, 1, 0, 0, 0), Year ), - List("下三年", "未来三年") + List("下三年", "未来三年", "三年内") ), ( localDateTimeInterval( @@ -216,7 +216,7 @@ object Examples extends DimExamples { LocalDateTime.of(2013, 2, 12, 4, 45, 0), Minute ), - List("未来一刻钟", "之后一刻钟", "向后一刻钟", "往后一刻钟") + List("未来一刻钟", "之后一刻钟", "向后一刻钟", "往后一刻钟", "一刻钟以内") ) ) @@ -271,7 +271,7 @@ object Examples extends DimExamples { LocalDateTime.of(2013, 3, 5, 0, 0, 0), Day ), - List("接下来三周") + List("接下来三周", "三周内") ), ( localDateTimeInterval( @@ -279,7 +279,7 @@ object Examples extends DimExamples { LocalDateTime.of(2013, 2, 19, 0, 0, 0), Day ), - List("未来一周") + List("未来一周", "一周内") ), ( datetime(LocalDateTime.of(2013, 3, 5, 4, 30, 0), Second),