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] Repeat(beta): 支持 "每周三下午","每天下午" #180

Merged
merged 1 commit into from
May 15, 2023
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 @@ -72,13 +72,13 @@ case class RepeatValue(interval: Option[DurationData] = None,
*/
override def schema: Option[String] = {
val duration =
if (interval.nonEmpty) {
val _interval = interval.get
if (_interval.schema.isEmpty) durationSchema(_interval.value.toString, _interval.grain).get
else _interval.schema.get
} else if (workdayType.nonEmpty) {
workdayType.get.toString
} else "undefined"
if (interval.nonEmpty) {
val _interval = interval.get
if (_interval.schema.isEmpty) durationSchema(_interval.value.toString, _interval.grain).get
else _interval.schema.get
} else if (workdayType.nonEmpty) {
workdayType.get.toString
} else "undefined"
val isWorkdayType = workdayType.nonEmpty
start match {
case Some((TimeValue(x, _, _, _, _, _), _)) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import com.xiaomi.duckling.dimension.matcher.GroupMatch
import com.xiaomi.duckling.dimension.matcher.Prods.{regexMatch, singleRegexMatch}
import com.xiaomi.duckling.dimension.time.{form, Time, TimeData}
import com.xiaomi.duckling.dimension.time.duration.{Duration, DurationData}
import com.xiaomi.duckling.dimension.time.enums.Grain
import com.xiaomi.duckling.dimension.time.predicates.{isAPartOfDay, isATimeOfDay, isNotLatent, isTimeDatePredicate, TimeDatePredicate}
import com.xiaomi.duckling.dimension.time.enums.{Grain, Hint}
import com.xiaomi.duckling.dimension.time.predicates.{isAPartOfDay, isATimeOfDay, isHint, isNotLatent, isTimeDatePredicate, IntersectTimePredicate, TimeDatePredicate, TimeIntervalsPredicate}

trait Rules extends DimRules with LazyLogging {
/**
Expand All @@ -46,15 +46,19 @@ trait Rules extends DimRules with LazyLogging {
*/
val ruleEveryDatetime = Rule(
name = "<every> <datetime>",
pattern = List("每(一|一个|个)?".regex, isTimeDatePredicate.predicate),
pattern = List("每(一个|一|个)?".regex, or(isTimeDatePredicate, isHint(Hint.PartOfDayAtLast), isAPartOfDay).predicate),
prod = tokens {
case _ :: (t @ Token(_, td: TimeData)) :: _ =>
val grainOfInterval = td.timePred.asInstanceOf[TimeDatePredicate].maxGrain.get
case _ :: (t@Token(_, td: TimeData)) :: _ if td.timePred.maxGrain.nonEmpty =>
val maxGrain = td.timePred.maxGrain.get
val grain =
if (grainOfInterval == Grain.Hour && (isAPartOfDay(t) || isATimeOfDay(t))) Grain.Day
else grainOfInterval
if (maxGrain == Grain.Hour && (isAPartOfDay(t) || isATimeOfDay(t))) Grain.Day
else maxGrain
val interval = DurationData(1, grain)
Token(Repeat, RepeatData(interval, start = td))
td.timePred match {
case _: TimeDatePredicate | _: TimeIntervalsPredicate | _: IntersectTimePredicate =>
Token(Repeat, RepeatData(interval, start = td))
case _ => None
}
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ object Examples extends DimExamples {
new DuckDateTime(LocalDateTime.of(2013, 2, 12, 8, 0, 0)),
new DuckDateTime(LocalDateTime.of(2013, 2, 12, 12, 0, 0)),
Hour,
partOfDay = "上午"), Some(form.PartOfDay("上午")))), List("每个工作日上午"))
partOfDay = "上午"), Some(form.PartOfDay("上午")))), List("每个工作日上午")),
(RepeatValue(DurationData(1, Week), start = (datetimeInterval(
new DuckDateTime(LocalDateTime.of(2013, 2, 13, 12, 0, 0)),
new DuckDateTime(LocalDateTime.of(2013, 2, 13, 18, 0, 0)),
Hour,
partOfDay = "下午"), Some(form.PartOfDay("下午")))), List("每周三下午"))
)

override val dimension: Dimension = Repeat
Expand Down
Loading