-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 强化 Form,只在确定的情况下增加
- Loading branch information
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/dimension/time/FormTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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号上午", PartOfDay("上午")) | ||
, ("明天上午", PartOfDay("上午")) | ||
) | ||
|
||
it("form test") { | ||
forEvery(cases) { (query, form) => | ||
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 match { | ||
case td: TimeData => td.form shouldBe form | ||
case repeat: RepeatData => repeat.start.get.form shouldBe form | ||
} | ||
} | ||
} | ||
} | ||
} |