You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2021/05/31 03:18:42 UTC

[incubator-nlpcraft] branch NLPCRAFT-296 updated (1c9cbfd -> 6c8e6eb)

This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a change to branch NLPCRAFT-296
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git.


    from 1c9cbfd  WIP.
     new 679db5a  WIP.
     new 6c8e6eb  WIP.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../nlpcraft/examples/sql/db/SqlAccess.scala       |  1 -
 .../nlpcraft/examples/sql/db/SqlBuilder.scala      |  2 +-
 nlpcraft/pom.xml                                   |  8 +++----
 .../org/apache/nlpcraft/common/NCService.scala     |  4 +---
 .../common/nlp/numeric/NCNumericManager.scala      |  2 +-
 .../org/apache/nlpcraft/common/util/NCUtils.scala  |  2 +-
 .../apache/nlpcraft/model/intent/NCIdlStack.scala  |  2 +-
 .../nlpcraft/probe/mgrs/cmd/NCCommandManager.scala |  2 +-
 .../mgrs/nlp/enrichers/limit/NCLimitEnricher.scala |  4 ++--
 .../mgrs/nlp/enrichers/model/NCModelEnricher.scala |  2 +-
 .../probe/mgrs/sentence/NCSentenceManager.scala    | 10 +++++---
 .../coordinate/NCCoordinatesEnricher.scala         |  4 ++--
 .../enrichers/stopword/NCStopWordEnricher.scala    | 27 ++++++++++++++--------
 .../server/sugsyn/NCSuggestSynonymManager.scala    |  4 ++--
 .../nlpcraft/common/ascii/NCAsciiTableSpec.scala   |  7 +++---
 .../common/blowfish/NCBlowfishHasherSpec.scala     |  4 ++--
 .../nlpcraft/common/crypto/NCCipherSpec.scala      |  6 ++---
 .../nlpcraft/common/makro/NCMacroParserSpec.scala  |  6 ++---
 .../apache/nlpcraft/common/util/NCUtilsSpec.scala  |  8 +++----
 .../compiler/functions/NCIdlFunctionsDate.scala    |  1 +
 .../sqlgen/impl/NCSqlModelGeneratorImplSpec.scala  |  8 +++----
 .../enrichers/date/tools/NCDateGeneratorSpec.scala | 11 +++++----
 .../apache/nlpcraft/server/rest/NCRestSpec.scala   |  2 +-
 pom.xml                                            | 20 ++++++++--------
 24 files changed, 80 insertions(+), 67 deletions(-)

[incubator-nlpcraft] 02/02: WIP.

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a commit to branch NLPCRAFT-296
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git

commit 6c8e6ebde308152c0bf67b8c987b41eeed587710
Author: Aaron Radzinzski <ar...@datalingvo.com>
AuthorDate: Sun May 30 20:18:33 2021 -0700

    WIP.
---
 .../java/org/apache/nlpcraft/examples/sql/db/SqlAccess.scala  |  1 -
 .../java/org/apache/nlpcraft/examples/sql/db/SqlBuilder.scala |  2 +-
 .../src/main/scala/org/apache/nlpcraft/common/NCService.scala |  4 +---
 .../apache/nlpcraft/common/nlp/numeric/NCNumericManager.scala |  2 +-
 .../scala/org/apache/nlpcraft/model/intent/NCIdlStack.scala   |  2 +-
 .../probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala      |  4 ++--
 .../nlp/enrichers/coordinate/NCCoordinatesEnricher.scala      |  4 ++--
 .../server/nlp/enrichers/stopword/NCStopWordEnricher.scala    |  2 +-
 .../org/apache/nlpcraft/common/ascii/NCAsciiTableSpec.scala   |  6 +++---
 .../nlpcraft/common/blowfish/NCBlowfishHasherSpec.scala       |  4 ++--
 .../org/apache/nlpcraft/common/crypto/NCCipherSpec.scala      |  6 +++---
 .../org/apache/nlpcraft/common/makro/NCMacroParserSpec.scala  |  6 +++---
 .../scala/org/apache/nlpcraft/common/util/NCUtilsSpec.scala   |  8 ++++----
 .../model/tools/sqlgen/impl/NCSqlModelGeneratorImplSpec.scala |  8 ++++----
 .../server/nlp/enrichers/date/tools/NCDateGeneratorSpec.scala | 11 ++++++-----
 15 files changed, 34 insertions(+), 36 deletions(-)

diff --git a/nlpcraft-examples/sql/src/main/java/org/apache/nlpcraft/examples/sql/db/SqlAccess.scala b/nlpcraft-examples/sql/src/main/java/org/apache/nlpcraft/examples/sql/db/SqlAccess.scala
index f26e356..80a3847 100644
--- a/nlpcraft-examples/sql/src/main/java/org/apache/nlpcraft/examples/sql/db/SqlAccess.scala
+++ b/nlpcraft-examples/sql/src/main/java/org/apache/nlpcraft/examples/sql/db/SqlAccess.scala
@@ -24,7 +24,6 @@ import com.typesafe.scalalogging.LazyLogging
 import org.apache.nlpcraft.common.ascii.NCAsciiTable
 import org.h2.jdbc.JdbcSQLException
 import org.h2.jdbcx.JdbcDataSource
-import resource.managed
 
 /**
   * Ad-hoc querying for H2 Database. This is a simple, single thread implementation.
diff --git a/nlpcraft-examples/sql/src/main/java/org/apache/nlpcraft/examples/sql/db/SqlBuilder.scala b/nlpcraft-examples/sql/src/main/java/org/apache/nlpcraft/examples/sql/db/SqlBuilder.scala
index d5a9099..b30ffea 100644
--- a/nlpcraft-examples/sql/src/main/java/org/apache/nlpcraft/examples/sql/db/SqlBuilder.scala
+++ b/nlpcraft-examples/sql/src/main/java/org/apache/nlpcraft/examples/sql/db/SqlBuilder.scala
@@ -70,7 +70,7 @@ case class SqlBuilder(schema: NCSqlSchema) extends LazyLogging {
             var found = false
 
             while (queue.nonEmpty && !found) {
-                val parent = queue.dequeue
+                val parent = queue.dequeue()
                 val children = allNeighbors(parent)
 
                 if (children.contains(to)) {
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/NCService.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/NCService.scala
index fbd47db..ddba511 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/NCService.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/NCService.scala
@@ -22,8 +22,6 @@ import io.opencensus.trace.Span
 import org.apache.nlpcraft.common.opencensus.NCOpenCensusTrace
 import org.apache.nlpcraft.common.ansi.NCAnsi._
 
-import scala.compat.Platform._
-
 /**
   * Basic abstract class defining internal service/manager/component lifecycle. Components that
   * extend this class are typically called 'managers'.
@@ -121,7 +119,7 @@ abstract class NCService extends LazyLogging with NCOpenCensusTrace {
             "state" -> "started"
         )
 
-        val dur = s"$ansiGreenFg[${currentTime - timeStampMs}ms]$ansiReset"
+        val dur = s"$ansiGreenFg[${U.now() - timeStampMs}ms]$ansiReset"
 
         logger.info(s"$name started $dur")
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/numeric/NCNumericManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/numeric/NCNumericManager.scala
index d759796..e20a18b 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/numeric/NCNumericManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/numeric/NCNumericManager.scala
@@ -363,7 +363,7 @@ object NCNumericManager extends NCService {
             val nums = grps.flatMap(seq => {
                 def mkNums(v: Double, isFractional: Boolean): Seq[NCNumeric] = {
                     // Units synonyms are not stemmed.
-                    Range.inclusive(1, maxSynWords).reverse.toStream.flatMap(i => {
+                    Range.inclusive(1, maxSynWords).reverse.to(LazyList).flatMap(i => {
                         val afterNum = ns.slice(seq.last.index + 1, seq.last.index + i + 1)
                         
                         if (afterNum.nonEmpty && !afterNum.exists(cds.contains)) {
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCIdlStack.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCIdlStack.scala
index 2fdc4a9..1f93e5e 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCIdlStack.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCIdlStack.scala
@@ -41,7 +41,7 @@ trait NCIdlStackType extends (() => NCIdlStackItem)
 /**
   *
   */
-class NCIdlStack extends mutable.ArrayStack[NCIdlStackType] {
+class NCIdlStack extends mutable.Stack[NCIdlStackType] {
     /**
       * Special marker for stack frames.
       */
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala
index 9e54a6c..7bad3c5 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala
@@ -349,7 +349,7 @@ object NCLimitEnricher extends NCProbeEnricher {
 
             // Reference should be last.
             if (refCands.nonEmpty && refCands.last.index == toks.last.index && cmnRefNotes.nonEmpty)
-                Stream(try0(matchCands), try0(matchCands.filter(!_.isStopWord))).flatten.headOption
+                LazyList(try0(matchCands), try0(matchCands.filter(!_.isStopWord))).flatten.headOption
             else
                 None
         }
@@ -360,7 +360,7 @@ object NCLimitEnricher extends NCProbeEnricher {
         def f(seq: => Seq[NCNlpSentenceToken]): Seq[NCNlpSentenceToken] =
             seq.filter(_.exists(n => isUserNotValue(n) && n.tokenIndexes.head >= i1 && n.tokenIndexes.last <= i2))
 
-        Stream(tryCandidates(f(toks)), tryCandidates(f(toks.dropWhile(tech.contains)))).flatten.headOption
+        LazyList(tryCandidates(f(toks)), tryCandidates(f(toks.dropWhile(tech.contains)))).flatten.headOption
     }
 
     /**
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/coordinate/NCCoordinatesEnricher.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/coordinate/NCCoordinatesEnricher.scala
index ad94117..4ccf679 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/coordinate/NCCoordinatesEnricher.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/coordinate/NCCoordinatesEnricher.scala
@@ -130,7 +130,7 @@ object NCCoordinatesEnricher extends NCServerEnricher {
         if (toks.nonEmpty) {
             val from = toks.head.index
 
-            markers.toStream.
+            markers.to(LazyList).
                 flatMap(m => get(
                     ns,
                     from,
@@ -155,7 +155,7 @@ object NCCoordinatesEnricher extends NCServerEnricher {
         if (toks.nonEmpty) {
             val to = toks.last.index + 1
 
-            markers.toStream.
+            markers.to(LazyList).
                 flatMap(m => get(
                     ns,
                     m.last.index + 1,
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/stopword/NCStopWordEnricher.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/stopword/NCStopWordEnricher.scala
index 725a737..e65b263 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/stopword/NCStopWordEnricher.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/stopword/NCStopWordEnricher.scala
@@ -239,7 +239,7 @@ object NCStopWordEnricher extends NCServerEnricher {
             def add(f: WordForm, mkT: Unit => T, isExc: Boolean): Unit = {
                 val tuple: (Key, T) = (isExc, f) -> mkT(())
 
-                m += tuple._1 → tuple._2
+                m += tuple._1 -> tuple._2
             }
 
             WordForm.values.foreach(f => {
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/common/ascii/NCAsciiTableSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/common/ascii/NCAsciiTableSpec.scala
index f914eaa..3fbb53f 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/common/ascii/NCAsciiTableSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/common/ascii/NCAsciiTableSpec.scala
@@ -26,7 +26,7 @@ import org.junit.jupiter.api.Test
  */
 class NCAsciiTableSpec {
     @Test
-    def test() {
+    def test(): Unit = {
         val t = NCAsciiTable()
         
         t.defaultHeaderStyle = "leftPad: 10, rightPad: 5"
@@ -56,7 +56,7 @@ class NCAsciiTableSpec {
     }
 
     @Test
-    def testWithSequenceHeader() {
+    def testWithSequenceHeader(): Unit = {
         val t = NCAsciiTable()
         
         t.defaultHeaderStyle = "leftPad: 10, rightPad: 5"
@@ -73,7 +73,7 @@ class NCAsciiTableSpec {
     }
 
     @Test
-    def testWithVeryBigTable() {
+    def testWithVeryBigTable(): Unit = {
         val NUM = 100
 
         val start = U.now()
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/common/blowfish/NCBlowfishHasherSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/common/blowfish/NCBlowfishHasherSpec.scala
index 440ac62..001a9ae 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/common/blowfish/NCBlowfishHasherSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/common/blowfish/NCBlowfishHasherSpec.scala
@@ -21,11 +21,11 @@ import org.junit.jupiter.api.Assertions.assertTrue
 import org.junit.jupiter.api.Test
 
 /**
-  * Tests for Blowfish hasher.
+  * Tests for Blowfish hasLazyListher.
   */
 class NCBlowfishHasherSpec {
     @Test
-    def testWithSequenceHeader() {
+    def testWithSequenceHeader(): Unit = {
         val email = "dev@nlpcraft.org"
         val passwd = "test"
         
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/common/crypto/NCCipherSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/common/crypto/NCCipherSpec.scala
index ce14aad..91f26ae 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/common/crypto/NCCipherSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/common/crypto/NCCipherSpec.scala
@@ -29,7 +29,7 @@ class NCCipherSpec  {
     private final val IN = "abcdefghijklmnopqrstuvwxyz0123456789"
 
     @Test
-    def testEncryptDecrypt() {
+    def testEncryptDecrypt(): Unit = {
         val s1 = NCCipher.encrypt(IN)
         val s2 = NCCipher.decrypt(s1)
 
@@ -37,7 +37,7 @@ class NCCipherSpec  {
     }
 
     @Test
-    def testDifference() {
+    def testDifference(): Unit = {
         val s1 = NCCipher.encrypt(IN)
         val s2 = NCCipher.encrypt(IN)
         val s3 = NCCipher.encrypt(IN)
@@ -55,7 +55,7 @@ class NCCipherSpec  {
     }
 
     @Test
-    def testCorrectness() {
+    def testCorrectness(): Unit = {
         val buf = new StringBuilder
         
         // Max long string.
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/common/makro/NCMacroParserSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/common/makro/NCMacroParserSpec.scala
index 3364cef..b6ffe2b 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/common/makro/NCMacroParserSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/common/makro/NCMacroParserSpec.scala
@@ -70,7 +70,7 @@ class NCMacroParserSpec  {
     }
 
     // @Test
-    def testPerformance() {
+    def testPerformance(): Unit = {
         val start = U.now()
 
         val N = 50000
@@ -101,7 +101,7 @@ class NCMacroParserSpec  {
     }
 
     @Test
-    def testExpand() {
+    def testExpand(): Unit = {
         // Make sure we can parse these.
         parser.expand("<OF>")
         parser.expand("<QTY>")
@@ -153,7 +153,7 @@ class NCMacroParserSpec  {
     }
 
     @Test
-    def testLimit() {
+    def testLimit(): Unit = {
         checkError("<METRICS> <USER> <BY> <WEBSITE> <BY> <SES> <BY> <METRICS> <BY> <USER> <BY> <METRICS>")
     }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/common/util/NCUtilsSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/common/util/NCUtilsSpec.scala
index 4221b0f..dd80f62 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/common/util/NCUtilsSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/common/util/NCUtilsSpec.scala
@@ -26,7 +26,7 @@ import org.junit.jupiter.api.Test
  */
 class NCUtilsSpec  {
     @Test
-    def testInflateDeflate() {
+    def testInflateDeflate(): Unit = {
         val rawStr = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. " +
             "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when " +
             "an unknown printer took a galley of type and scrambled it to make a type specimen book. " +
@@ -52,21 +52,21 @@ class NCUtilsSpec  {
     }
 
     @Test
-    def testGetDups() {
+    def testGetDups(): Unit = {
         assertTrue(U.getDups(Seq("a", "b", "a")) == Set("a"))
         assertTrue(U.getDups(Seq("a", "a", "a", "b", "a")) == Set("a"))
         assertTrue(U.getDups(Seq("a", "d", "c", "b", "e")) == Set())
     }
 
     @Test
-    def testToFirstLastName() {
+    def testToFirstLastName(): Unit = {
         assertTrue(U.toFirstLastName("A BbbBB") == ("A", "Bbbbb"))
         assertTrue(U.toFirstLastName("aBC BbbBB CCC") == ("Abc", "Bbbbb ccc"))
         assertTrue(U.toFirstLastName("abc b C C C") == ("Abc", "B c c c"))
     }
 
     @Test
-    def testWorkWithoutUnnecessaryLogging() {
+    def testWorkWithoutUnnecessaryLogging(): Unit = {
         val t = new Thread() {
             override def run(): Unit = {
                 while (!isInterrupted) {
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/tools/sqlgen/impl/NCSqlModelGeneratorImplSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/tools/sqlgen/impl/NCSqlModelGeneratorImplSpec.scala
index 60c92c3..cb99ffc 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/tools/sqlgen/impl/NCSqlModelGeneratorImplSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/tools/sqlgen/impl/NCSqlModelGeneratorImplSpec.scala
@@ -76,7 +76,7 @@ class NCSqlModelGeneratorImplSpec {
         }).mkString(" ")
 
     @Test
-    def testRemovePrefix() {
+    def testRemovePrefix(): Unit = {
         val fun1 = mkPrefixFun("tbl_, col_")
         val fun2 = mkPrefixFun("")
         val fun3 = mkPrefixFun("tbl_tbl_, col_")
@@ -90,7 +90,7 @@ class NCSqlModelGeneratorImplSpec {
     }
 
     @Test
-    def testRemoveSuffix() {
+    def testRemoveSuffix(): Unit = {
         val fun1 = mkSuffixFun("_tmp, _old")
         val fun2 = mkSuffixFun("")
         val fun3 = mkSuffixFun("_tmp_tmp")
@@ -104,14 +104,14 @@ class NCSqlModelGeneratorImplSpec {
     }
 
     @Test
-    def testSubstituteMacros() {
+    def testSubstituteMacros(): Unit = {
         assertTrue(substituteMacros("a id") == "a <ID>")
         assertTrue(substituteMacros("a     id   ") == "a <ID>")
         assertTrue(substituteMacros("id") == "<ID>")
     }
 
     @Test
-    def testRemoveSequentialDups() {
+    def testRemoveSequentialDups(): Unit = {
         assertTrue(removeSeqDups("a a b b") == "a b")
         assertTrue(removeSeqDups("aa b b") == "aa b")
         assertTrue(removeSeqDups("aa     b    b") == "aa b")
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/nlp/enrichers/date/tools/NCDateGeneratorSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/nlp/enrichers/date/tools/NCDateGeneratorSpec.scala
index d4d833f..92d54b5 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/nlp/enrichers/date/tools/NCDateGeneratorSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/nlp/enrichers/date/tools/NCDateGeneratorSpec.scala
@@ -17,6 +17,7 @@
 
 package org.apache.nlpcraft.server.nlp.enrichers.date.tools
 
+import org.apache.nlpcraft.common._
 import org.apache.nlpcraft.common.ascii.NCAsciiTable
 import org.apache.nlpcraft.server.nlp.enrichers.date.NCDateConstants._
 import org.apache.nlpcraft.server.nlp.enrichers.date.NCDateFormatType._
@@ -38,8 +39,8 @@ import scala.language.implicitConversions
 class NCDateGeneratorSpec  {
     private def print(
         f: LHM[String, String] => Unit, cnt: Int = 500, asc: Boolean = true, keys2Check: Option[Seq[String]] = None
-    ) {
-        val base = scala.compat.Platform.currentTime
+    ): Unit = {
+        val base = U.now()
 
         val map = new LHM[String, String]
 
@@ -70,7 +71,7 @@ class NCDateGeneratorSpec  {
         d: Date,
         fs: Seq[SimpleDateFormat],
         m: Map[String, Seq[SimpleDateFormat]],
-        withDup: Boolean) {
+        withDup: Boolean): Unit = {
         val res = fs.map(_.format(d)) ++ NCDateGenerator.format(d, m)
 
         res.foreach(println(_))
@@ -317,7 +318,7 @@ class NCDateGeneratorSpec  {
 
     @Test
     def testLastDay(): Unit = {
-        val date = scala.compat.Platform.currentTime
+        val date = U.now()
 
         def print(f: String): Unit = {
             val res = NCDateParser.calculatePart(f, date)
@@ -341,7 +342,7 @@ class NCDateGeneratorSpec  {
 
     @Test
     def testParse(): Unit = {
-        val date = scala.compat.Platform.currentTime
+        val date = U.now()
 
         val f = "m, $dm, 1dw, w1"
 

[incubator-nlpcraft] 01/02: WIP.

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a commit to branch NLPCRAFT-296
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git

commit 679db5af91174d3e2a454df8cb1c9533a530c284
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Sun May 30 14:14:41 2021 +0300

    WIP.
---
 nlpcraft/pom.xml                                   |  8 +++----
 .../org/apache/nlpcraft/common/util/NCUtils.scala  |  2 +-
 .../nlpcraft/probe/mgrs/cmd/NCCommandManager.scala |  2 +-
 .../mgrs/nlp/enrichers/model/NCModelEnricher.scala |  2 +-
 .../probe/mgrs/sentence/NCSentenceManager.scala    | 10 +++++---
 .../enrichers/stopword/NCStopWordEnricher.scala    | 27 ++++++++++++++--------
 .../server/sugsyn/NCSuggestSynonymManager.scala    |  4 ++--
 .../nlpcraft/common/ascii/NCAsciiTableSpec.scala   |  1 +
 .../compiler/functions/NCIdlFunctionsDate.scala    |  1 +
 .../apache/nlpcraft/server/rest/NCRestSpec.scala   |  2 +-
 pom.xml                                            | 20 ++++++++--------
 11 files changed, 47 insertions(+), 32 deletions(-)

diff --git a/nlpcraft/pom.xml b/nlpcraft/pom.xml
index 779a4ba..4d8c292 100644
--- a/nlpcraft/pom.xml
+++ b/nlpcraft/pom.xml
@@ -190,15 +190,15 @@
         </dependency>
         <dependency>
             <groupId>com.typesafe.akka</groupId>
-            <artifactId>akka-http_2.12</artifactId>
+            <artifactId>akka-http_2.13</artifactId>
         </dependency>
         <dependency>
             <groupId>com.typesafe.akka</groupId>
-            <artifactId>akka-stream_2.12</artifactId>
+            <artifactId>akka-stream_2.13</artifactId>
         </dependency>
         <dependency>
             <groupId>com.typesafe.akka</groupId>
-            <artifactId>akka-http-spray-json_2.12</artifactId>
+            <artifactId>akka-http-spray-json_2.13</artifactId>
         </dependency>
         <dependency>
             <groupId>com.fasterxml.jackson.dataformat</groupId>
@@ -210,7 +210,7 @@
         </dependency>
         <dependency>
             <groupId>com.fasterxml.jackson.module</groupId>
-            <artifactId>jackson-module-scala_2.12</artifactId>
+            <artifactId>jackson-module-scala_2.13</artifactId>
         </dependency>
         <dependency>
             <groupId>com.google.cloud</groupId>
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
index 3e7b046..c698e10 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
@@ -1016,7 +1016,7 @@ object NCUtils extends LazyLogging {
       */
     def asFuture[T](
         body: Unit => T,
-        onFailure: Throwable => Unit = _ => Unit,
+        onFailure: Throwable => Unit = _ => (),
         onSuccess: T => Unit = (_: T) => ())(implicit ec: ExecutionContext): Future[T] = {
         val fut = Future {
             body(())
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/cmd/NCCommandManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/cmd/NCCommandManager.scala
index 8a88008..1f96350 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/cmd/NCCommandManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/cmd/NCCommandManager.scala
@@ -101,7 +101,7 @@ object NCCommandManager extends NCService {
                             txt = msg.data[String]("txt"),
                             nlpSens = msg.data[JList[NCNlpSentence]]("nlpSens").asScala,
                             usrId = msg.data[Long]("userId"),
-                            senMeta = msg.data[java.util.Map[String, JSerializable]]("senMeta").asScala,
+                            senMeta = msg.data[java.util.Map[String, JSerializable]]("senMeta").asScala.toMap,
                             mdlId = msg.data[String]("mdlId"),
                             enableLog = msg.data[Boolean]("enableLog"),
                             span
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCModelEnricher.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCModelEnricher.scala
index 6b92656..1b10224 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCModelEnricher.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCModelEnricher.scala
@@ -286,7 +286,7 @@ object NCModelEnricher extends NCProbeEnricher {
                                 elem = mdl.elements.getOrElse(elemId, throw new NCE(s"Custom model parser returned unknown element ID: $elemId")),
                                 toks = matchedToks,
                                 direct = true,
-                                metaOpt = Some(e.getMetadata.asScala)
+                                metaOpt = Some(e.getMetadata.asScala.toMap)
                             )
                     })
             }
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/sentence/NCSentenceManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/sentence/NCSentenceManager.scala
index 4c49d1d..63913ac 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/sentence/NCSentenceManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/sentence/NCSentenceManager.scala
@@ -28,6 +28,7 @@ import java.io.{Serializable => JSerializable}
 import java.util
 import java.util.{List => JList}
 import scala.collection.mutable
+import scala.collection.parallel.CollectionConverters.ImmutableIterableIsParallelizable
 import scala.jdk.CollectionConverters.{ListHasAsScala, SeqHasAsJava, SetHasAsJava}
 import scala.language.implicitConversions
 
@@ -655,7 +656,7 @@ object NCSentenceManager extends NCService {
                 distinct
 
         // Optimization. Deletes all wholly swallowed notes.
-        val links = getLinks(sen.flatten)
+        val links = getLinks(sen.tokens.flatMap(p => p))
 
         val swallowed =
             delCombs.
@@ -690,13 +691,16 @@ object NCSentenceManager extends NCService {
                         groupBy { case (idx, _) => idx }.
                         map { case (_, seq) => seq.map { case (_, note) => note }.toSet }.
                         toSeq.sortBy(-_.size)
+                        
+                def findCombinations(): Seq[Seq[NCNlpSentenceNote]] =
+                    NCSentenceHelper.findCombinations(toksByIdx.map(_.asJava).asJava, pool).asScala.map(_.asScala.toSeq)
 
                 val seqSens =
                     combCache.
                         getOrElseUpdate(sen.srvReqId, mutable.HashMap.empty[CacheKey, CacheValue]).
                         getOrElseUpdate(
                             toksByIdx,
-                            NCSentenceHelper.findCombinations(toksByIdx.map(_.asJava).asJava, pool).asScala.map(_.asScala)
+                            findCombinations()
                         ).par.
                         flatMap(delComb => {
                             val nsClone = sen.clone()
@@ -721,7 +725,7 @@ object NCSentenceManager extends NCService {
 
                     Holder(
                         // We have to delete some keys to have possibility to compare sentences.
-                        notes.map(_.clone().filter { case (name, _) => name != "direct" }),
+                        notes.map(_.clone().filter { case (name, _) => name != "direct" }).toSeq,
                         sen,
                         notes.filter(_.isNlp).map(p => if (p.isDirect) 0 else 1).sum
                     )
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/stopword/NCStopWordEnricher.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/stopword/NCStopWordEnricher.scala
index 0762677..725a737 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/stopword/NCStopWordEnricher.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/stopword/NCStopWordEnricher.scala
@@ -232,15 +232,24 @@ object NCStopWordEnricher extends NCServerEnricher {
                 }
         }
 
-        def mkEntry[T](f: WordForm, mkT: Unit => T, isExc: Boolean):((Boolean, WordForm), T) = (isExc, f) -> mkT(())
-        def mkMap[T](mkT: Unit => T): Map[(Boolean, WordForm), T] =
-            WordForm
-                .values
-                .toSet
-                .flatMap(f => Map(
-                    mkEntry(f, mkT, isExc = true),
-                    mkEntry(f, mkT, isExc = false)
-                )).toMap
+        type Key = (Boolean, WordForm)
+        def mkMap[T](mkT: Unit => T): Map[Key, T] = {
+            val m = mutable.Map.empty[Key, T]
+
+            def add(f: WordForm, mkT: Unit => T, isExc: Boolean): Unit = {
+                val tuple: (Key, T) = (isExc, f) -> mkT(())
+
+                m += tuple._1 → tuple._2
+            }
+
+            WordForm.values.foreach(f => {
+                add(f, mkT, isExc = true)
+                add(f, mkT, isExc = false)
+
+            })
+
+            m.toMap
+        }
 
         // Prepares collections.
         val mHash = mkMap(_ => new Condition[Word]())
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala
index cd3777b..47f8171 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala
@@ -38,7 +38,7 @@ import java.util.concurrent._
 import java.util.concurrent.atomic.{AtomicInteger, AtomicReference}
 import scala.collection.mutable
 import scala.concurrent.{ExecutionContext, Future, Promise}
-import scala.jdk.CollectionConverters.{ListHasAsScala, MapHasAsScala, SeqHasAsJava}
+import scala.jdk.CollectionConverters._
 import scala.util.{Failure, Success}
 
 /**
@@ -411,7 +411,7 @@ object NCSuggestSynonymManager extends NCService {
 
                                                 m
                                             }).asJava
-                                    }.asJava
+                                    }.toMap.asJava
 
                                 promise.success(
                                     NCSuggestSynonymResult(
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/common/ascii/NCAsciiTableSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/common/ascii/NCAsciiTableSpec.scala
index a3bf00f..f914eaa 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/common/ascii/NCAsciiTableSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/common/ascii/NCAsciiTableSpec.scala
@@ -17,6 +17,7 @@
 
 package org.apache.nlpcraft.common.ascii
 
+import org.apache.nlpcraft.common.U
 import org.apache.nlpcraft.common.ansi.NCAnsi._
 import org.junit.jupiter.api.Test
 
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala
index 0bac73e..97a149b 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala
@@ -17,6 +17,7 @@
 
 package org.apache.nlpcraft.model.intent.idl.compiler.functions
 
+import org.apache.nlpcraft.common.U
 import org.junit.jupiter.api.Test
 
 import java.time.temporal.IsoFields
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestSpec.scala
index 948e5ee..03bf811 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestSpec.scala
@@ -130,7 +130,7 @@ import org.apache.nlpcraft.server.rest.NCRestSpec._
 class NCRestSpec extends NCTestContext {
     type ResponseContent = java.util.Map[String, Object]
     type ResponseList = JList[ResponseContent]
-    type JList[T] = JList[T]
+    type JList[T] = java.util.List[T]
 
     protected var tkn: String = _
     /**
diff --git a/pom.xml b/pom.xml
index bf77506..be9d907 100644
--- a/pom.xml
+++ b/pom.xml
@@ -128,9 +128,9 @@
         <maven.clean.plugin.ver>3.1.0</maven.clean.plugin.ver>
         <apache.rat.plugin.ver>0.13</apache.rat.plugin.ver>
         <org.antlr4.ver>4.9</org.antlr4.ver>
-        <akka.http.2.12.ver>10.2.0</akka.http.2.12.ver>
-        <akka.stream.2.12.ver>2.6.8</akka.stream.2.12.ver>
-        <akka.http.spray.json.2.12.ver>10.2.0</akka.http.spray.json.2.12.ver>
+        <akka.http.2.13.ver>10.2.4</akka.http.2.13.ver>
+        <akka.stream.2.13.ver>2.6.14</akka.stream.2.13.ver>
+        <akka.http.spray.json.2.13.ver>10.2.4</akka.http.spray.json.2.13.ver>
         <google.guava.ver>29.0-jre</google.guava.ver>
         <diff.utils.ver>4.7</diff.utils.ver>
         <vertical.blank.ver>1.0.1</vertical.blank.ver>
@@ -409,20 +409,20 @@
 
             <dependency>
                 <groupId>com.typesafe.akka</groupId>
-                <artifactId>akka-http_2.12</artifactId>
-                <version>${akka.http.2.12.ver}</version>
+                <artifactId>akka-http_2.13</artifactId>
+                <version>${akka.http.2.13.ver}</version>
             </dependency>
 
             <dependency>
                 <groupId>com.typesafe.akka</groupId>
-                <artifactId>akka-stream_2.12</artifactId>
-                <version>${akka.stream.2.12.ver}</version>
+                <artifactId>akka-stream_2.13</artifactId>
+                <version>${akka.stream.2.13.ver}</version>
             </dependency>
 
             <dependency>
                 <groupId>com.typesafe.akka</groupId>
-                <artifactId>akka-http-spray-json_2.12</artifactId>
-                <version>${akka.http.spray.json.2.12.ver}</version>
+                <artifactId>akka-http-spray-json_2.13</artifactId>
+                <version>${akka.http.spray.json.2.13.ver}</version>
             </dependency>
 
             <dependency>
@@ -439,7 +439,7 @@
 
             <dependency>
                 <groupId>com.fasterxml.jackson.module</groupId>
-                <artifactId>jackson-module-scala_2.12</artifactId>
+                <artifactId>jackson-module-scala_2.13</artifactId>
                 <version>${jackson.ver}</version>
             </dependency>