Skip to content

Commit

Permalink
为 上午/下午... 默认开启beforeEndOfInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
du00cs committed Jul 5, 2023
1 parent f5c4e7f commit 74b0020
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ object FuzzyDayIntervals {
}
}

def ofInterval(s: String, larger: Boolean = false, beforeEndOfInterval: Boolean): Option[(String, TimeData)] = {
def ofInterval(s: String, larger: Boolean = false): Option[(String, TimeData)] = {
val (name, (from, to), (_from, _to)) = between(s)
val td =
if (larger) interval(Open, hour(is12H = false, _from), hour(is12H = false, _to), beforeEndOfInterval)
else interval(Open, hour(is12H = false, from), hour(is12H = false, to), beforeEndOfInterval)
if (larger) interval(Open, hour(is12H = false, _from), hour(is12H = false, _to), beforeEndOfInterval = true)
else interval(Open, hour(is12H = false, from), hour(is12H = false, to), beforeEndOfInterval = true)
td.map((name, _))
}

Expand All @@ -67,7 +67,7 @@ object FuzzyDayIntervals {
def enlarge(td: TimeData, beforeEndOfInterval: Boolean): TimeData = {
(td.form, td.timePred) match {
case (Some(PartOfDay(part)), _: TimeIntervalsPredicate) =>
val _td = ofInterval(part, larger = true, beforeEndOfInterval).map(_._2).get
val _td = ofInterval(part, larger = true).map(_._2).get
_td.copy(latent = td.latent)
case _ => td
}
Expand All @@ -79,7 +79,7 @@ object FuzzyDayIntervals {
case (options, tokens: List[Token]) =>
tokens.headOption.flatMap {
case Token(RegexMatch, GroupMatch(s :: _)) =>
for ((name, td) <- ofInterval(s, beforeEndOfInterval = options.timeOptions.beforeEndOfInterval)) yield {
for ((name, td) <- ofInterval(s)) yield {
tt(partOfDay(name, td).copy(latent = s.length == 1))
}
case _ => None
Expand All @@ -103,7 +103,7 @@ object FuzzyDayIntervals {
case '中' => "中午"
case '晚' => "晚上"
}
val tdInterval = ofInterval(part, beforeEndOfInterval = options.timeOptions.beforeEndOfInterval)
val tdInterval = ofInterval(part)
for {
(_, td) <- tdInterval
td1 <- intersect(cycleNth(Day, offset), td)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,15 @@ object Examples extends DimExamples {
),
List("9点到9点")
),
(
localDateTimeInterval(
LocalDateTime.of(2013, 2, 12, 0, 0, 0),
LocalDateTime.of(2013, 2, 12, 6, 0, 0),
Hour,
partOfDay = "凌晨"
),
List("凌晨")
),
(
localDateTimeInterval(
LocalDateTime.of(2013, 2, 13, 15, 0, 0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ object NaiveBayesDebug {
options.timeOptions.setResetTimeOfDay(false)
options.timeOptions.setRecentInFuture(true)
options.timeOptions.setAlwaysInFuture(true)
options.timeOptions.setBeforeEndOfInterval(true)
options.timeOptions.setBeforeEndOfInterval(false)
options.numeralOptions.setAllowZeroLeadingDigits(false)
options.numeralOptions.setCnSequenceAsNumber(false)

Expand Down

0 comments on commit 74b0020

Please sign in to comment.