From 3fc74649229569bcbef9a153b18abe3b956f2f05 Mon Sep 17 00:00:00 2001 From: Ninglin Du Date: Tue, 10 Oct 2023 15:00:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B8=A9=E5=BA=A6=E2=80=9C?= =?UTF-8?q?=E4=BA=8C=E5=8D=81=E4=BA=94=E5=BA=A6=E5=85=AD=E2=80=9D=E7=9A=84?= =?UTF-8?q?=E8=AF=B4=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../duckling/dimension/temperature/Rules.scala | 12 +++++++++++- .../duckling/dimension/temperature/Examples.scala | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) 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华氏度")),