This is an automated email from the ASF dual-hosted git repository. sergeykamov pushed a commit to branch NLPCRAFT-400 in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
commit 26a546d8e3a78f56e3d1567acf433dec105faece Author: Sergey Kamov <[email protected]> AuthorDate: Tue Aug 10 11:22:37 2021 +0300 WIP. --- nlpcraft/src/main/resources/date/full.txt.gz | Bin 6098772 -> 6985934 bytes nlpcraft/src/main/resources/date/parts.txt.gz | Bin 8104071 -> 8146091 bytes nlpcraft/src/main/resources/date/parts_dmy.txt.gz | Bin 4949759 -> 4986446 bytes nlpcraft/src/main/resources/date/parts_mdy.txt.gz | Bin 4923267 -> 4955873 bytes nlpcraft/src/main/resources/date/parts_ymd.txt.gz | Bin 5298790 -> 5326821 bytes .../nlp/enrichers/date/tools/NCDateGenerator.scala | 30 ++++++++++--- .../nlp/enrichers/date/NCEnricherDateSpec.scala | 47 +++++++++++++++++++++ 7 files changed, 71 insertions(+), 6 deletions(-) diff --git a/nlpcraft/src/main/resources/date/full.txt.gz b/nlpcraft/src/main/resources/date/full.txt.gz index f303bd5..37216a0 100644 Binary files a/nlpcraft/src/main/resources/date/full.txt.gz and b/nlpcraft/src/main/resources/date/full.txt.gz differ diff --git a/nlpcraft/src/main/resources/date/parts.txt.gz b/nlpcraft/src/main/resources/date/parts.txt.gz index 5529eb8..4b7008a 100644 Binary files a/nlpcraft/src/main/resources/date/parts.txt.gz and b/nlpcraft/src/main/resources/date/parts.txt.gz differ diff --git a/nlpcraft/src/main/resources/date/parts_dmy.txt.gz b/nlpcraft/src/main/resources/date/parts_dmy.txt.gz index 3d1885c..42d35d7 100644 Binary files a/nlpcraft/src/main/resources/date/parts_dmy.txt.gz and b/nlpcraft/src/main/resources/date/parts_dmy.txt.gz differ diff --git a/nlpcraft/src/main/resources/date/parts_mdy.txt.gz b/nlpcraft/src/main/resources/date/parts_mdy.txt.gz index 195a71a..faeac93 100644 Binary files a/nlpcraft/src/main/resources/date/parts_mdy.txt.gz and b/nlpcraft/src/main/resources/date/parts_mdy.txt.gz differ diff --git a/nlpcraft/src/main/resources/date/parts_ymd.txt.gz b/nlpcraft/src/main/resources/date/parts_ymd.txt.gz index 2b1c176..22f38bf 100644 Binary files a/nlpcraft/src/main/resources/date/parts_ymd.txt.gz and b/nlpcraft/src/main/resources/date/parts_ymd.txt.gz differ diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/date/tools/NCDateGenerator.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/date/tools/NCDateGenerator.scala index d20d94e..646267c 100644 --- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/date/tools/NCDateGenerator.scala +++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/date/tools/NCDateGenerator.scala @@ -453,17 +453,35 @@ object NCDateGenerator { } private[date] def simpleYears(df: LHM_SS): Unit = { + def addRange(from:String, to: String , y1: Int, y2: Int, templ: String): Unit = { + df += s"$from $y1 $to $y2" -> templ + df += s"$from $y1 y $to $y2 y" -> templ + df += s"$from ${y1}y $to ${y2}y" -> templ + df += s"$from $y1 year $to $y2 year" -> templ + df += s"$from ${y1}year $to ${y2}year" -> templ + df += s"$from $y1 $to $y2 years" -> templ + } + // Between. - for (b <- BETWEEN_INCLUSIVE; y1 <- YEARS_SEQ; y2 <- YEARS_SEQ if y2 > y1) - df += s"${b._1} $y1 ${b._2} $y2" -> s"${y1}y:${y2}y" - for (b <- BETWEEN_EXCLUSIVE; y1 <- YEARS_SEQ; y2 <- YEARS_SEQ if y2 > y1) - df += s"${b._1} $y1 ${b._2} $y2" -> s"${y1}y:${y2-1}y" + for ((from, to) <- BETWEEN_INCLUSIVE; y1 <- YEARS_SEQ; y2 <- YEARS_SEQ if y2 > y1) + addRange(from, to, y1, y2, s"${y1}y:${y2}y") + + for ((from, to) <- BETWEEN_EXCLUSIVE; y1 <- YEARS_SEQ; y2 <- YEARS_SEQ if y2 > y1) + addRange(from, to, y1, y2, s"${y1}y:${y2-1}y") + + def add(word: String, y: Int, templ: String): Unit = { + s"$word $y" -> templ + s"$word $y y" -> templ + s"$word ${y}y" -> templ + s"$word $y year" -> templ + s"$word ${y}year" -> templ + } // From. - for (f <- FROM; y <- YEARS_SEQ) df += s"$f $y" -> toNow(s"${y}y") + for (f <- FROM; y <- YEARS_SEQ) add(f, y, toNow(s"${y}y")) // Till. - for (t <- TO; y <- YEARS_SEQ) df += s"$t $y" -> to(s"${y}y") + for (t <- TO; y <- YEARS_SEQ) add(t, y, to(s"${y}y")) } private[date] def simpleQuarters(df: LHM_SS): Unit = { diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/date/NCEnricherDateSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/date/NCEnricherDateSpec.scala new file mode 100644 index 0000000..429b24c --- /dev/null +++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/date/NCEnricherDateSpec.scala @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.nlpcraft.probe.mgrs.nlp.enrichers.date + +import org.apache.nlpcraft.NCTestEnvironment +import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{NCDefaultTestModel, NCEnricherBaseSpec, NCTestDateToken => dte} +import org.junit.jupiter.api.Test + +/** + * Date enricher test. + */ +@NCTestEnvironment(model = classOf[NCDefaultTestModel], startClient = true) +class NCEnricherDateSpec extends NCEnricherBaseSpec { + /** + * + * @throws Exception + */ + @Test + def test(): Unit = + runBatch( + Seq("today", + "1900", + "1900 year", + "from 1900 year", + "between 1900 and 1905", + "between 1900 and 1905 years" + ).map(txt => { + val f: Unit => Unit = _ => checkExists(txt, dte(text = txt)) + + f + }):_*) +}
