diff --git a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/numeral/fraction/Rules.scala b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/numeral/fraction/Rules.scala index fbee2414..e17493ca 100644 --- a/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/numeral/fraction/Rules.scala +++ b/duckling-fork-chinese/core/src/main/scala/com/xiaomi/duckling/dimension/numeral/fraction/Rules.scala @@ -29,7 +29,7 @@ trait Rules extends DimRules { pattern = List(isDimension(Numeral).predicate, "分之".regex, isPositive.predicate), prod = tokens { case Token(_, n1: NumeralData) :: _ :: Token(_, n2: NumeralData) :: _ => - val v = if (n1.value == 0) 0 else n2.value / n1.value + val v = if (n1.value == 0) 0 else (BigDecimal.apply(n2.value)./(BigDecimal.apply(n1.value))).toDouble fraction(v, n2.value, n1.value) } ) @@ -39,7 +39,7 @@ trait Rules extends DimRules { pattern = List(isDimension(Numeral).predicate, "/".regex, isDimension(Numeral).predicate), prod = tokens { case Token(_, n1: NumeralData) :: _ :: Token(_, n2: NumeralData) :: _ => - val v = if (n2.value == 0) 0 else n1.value / n2.value + val v = if (n2.value == 0) 0 else (BigDecimal.apply(n1.value)./(BigDecimal.apply(n2.value))).toDouble fraction(v, n1.value, n2.value) } ) @@ -55,7 +55,7 @@ trait Rules extends DimRules { case "千" => if (neg) -1000.0 else 1000.0 case "万" => if (neg) -10000.0 else 10000.0 } - fraction(n.value / scalar, n.value, scalar) + fraction((BigDecimal.apply(n.value)./(BigDecimal.apply(scalar))).toDouble, n.value, scalar) } ) @@ -68,7 +68,7 @@ trait Rules extends DimRules { case "%" => 0.01 case "‰" => 0.001 } - fraction(n.value * scalar, n.value, 1/scalar) + fraction((BigDecimal.apply(n.value).*(BigDecimal.apply(scalar))).toDouble, n.value, 1/scalar) } ) diff --git a/duckling-fork-chinese/learning/src/main/scala/com/xiaomi/duckling/dimension/numeral/fraction/Examples.scala b/duckling-fork-chinese/learning/src/main/scala/com/xiaomi/duckling/dimension/numeral/fraction/Examples.scala index ee27616a..e71fce6e 100644 --- a/duckling-fork-chinese/learning/src/main/scala/com/xiaomi/duckling/dimension/numeral/fraction/Examples.scala +++ b/duckling-fork-chinese/learning/src/main/scala/com/xiaomi/duckling/dimension/numeral/fraction/Examples.scala @@ -24,6 +24,7 @@ object Examples extends DimExamples { override def pairs: List[(Types.ResolvedValue, List[String])] = List( (0.6, 60.0, 100.0, List("百分之六十")), + (0.7, 70.0, 100.0, List("70%")), (0.6, 600.0, 1000.0, List("千分之六百")), (0.75, 3.0, 4.0, List("4分之3", "四分之3", "3/4")), (0.5, 64.0, 128.0, List("一百二十八分之64")),