Skip to content

Commit

Permalink
强化 Form,只在确定的情况下增加
Browse files Browse the repository at this point in the history
  • Loading branch information
du00cs committed Aug 8, 2024
1 parent db324a3 commit 46a905f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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点)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Expand Down

0 comments on commit 46a905f

Please sign in to comment.