From 1abfe9438ccbabb687671a5d283f555f28b3e001 Mon Sep 17 00:00:00 2001 From: Ninglin Du Date: Tue, 19 Nov 2024 14:37:55 +0800 Subject: [PATCH] =?UTF-8?q?time:=20=E6=94=AF=E6=8C=81"=E4=B8=8B=E4=B8=80?= =?UTF-8?q?=E4=B8=AA15=E5=8F=B7"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scala/com/xiaomi/duckling/dimension/time/Rules.scala | 8 +++++--- .../com/xiaomi/duckling/dimension/time/Examples.scala | 1 + 2 files changed, 6 insertions(+), 3 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 cd8779f..4fe78a5 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 @@ -46,7 +46,7 @@ trait Rules extends DimRules { pattern = List( "((这|今|本(?!现在))一?个?|明|上+一?个?|前一个?|(? 下[周一早上] - and(isDimension(Time), isNotLatent, not(isHint(Intersect, FinalRule)), not(isAPartOfDay)).predicate + and(isDimension(Time), not(isAPartOfDay)).predicate ), prod = tokens { case Token(RegexMatch, GroupMatch(s :: _)) :: (t @ Token(Time, td: TimeData)) :: _ => @@ -58,7 +58,9 @@ trait Rules extends DimRules { case '上' => -1 * s.takeWhile(_ == '上').length case '下' => val n = 1 * s.takeWhile(_ == '下').length - if (td.holiday.nonEmpty && n > 0) n - 1 else n + if (td.holiday.nonEmpty && n > 0) n - 1 + else if (s.endsWith("个")) n - 1 + else n } val isValidCombination = s(0) match { // 病态表达验证 @@ -68,7 +70,7 @@ trait Rules extends DimRules { case Day if td.form.contains(Weekend) => true // 本周末 case _ => false } - case '上' | '下' => // 上/下, 不与‘天’和‘确切年’组合,eg:本今天,下二零一九年 + case '上' | '下' if !s.endsWith("个")=> // 上/下, 不与‘天’和‘确切年’组合,eg:本今天,下二零一九年 if (td.timeGrain == Day && td.holiday.isEmpty && !td.form.contains(Weekend) // 下周末是可以的 || td.timeGrain == Year) false else true 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 82d7b75..eb0765f 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 @@ -495,6 +495,7 @@ object Examples extends DimExamples { ), (datetime(LocalDateTime.of(2013, 2, 11, 4, 30, 0), Second), List("昨天现在")), (datetime(LocalDateTime.of(2013, 2, 22, 8, 0, 0), Hour), List("下周五8点")), + (datetime(LocalDateTime.of(2013, 2, 15, 0, 0, 0), Day), List("下一个15号")), (datetime(LocalDateTime.of(2013, 11, 20, 20, 0, 0), Hour), List("11.20 20点")), (datetime(LocalDateTime.of(2013, 12, 24, 0, 0, 0), Day), List("圣诞节的前一天", "圣诞节前一天")), (datetime(LocalDateTime.of(2013, 2, 12, 5, 5, 0), Minute), List("05分")),