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 e9e302a..85b8f51 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 @@ -186,6 +186,7 @@ trait Rules extends DimRules { val form = (td1.form, td2.form) match { case (Some(PartOfDay(_)), Some(tod: TimeOfDay)) => Some(tod.copy(is12H = false)) case (Some(DayOfWeek), Some(_: TimeOfDay)) => td2.form + case (None, _) => td2.form case _ => None } // 10号八点,需要去掉AMPM (今天是10号9点时,不应再出20点) diff --git a/duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/dimension/time/FormTest.scala b/duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/dimension/time/FormTest.scala index 7751967..0b909d8 100644 --- a/duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/dimension/time/FormTest.scala +++ b/duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/dimension/time/FormTest.scala @@ -3,27 +3,30 @@ package com.xiaomi.duckling.dimension.time import com.xiaomi.duckling.{Api, UnitSpec} import com.xiaomi.duckling.dimension.implicits._ import com.xiaomi.duckling.dimension.time.form.{Form, PartOfDay, TimeOfDay} +import com.xiaomi.duckling.dimension.time.repeat.{Repeat, RepeatData} import com.xiaomi.duckling.ranking.Testing class FormTest extends UnitSpec { describe("Form") { val cases = Table[String, Option[Form]](("query", "form") + , ("每个月五号的早上", PartOfDay("早上")) + , ("23号8点", TimeOfDay(8, true)) , ("23号上午8点", TimeOfDay(8, false)) , ("8点", TimeOfDay(8, true)) , ("上午8点", TimeOfDay(8, false)) - , ("23号8点", None) , ("23号上午", PartOfDay("上午")) , ("明天上午", PartOfDay("上午")) ) it("form test") { forEvery(cases) { (query, form) => - val answers = Api.analyze(query, Testing.testContext, Testing.testOptions.copy(targets = Set(Time))) + val answers = Api.analyze(query, Testing.testContext, Testing.testOptions.copy(targets = Set(Time, Repeat))) answers should not be empty - answers.head.token.node.token.data shouldBe a[TimeData] - val tv = answers.head.token.node.token.data.asInstanceOf[TimeData] - tv.form shouldBe form + answers.head.token.node.token.data match { + case td: TimeData => td.form shouldBe form + case repeat: RepeatData => repeat.start.get.form shouldBe form + } } } }