diff --git a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/temperature/Rules.scala b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/temperature/Rules.scala index 7b9ceeb2..6c92a932 100644 --- a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/temperature/Rules.scala +++ b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/temperature/Rules.scala @@ -20,7 +20,7 @@ import com.xiaomi.duckling.Types._ import com.xiaomi.duckling.dimension.DimRules import com.xiaomi.duckling.dimension.implicits._ import com.xiaomi.duckling.dimension.matcher.{GroupMatch, RegexMatch} -import com.xiaomi.duckling.dimension.numeral.Predicates.isInteger +import com.xiaomi.duckling.dimension.numeral.Predicates.{isInteger, isIntegerBetween} import com.xiaomi.duckling.dimension.numeral.{Numeral, NumeralData} import com.xiaomi.duckling.dimension.quantity.QuantityData @@ -97,4 +97,14 @@ trait Rules extends DimRules { Token(Temperature, QuantityData(temperature_value, "C", "温度")) } ) + + val ruleDecimal1Temperature = Rule( + name = " unit like [30度5]", + pattern = List(and(isInteger).predicate, "度".regex, isIntegerBetween(1, 9).predicate), + prod = tokens { + case Token(Numeral, NumeralData(v1, _, _, _, _, _)) :: _ :: Token(Numeral, NumeralData(v2, _, _, _, _, _)) :: _ => + val temperature_value = if (v1 >= 0) v1 + 0.1 * v2 else v1 - 0.1 * v2 + Token(Temperature, QuantityData(temperature_value, "C", "温度")) + } + ) } diff --git a/duckling-fork-chinese/learning/src/main/scala/com/xiaomi/duckling/dimension/temperature/Examples.scala b/duckling-fork-chinese/learning/src/main/scala/com/xiaomi/duckling/dimension/temperature/Examples.scala index 89a37bda..6d63d97d 100644 --- a/duckling-fork-chinese/learning/src/main/scala/com/xiaomi/duckling/dimension/temperature/Examples.scala +++ b/duckling-fork-chinese/learning/src/main/scala/com/xiaomi/duckling/dimension/temperature/Examples.scala @@ -24,7 +24,7 @@ object Examples extends DimExamples { override def pairs: List[(Types.ResolvedValue, List[String])] = List( (QuantityValue(30, "C", "温度"), List("摄氏30度", "30摄氏度")), (QuantityValue(13, "C", "温度"), List("十三度", "十三°", "13°C")), - (QuantityValue(12.5, "C", "温度"), List("12点5度", "12.5摄氏度")), + (QuantityValue(12.5, "C", "温度"), List("12点5度", "12.5摄氏度", "十二度五")), (QuantityValue(-25.3, "C", "温度"), List("零下25.3摄氏度", "零下25.3°C", "负的二十五点3度")), (QuantityValue(21, "F", "温度"), List("华氏21度", "2十一华氏度")), (QuantityValue(+22.6, "F", "温度"), List("华氏22点6度", "二十二点6华氏度")),