diff --git a/duckling-fork-chinese/benchmark/src/main/java/com/xiaomi/duckling/benchmark/DateTimeBenchmark.java b/duckling-fork-chinese/benchmark/src/main/java/com/xiaomi/duckling/benchmark/DateTimeBenchmark.java index 0e19787d..ce142aeb 100644 --- a/duckling-fork-chinese/benchmark/src/main/java/com/xiaomi/duckling/benchmark/DateTimeBenchmark.java +++ b/duckling-fork-chinese/benchmark/src/main/java/com/xiaomi/duckling/benchmark/DateTimeBenchmark.java @@ -46,7 +46,7 @@ @State(Scope.Benchmark) public class DateTimeBenchmark { Context context = new Context(ZonedDateTime.of(LocalDateTime.of(2016, 12, 8, 11, 30, 30), Types.ZoneCN()), Locale.CHINA); - final Types.Options option = new Types.Options(Sets.newHashSet("time", "duration"), false); + final Types.Options option = new Types.Options(Sets.newHashSet("Time", "Duration"), false); final Random rand = new Random(); 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 92d3e250..807d9802 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 @@ -128,7 +128,7 @@ trait Rules extends DimRules { name = "intersect", // 左右边均不能是中午/下午,避免与 冲突 pattern = List( - and(isDimension(Time), isNotLatent, isNotHint(Hint.Season)).predicate, + and(isDimension(Time), isNotLatent, isNotHint(Hint.Season, Hint.FinalRule)).predicate, // "一日"单独是latent,但是可以参与组合 and(isDimension(Time), or(and(or(isNotLatent, isLatent0oClockOfDay), not(isAPartOfDay)), isADayOfMonth)).predicate ), @@ -345,7 +345,7 @@ trait Rules extends DimRules { val predicate = SequencePredicate( List(td, TimeData(TimeOpenIntervalPredicate(intervalDirection), timeGrain = Grain.NoGrain)) ) - tt(TimeData(timePred = predicate, timeGrain = td.timeGrain)) + tt(TimeData(timePred = predicate, timeGrain = td.timeGrain, hint = Hint.FinalRule)) } ) diff --git a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/grain/Rules.scala b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/grain/Rules.scala index 3a7c8916..375f175e 100644 --- a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/grain/Rules.scala +++ b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/grain/Rules.scala @@ -27,7 +27,7 @@ trait Rules extends DimRules { val grains = List( ("second (grain)", "秒钟?", Second), ("minute (grain)", "分(?!贝)钟?", Minute), - ("hour (grain)", "(小时|钟头|钟|点)", Hour), + ("hour (grain)", "(小时|钟头|钟)", Hour), ("day (grain)", "(天(?!气(?!温))|日(?![元本]))", Day), ("week (grain)", WeekPattern, Week), ("month (grain)", "月", Month), @@ -35,7 +35,7 @@ trait Rules extends DimRules { ("year (grain)", "年", Year) ) - val latentExpr = Set("分", "钟", "点") + val latentExpr = Set("分", "钟") override def dimRules: List[Rule] = grains.map { case (name, regexPattern, grain) => diff --git a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/predicates.scala b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/predicates.scala index 055d0a9e..74208bd5 100644 --- a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/predicates.scala +++ b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/predicates.scala @@ -256,8 +256,8 @@ object predicates { case Token(Time | Date, td: TimeData) => hints.contains(td.hint) } - val isNotHint: Hint => Predicate = (hint: Hint) => { - case Token(Time | Date, td: TimeData) => td.hint != hint + def isNotHint(hints: Hint*): Predicate = { + case Token(Time | Date, td: TimeData) => !hints.contains(td.hint) } val is24oClockOfDay: Predicate = {