diff --git a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/enums/Hint.java b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/enums/Hint.java index 838154e0..e7d9f0c1 100644 --- a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/enums/Hint.java +++ b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/enums/Hint.java @@ -34,6 +34,10 @@ public enum Hint { * 早/晚上位于规则右部 */ PartOfDayAtLast, + /** + * 上午下午组合 + */ + PartOfDay, /** * 节假日 */ diff --git a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/rule/FuzzyDayIntervals.scala b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/rule/FuzzyDayIntervals.scala index 03ec3ea8..fe8e62aa 100644 --- a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/rule/FuzzyDayIntervals.scala +++ b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/rule/FuzzyDayIntervals.scala @@ -123,7 +123,7 @@ object FuzzyDayIntervals { for { hAdjustP <- updatePredicateByFuzzyInterval(part, p) (is12H, hAdjust) <- hAdjustP.hour - } yield timeOfDay(hAdjust, is12H = false, td).copy(timePred = hAdjustP, hint = Hint.NoHint) + } yield timeOfDay(hAdjust, is12H = false, td).copy(timePred = hAdjustP, hint = Hint.PartOfDay) case ( TimeIntervalsPredicate(t, p1: TimeDatePredicate, p2: TimeDatePredicate, beforeEndOfInterval), IntervalOfDay @@ -149,7 +149,7 @@ object FuzzyDayIntervals { pattern = List( // 避免[2017年三月2号早上][10点半] 与 [2017年三月2号][早上10点半] 同时出现,只保留后者 and(isAPartOfDay, not(isHint(PartOfDayAtLast))).predicate, - and(or(isNotLatent, isLatent0oClockOfDay), or(isATimeOfDay, isIntervalOfDay)).predicate + and(or(isNotLatent, isLatent0oClockOfDay), or(isATimeOfDay, isIntervalOfDay), not(isHint(Hint.PartOfDay))).predicate ), prod = { case (options: Options, Token(Time, td0: TimeData) :: Token(Time, td: TimeData) :: _) => @@ -163,7 +163,7 @@ object FuzzyDayIntervals { // 避免[2017年三月2号早上][10点半] 与 [2017年三月2号][早上10点半] 同时出现,只保留后者 and(isAPartOfDay, not(isHint(PartOfDayAtLast)), isNotLatent).predicate, "的".regex, - and(or(isNotLatent, isLatent0oClockOfDay), or(isATimeOfDay, isIntervalOfDay)).predicate + and(or(isNotLatent, isLatent0oClockOfDay), or(isATimeOfDay, isIntervalOfDay), not(isHint(Hint.PartOfDay))).predicate ), prod = { case (options, Token(Time, td0: TimeData) :: _ :: Token(Time, td: TimeData) :: _) => diff --git a/duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/dimension/time/TimeTest.scala b/duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/dimension/time/TimeTest.scala index 856ff7f3..86bc2d0c 100644 --- a/duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/dimension/time/TimeTest.scala +++ b/duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/dimension/time/TimeTest.scala @@ -107,7 +107,7 @@ class TimeTest extends UnitSpec { } it("不支持日到月等") { - val cases = Table("query", "八号到十二月", "八点到五分", "春天一点", "这十分钟后", "十后", "后三十分钟后") + val cases = Table("query", "八号到十二月", "八点到五分", "春天一点", "这十分钟后", "十后", "后三十分钟后", "早上晚上八点") forAll(cases) { query => parse(query, context = testContext, options = options) should have size 0 }