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 <[email protected]> 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 = "[email protected]" 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"
