Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DUCK] 修复“过去七天”这种表达在alwaysInFuture = false的时候也反转的了问题 #223

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ case class TimeData(timePred: TimePredicate,
val refTime =
refTimeAdjust(new TimeObject(context.referenceTime, Grain.Second), options.timeOptions)

val reverseTake = hint == Hint.UncertainRecent && !options.timeOptions.recentInFuture || !options.timeOptions.alwaysInFuture
val reverseTake = (hint == Hint.UncertainRecent && !options.timeOptions.recentInFuture
|| hint != Hint.Recent && !options.timeOptions.alwaysInFuture)
val valueOpt =
try {
resolveTimeData(refTime, this, reverseTake)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,40 @@ class TimeDataTest extends UnitSpec with LazyLogging {
}
}

val testCases = List(
//2013, 2, 12, 4, 30, 0
("昨天", 2013, 2, 11),
("今天", 2013, 2, 12),
("明天", 2013, 2, 13),
("一月二号", 2013, 1, 2),
("二月十一号", 2013, 2, 11),
("明年一月二号", 2014, 1, 2),
("今年三月十号", 2013, 3, 10)
val testCases = Table( ("query", "year", "month", "day"),
("最近三天", 2013, 2, 9)
, ("过去三天", 2013, 2, 9)
, ("昨天", 2013, 2, 11)
, ("今天", 2013, 2, 12)
, ("明天", 2013, 2, 13)
, ("一月二号", 2013, 1, 2)
, ("二月十一号", 2013, 2, 11)
, ("明年一月二号", 2014, 1, 2)
, ("今年三月十号", 2013, 3, 10)
)

it("not InFuture eq") {
val timeOptions = new TimeOptions()
timeOptions.setAlwaysInFuture(false)
timeOptions.setRecentInFuture(false)
val options = testOptions.copy(targets = Set(Time), timeOptions = timeOptions)

testCases.foreach {
case (query, yyyy, mm, dd) =>
val answers = analyze(query, testContext, options)
answers.headOption match {
case Some(answer) =>
answer.token.value match {
case TimeValue(SimpleValue(InstantValue(dt, _)), _, _, _, _, _) =>
(dt.year, dt.month, dt.dayOfMonth) shouldBe(yyyy, mm, dd)
case v =>
logger.warn(s"unexpected value: $query => $v")
true shouldBe false
}
case _ =>
logger.warn(s"empty result: $query")
true shouldBe false
}
forAll(testCases) { (query, yyyy, mm, dd) =>
val answers = analyze(query, testContext, options)
answers.headOption match {
case Some(answer) =>
answer.token.value match {
case TimeValue(SimpleValue(InstantValue(dt, _)), _, _, _, _, _) =>
(dt.year, dt.month, dt.dayOfMonth) shouldBe(yyyy, mm, dd)
case TimeValue(IntervalValue(InstantValue(dt, _), _), _, _, _, _, _) =>
(dt.year, dt.month, dt.dayOfMonth) shouldBe(yyyy, mm, dd)
case v =>
logger.warn(s"unexpected value: $query => $v")
true shouldBe false
}
case _ =>
logger.warn(s"empty result: $query")
true shouldBe false
}
}
}

Expand Down
Loading