Repository: XiaoMi/MiNLP (language: python)

Issue:
[DUCK] temperature支持25度半
支持：25度半，零下25度半，华氏25度半
[DUCK] 最近几次修改引入的问题
date+晚：国庆晚会，十月一晚会，错误抽取：国庆晚/十月一晚  
叫一下钟浩然，错误抽取：下钟  
六点半：错误抽取为duration  
单字：晚/早，抽取为interval


Discussion / hints:

Fix patch:
diff --git a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/Rules.scala b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/Rules.scala
index 87896322..a4ad712f 100644
--- a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/Rules.scala
+++ b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/Rules.scala
@@ -184,7 +184,7 @@ trait Rules extends DimRules {
     pattern =
       List("(这个?|今个?|本|下+一?个?|上+一?个?|去|昨|明|大*前|大*后)".regex, isDimension(TimeGrain).predicate),
     prod = tokens {
-      case Token(_, GroupMatch(s :: _)) :: Token(TimeGrain, GrainData(g, _)) :: _ =>
+      case Token(_, GroupMatch(s :: _)) :: Token(TimeGrain, GrainData(g, false)) :: _ =>
         val td: Option[TimeData] = s(0) match {
           case '这' => cycleNthThis(0, g, Year, Month, Hour, Week)
           case '今' => cycleNthThis(0, g, Year, Month, Day)
diff --git a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/duration/Rules.scala b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/duration/Rules.scala
index f60f5e02..f22d6a6f 100644
--- a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/duration/Rules.scala
+++ b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/duration/Rules.scala
@@ -133,9 +133,14 @@ trait Rules extends DimRules {
 
   val ruleDurationNumberGrainAndHalf = Rule(
     name = "<natural> <unit-of-duration> and a half",
-    pattern = List(isNatural.predicate, isDimension(TimeGrain).predicate, "半钟?".regex),
+    pattern = List(isNatural.predicate, "(分半钟?|天半|年半)".regex),
     prod = tokens {
-      case t1 :: Token(TimeGrain, GrainData(g, _)) :: _ =>
+      case t1 :: Token(_, GroupMatch(d :: _)) :: _ =>
+        val g = d.charAt(0) match {
+          case '分' => Minute
+          case '天' => Day
+          case '年' => Year
+        }
         for {
           i <- getIntValue(t1)
           d <- timesOneAndAHalf(g, i.toInt)
diff --git a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/rule/FuzzyDayIntervals.scala b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/rule/FuzzyDayIntervals.scala
index b4deb717..8ba188cc 100644
--- a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/rule/FuzzyDayIntervals.scala
+++ b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/rule/FuzzyDayIntervals.scala
@@ -77,7 +77,7 @@ object FuzzyDayIntervals {
     Rule(name = "fuzzy day intervals", pattern = List(pattern.regex), prod = singleRegexMatch {
       case s =>
         for ((name, td) <- ofInterval(s)) yield {
-          tt(partOfDay(name, td).copy(latent = name.length == 1))
+          tt(partOfDay(name, td).copy(latent = s.length == 1))
         }
     })
 
diff --git a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/rule/Times.scala b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/rule/Times.scala
index d7bba813..a5670c25 100644
--- a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/rule/Times.scala
+++ b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/time/rule/Times.scala
@@ -81,7 +81,7 @@ object Times {
 
   val ruleDimTimePartOfDay = Rule(
     name = "<dim time> <part-of-day>",
-    pattern = List(isADayOfMonth.predicate, isAPartOfDay.predicate),
+    pattern = List(isADayOfMonth.predicate, and(isAPartOfDay, isNotLatent).predicate),
     prod = tokens {
       case Token(Time, td1: TimeData) :: Token(Time, td2: TimeData) :: _ =>
         for (td <- intersect(td1, td2)) yield {


Test patch:
diff --git a/duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/dimension/time/TimeTest.scala b/duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/dimension/time/TimeTest.scala
index 7156a80a..2b4df093 100644
--- a/duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/dimension/time/TimeTest.scala
+++ b/duckling-fork-chinese/core/src/test/scala/com/xiaomi/duckling/dimension/time/TimeTest.scala
@@ -27,6 +27,7 @@ import com.xiaomi.duckling.dimension.time.predicates.ReplacePartPredicate
 import com.xiaomi.duckling.ranking.Testing
 import com.xiaomi.duckling.ranking.Testing._
 import com.xiaomi.duckling.UnitSpec
+import com.xiaomi.duckling.dimension.time.duration.Duration
 
 class TimeTest extends UnitSpec {
 
@@ -111,6 +112,15 @@ class TimeTest extends UnitSpec {
         parse(query, context = testContext, options = options) should have size 0
       }
     }
+
+    it("fix #187") {
+      val opt = options.copy(full = true, withLatent = false)
+      val cases = Table("query", "国庆晚", "十月一晚", "下钟", "晚")
+      forAll(cases) {query =>
+        parse(query, options = opt) should be (empty)
+      }
+      parse("六点半", options = opt.copy(targets = Set(Duration))) should be (empty)
+    }
   }
 
   describe("TimeSimpleTest") {