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 ef67e7e5..007c2e18 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 @@ -116,14 +116,18 @@ trait Rules extends DimRules { val ruleDurationDotNumeral = Rule( name = "number.number grain", - pattern = List("(\\d+)\\.(\\d+)".regex, isDimension(TimeGrain).predicate), + pattern = List(isInteger.predicate, "[点\\.]".regex, or(isDimension(DigitSequence), isIntegerBetween(0, 9)).predicate, isDimension(TimeGrain).predicate), prod = tokens { - case Token(_, GroupMatch(_ :: integer :: decimal :: _)) :: Token(_, GrainData(g, false, _)) :: _ => + case (t1@ Token(_, nd: NumeralData)) :: _ :: Token(_, decimal) :: Token(_, GrainData(g, false, _)) :: _ => + val (dOpt, length) = decimal match { + case ds: DigitSequenceData => (parseInt(ds.seq).toOption, ds.seq.length) + case nd: NumeralData => (getIntValue(nd.value).map(_.toInt), 1) + } (for { - i <- parseInt(integer).toOption - d <- parseInt(decimal).toOption + i <- getIntValue(t1).map(_.toInt) + d <- dOpt } yield { - val mden = math.pow(10, decimal.length).toInt + val mden = math.pow(10, length).toInt val token: Option[Token] = g match { case Grain.NoGrain => None case Grain.Second => None diff --git a/duckling-fork-chinese/learning/src/main/scala/com/xiaomi/duckling/dimension/time/duration/Examples.scala b/duckling-fork-chinese/learning/src/main/scala/com/xiaomi/duckling/dimension/time/duration/Examples.scala index 26fdfac8..4b6b2706 100644 --- a/duckling-fork-chinese/learning/src/main/scala/com/xiaomi/duckling/dimension/time/duration/Examples.scala +++ b/duckling-fork-chinese/learning/src/main/scala/com/xiaomi/duckling/dimension/time/duration/Examples.scala @@ -38,6 +38,7 @@ object Examples extends DimExamples { (DurationData(2000, Year, schema = Some("P2000Y")), List("两千年")), (DurationData(30, Minute, schema = Some("PT0H30M")), List("半小时")), (DurationData(30, Minute, schema = Some("PT30M")), List("0.5小时")), + (DurationData(90, Minute, schema = Some("PT90M")), List("1.5小时", "1.50小时", "一点五小时", "一点五零小时")), (DurationData(30, Minute, schema = Some("PT30M")), List("30分钟", "半个钟头")), (DurationData(12, Hour, schema = Some("P0DT12H")), List("半天")), (DurationData(90, Minute, schema = Some("PT1H30M")), List("一个半小时", "一小时30分钟", "一个小时30分钟")),