Skip to content

Commit

Permalink
增加温度“二十五度六”的说法
Browse files Browse the repository at this point in the history
  • Loading branch information
du00cs committed Oct 10, 2023
1 parent dd03adc commit 3fc7464
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -97,4 +97,14 @@ trait Rules extends DimRules {
Token(Temperature, QuantityData(temperature_value, "C", "温度"))
}
)

val ruleDecimal1Temperature = Rule(
name = "<number> 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", "温度"))
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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华氏度")),
Expand Down

0 comments on commit 3fc7464

Please sign in to comment.