From 71e919acd8f5f80f863b5114984bffd616300c47 Mon Sep 17 00:00:00 2001 From: Ninglin Du Date: Mon, 18 Nov 2024 16:18:08 +0800 Subject: [PATCH] =?UTF-8?q?duration:=20=E5=A2=9E=E5=8A=A0=20=E4=B8=80?= =?UTF-8?q?=E7=82=B9=E4=BA=94=E4=BA=8C=E5=B0=8F=E6=97=B6=20=E7=B1=BB?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../duckling/dimension/time/duration/Rules.scala | 14 +++++++++----- .../dimension/time/duration/Examples.scala | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) 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分钟")),