Skip to content
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 @@ -213,7 +213,10 @@ trait Rules extends DimRules {
if td1.timeGrain > td2.timeGrain && !(td1.hint == Hint.Date && td2.hint == Hint.Date) ||
// 上午的8-9点
td1.timeGrain == td2.timeGrain && td1.timeGrain == Hour && isAPartOfDay(t1) && !isAPartOfDay(t2) =>
intersectToken(options, td1, td2)
val g1 = td1.timePred.maxGrain
val g2 = td2.timePred.maxGrain
if (g1.isDefined && g2.isDefined && g1.get < g2.get) None
else intersectToken(options, td1, td2)
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ case class TimeData(timePred: TimePredicate,
case TimeDatePredicate(second, minute, hour, _, _, dayOfMonth, month, year, _) =>
// 如:2021年10月1日12点三十分
Simple(year, month, dayOfMonth, hour, minute, second, offset=Some(false))
case IntersectTimePredicate(TimeDatePredicate(second, minute, hour, _, _, _, _, _, _), IntersectTimePredicate(TimeDatePredicate(_, _, _, _, _, dayOfMonth, month, _, _), SeriesPredicate(_))) =>
case IntersectTimePredicate(TimeDatePredicate(second, minute, hour, _, _, _, _, _, _), IntersectTimePredicate(TimeDatePredicate(_, _, _, _, _, dayOfMonth, month, _, _), SeriesPredicate(_, _))) =>
// 如: 明年三月一号十二点三十分, 年份隐式表达SeriesPredicate
Simple(None, month, dayOfMonth, hour, minute, second, offset=Some(true))
case IntersectTimePredicate(SequencePredicate(_), TimeDatePredicate(_, _, _, _, _, _, _, year, _)) =>
Expand All @@ -217,26 +217,26 @@ case class TimeData(timePred: TimePredicate,
case IntersectTimePredicate(TimeDatePredicate(second, minute, hour, _, _, _, _, _, _), SequencePredicate(_)) =>
// 如:除夕十二点三十分,没有年份表达,除夕SequencePredicate
Simple(hour=hour, minute=minute, second=second, offset=Some(false))
case IntersectTimePredicate(TimeDatePredicate(second, minute, hour, _, _, _, _, _, _), IntersectTimePredicate(SequencePredicate(_), SeriesPredicate(_))) =>
case IntersectTimePredicate(TimeDatePredicate(second, minute, hour, _, _, _, _, _, _), IntersectTimePredicate(SequencePredicate(_), SeriesPredicate(_, _))) =>
// 如:今年除夕十二点三十分,年份隐式表达,除夕SequencePredicate
Simple(hour=hour, minute=minute, second=second, offset=Some(true))
case IntersectTimePredicate(TimeDatePredicate(second, minute, hour, _, _, _, _, _, _), IntersectTimePredicate(_, TimeDatePredicate(_, _, _, _, _, _, _, year, _))) =>
// 如:2021年[除夕、节气、西方节日]十二点三十分,有具体年份表达
Simple(year=year, hour=hour, minute=minute, second=second, offset=Some(false))
case IntersectTimePredicate(TimeDatePredicate(second, minute, hour, _, _, _, _, _, _), IntersectTimePredicate(SeriesPredicate(_), SeriesPredicate(_))) =>
case IntersectTimePredicate(TimeDatePredicate(second, minute, hour, _, _, _, _, _, _), IntersectTimePredicate(SeriesPredicate(_, _), SeriesPredicate(_, _))) =>
// 如:明年[清明节、西方节日]十二点三十分,年份隐式表达,节气SeriesPredicate
Simple(hour=hour, minute=minute, second=second, offset=Some(true))
case IntersectTimePredicate(SeriesPredicate(_), TimeDatePredicate(second, minute, hour, _, _, _, _, year, _)) =>
case IntersectTimePredicate(SeriesPredicate(_, _), TimeDatePredicate(second, minute, hour, _, _, _, _, year, _)) =>
// 如:2021年[清明节、西方节日],节气需要根据年份查表获取具体日期,只抽取年,节气SeriesPredicate
Simple(year=year, hour=hour, minute=minute, second=second, offset=Some(false))
case IntersectTimePredicate(TimeDatePredicate(second, minute, hour, _, _, dayOfMonth, month, _, _), SeriesPredicate(_)) =>
case IntersectTimePredicate(TimeDatePredicate(second, minute, hour, _, _, dayOfMonth, month, _, _), SeriesPredicate(_, grain)) =>
// 如:[清明节、西方节日]十二点三十分,今年国庆节,明年中秋节,今天十二点三十分,年份/日期隐式表达和节气SeriesPredicate
val offset = (second.isDefined || minute.isDefined || hour.isDefined) && holiday.exists(_.nonEmpty)
Simple(None, month, dayOfMonth, hour, minute, second, offset=Some(!offset))
case IntersectTimePredicate(SeriesPredicate(_), SeriesPredicate(_)) =>
case IntersectTimePredicate(SeriesPredicate(_, _), SeriesPredicate(_, _)) =>
// 如:今年[清明节、西方节日],年份隐式表达和节气SeriesPredicate
Simple(offset=Some(true))
case SeriesPredicate(_) =>
case SeriesPredicate(_, _) =>
// 如:[清明节、西方节日]西方节日和节气SeriesPredicate
Simple(offset=if (holiday.exists(_.nonEmpty)) Some(false) else Some(true))
case _ => Simple()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ object TimePredicateHelpers {
}
}

SeriesPredicate(timeSeqMap(false, f, basePred))
SeriesPredicate(timeSeqMap(false, f, basePred), basePred.maxGrain)
}

def timeCycle(grain: Grain): CycleSeriesPredicate = timeCycle(grain, grain)
Expand Down Expand Up @@ -192,7 +192,7 @@ object TimePredicateHelpers {
}
}

SeriesPredicate(series)
SeriesPredicate(series, cycleSP.maxGrain)
}

/**
Expand Down Expand Up @@ -221,7 +221,7 @@ object TimePredicateHelpers {
else (Stream(nth), Stream.empty)
}
}
SeriesPredicate(series)
SeriesPredicate(series, f.maxGrain)
}

/**
Expand Down Expand Up @@ -255,7 +255,7 @@ object TimePredicateHelpers {
(Stream.iterate(anchor)(f(-1)).tail, Stream.iterate(anchor)(f(1)))
}
}
SeriesPredicate(series)
SeriesPredicate(series, Some(Day))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ package object time {
def runPredicate(tp: TimePredicate): SeriesPredicateF = {
tp match {
case EmptyTimePredicate => EmptySeriesPredicate
case SeriesPredicate(f) => f
case SeriesPredicate(f, _) => f
case TimeDatePredicate(sec, min, hour, ampm, dayOfWeek, dayOfMonth, month, year, calendar) =>
if (hour.isEmpty && ampm.nonEmpty) EmptySeriesPredicate
else {
Expand Down Expand Up @@ -197,8 +197,8 @@ package object time {
t2 <- resolveTimeData(t, td2)
} yield {
val to =
if (td2.timePred.maxGrain.nonEmpty && td1.timeGrain > td2.timePred.maxGrain.get) {
copyGrain(Year, td2.timePred.maxGrain.get, t1, t2)
if (td2.timePred.maxGrain.nonEmpty && td1.timeGrain > td2.timePred.maxGrain.get && td1.timeGrain.finer().isDefined) {
copyGrain(Year, td1.timeGrain.finer().get, t1, t2)
} else {
(td1.timeGrain, td2.timeGrain) match {
case (Year, Month) => t2.copy(start = t2.start.withYear(t1.start.year))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ object predicates {
}
}

case class SeriesPredicate(f: SeriesPredicateF) extends TimePredicate {
case class SeriesPredicate(f: SeriesPredicateF, grainOpt: Option[Grain]) extends TimePredicate {
override def toString: String = "f:Series"
override val maxGrain: Option[Grain] = grainOpt
}

case class IntersectTimePredicate(pred1: TimePredicate, pred2: TimePredicate)
Expand Down Expand Up @@ -105,12 +106,17 @@ object predicates {
/**
* 用td1的部分信息替换td2的结果,解决明年的今天、上个月的今天之类的问题
*/
case class ReplacePartPredicate(td1: TimeData, td2: TimeData) extends TimePredicate
case class ReplacePartPredicate(td1: TimeData, td2: TimeData) extends TimePredicate {
override val maxGrain: Option[Grain] = td1.timeGrain
}

case object EndOfGrainPredicate extends TimePredicate

case class CycleSeriesPredicate(seriesF: SeriesPredicateF, n: Int, grain: Grain)
extends TimePredicate
extends TimePredicate {

override val maxGrain: Option[Grain] = Some(grain)
}

val singleNumeber: Predicate = isIntegerBetween(0, 9)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,13 @@ class TimeTest extends UnitSpec {
}
}

it("fix #187") {
it("不需要支持的") {
val opt = options.copy(full = true, withLatent = false)
val cases = Table("query", "国庆晚", "十月一晚", "下钟", "晚")
val cases = Table("query",
// fix #187
"国庆晚", "十月一晚", "下钟", "晚",
// fix #259
"上午今天早上七点")
forAll(cases) {query =>
parse(query, options = opt) should be (empty)
}
Expand Down
Loading