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] 支持"下一个15号" #253

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -46,7 +46,7 @@ trait Rules extends DimRules {
pattern = List(
"((这|今|本(?!现在))一?个?|明|上+一?个?|前一个?|(?<![一|查|看|搜|记|问|写])下+一?个?)".regex,
// ❌ 下周一早上 => 下[周一早上]
and(isDimension(Time), isNotLatent, not(isHint(Intersect, FinalRule)), not(isAPartOfDay)).predicate
and(isDimension(Time), not(isAPartOfDay), not(isHint(FinalRule))).predicate
),
prod = tokens {
case Token(RegexMatch, GroupMatch(s :: _)) :: (t @ Token(Time, td: TimeData)) :: _ =>
Expand All @@ -58,7 +58,9 @@ trait Rules extends DimRules {
case '上' => -1 * s.takeWhile(_ == '上').length
case '下' =>
val n = 1 * s.takeWhile(_ == '下').length
if (td.holiday.nonEmpty && n > 0) n - 1 else n
if (td.holiday.nonEmpty && n > 0) n - 1
else if (s.endsWith("个")) n - 1
else n
}

val isValidCombination = s(0) match { // 病态表达验证
Expand All @@ -68,7 +70,7 @@ trait Rules extends DimRules {
case Day if td.form.contains(Weekend) => true // 本周末
case _ => false
}
case '上' | '下' => // 上/下, 不与‘天’和‘确切年’组合,eg:本今天,下二零一九年
case '上' | '下' if !s.endsWith("个")=> // 上/下, 不与‘天’和‘确切年’组合,eg:本今天,下二零一九年
if (td.timeGrain == Day && td.holiday.isEmpty && !td.form.contains(Weekend) // 下周末是可以的
|| td.timeGrain == Year) false
else true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ object Examples extends DimExamples {
),
(datetime(LocalDateTime.of(2013, 2, 11, 4, 30, 0), Second), List("昨天现在")),
(datetime(LocalDateTime.of(2013, 2, 22, 8, 0, 0), Hour), List("下周五8点")),
(datetime(LocalDateTime.of(2013, 2, 15, 0, 0, 0), Day), List("下一个15号")),
(datetime(LocalDateTime.of(2013, 11, 20, 20, 0, 0), Hour), List("11.20 20点")),
(datetime(LocalDateTime.of(2013, 12, 24, 0, 0, 0), Day), List("圣诞节的前一天", "圣诞节前一天")),
(datetime(LocalDateTime.of(2013, 2, 12, 5, 5, 0), Minute), List("05分")),
Expand Down
Loading