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

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


The following commit(s) were added to refs/heads/scala-2.13 by this push:
     new f7f1340  WIP.
f7f1340 is described below

commit f7f13400974aab1f3b2f06e438b60faa3408329d
Author: Aaron Radzinzski <[email protected]>
AuthorDate: Tue May 18 17:26:08 2021 -0700

    WIP.
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 71 ++++++++++------------
 .../server/nlp/enrichers/date/NCDateEnricher.scala | 28 ++++-----
 .../enrichers/stopword/NCStopWordEnricher.scala    | 13 ++--
 3 files changed, 52 insertions(+), 60 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
index 01fda99..da53e88 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
@@ -55,10 +55,9 @@ import org.jline.utils.InfoCmp.Capability
 import org.apache.nlpcraft.model.tools.cmdline.NCCliRestSpec._
 import org.apache.nlpcraft.model.tools.cmdline.NCCliCommands._
 
-import scala.collection.JavaConverters._
 import scala.collection.mutable
-import scala.compat.Platform.currentTime
 import scala.compat.java8.OptionConverters._
+import scala.jdk.CollectionConverters._
 import scala.util.{Try, Using}
 import scala.util.control.Breaks.{break, breakable}
 import scala.util.control.Exception.ignoring
@@ -171,7 +170,6 @@ object NCCli extends NCCliBase {
      * @param args
      * @param id
      * @param dflt
-     * @throws
      * @return
      */
     @throws[InvalidParameter]
@@ -194,7 +192,6 @@ object NCCli extends NCCliBase {
      * @param args
      * @param id
      * @param dflt
-     * @throws
      * @return
      */
     @throws[InvalidParameter]
@@ -346,7 +343,7 @@ object NCCli extends NCCliBase {
      *
      */
     private def cleanUpTempFiles(): Unit = {
-        val tstamp = currentTime - 1000 * 60 * 60 * 24 * 2 // 2 days ago.
+        val tstamp = System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 2 // 2 
days ago.
 
         val files = new File(SystemUtils.getUserHome, ".nlpcraft").listFiles()
         
@@ -405,7 +402,7 @@ object NCCli extends NCCliBase {
             case None => ()
         }
 
-        val logTstamp = currentTime
+        val logTstamp = System.currentTimeMillis()
 
         // Server log redirect.
         val output = new File(SystemUtils.getUserHome, 
s".nlpcraft/server_log_$logTstamp.txt")
@@ -432,7 +429,7 @@ object NCCli extends NCCliBase {
         if (igniteCfgPath != null)
             srvArgs += s"-igniteConfig=$igniteCfgPath"
 
-        val srvPb = new ProcessBuilder(srvArgs.asJava)
+        val srvPb = new ProcessBuilder(srvArgs.toSeq.asJava)
 
         srvPb.directory(new File(USR_WORK_DIR))
         srvPb.redirectErrorStream(true)
@@ -518,9 +515,9 @@ object NCCli extends NCCliBase {
 
                 var beacon: NCCliServerBeacon = null
                 var online = false
-                val endOfWait = currentTime + timeoutMins.mins
+                val endOfWait = System.currentTimeMillis() + timeoutMins.mins
 
-                while (currentTime < endOfWait && !online && 
ProcessHandle.of(srvPid).isPresent) {
+                while (System.currentTimeMillis() < endOfWait && !online && 
ProcessHandle.of(srvPid).isPresent) {
                     if (progressBar.completed) {
                         // First, load the beacon, if any.
                         if (beacon == null)
@@ -538,7 +535,7 @@ object NCCli extends NCCliBase {
                 tailer.stop()
                 progressBar.stop()
 
-                if (!online && currentTime >= endOfWait) // Timed out - 
attempt to kill the timed out process...
+                if (!online && System.currentTimeMillis() >= endOfWait) // 
Timed out - attempt to kill the timed out process...
                     ProcessHandle.of(srvPid).asScala match {
                         case Some(ph) =>
                             if (ph.destroy())
@@ -662,7 +659,7 @@ object NCCli extends NCCliBase {
             case None => Seq("-ea", "-Xms1024m")
         }
 
-        val logTstamp = currentTime
+        val logTstamp = System.currentTimeMillis()
 
         // Server log redirect.
         val output = new File(SystemUtils.getUserHome, 
s".nlpcraft/probe_log_$logTstamp.txt")
@@ -777,9 +774,9 @@ object NCCli extends NCCliBase {
                 )
 
                 var beacon: NCCliProbeBeacon = null
-                val endOfWait = currentTime + timeoutMins.mins
+                val endOfWait = System.currentTimeMillis() + timeoutMins.mins
 
-                while (currentTime < endOfWait && beacon == null && 
ProcessHandle.of(prbPid).isPresent) {
+                while (System.currentTimeMillis() < endOfWait && beacon == 
null && ProcessHandle.of(prbPid).isPresent) {
                     if (progressBar.completed) {
                         // Load the beacon, if any.
                         if (beacon == null)
@@ -793,7 +790,7 @@ object NCCli extends NCCliBase {
                 tailer.stop()
                 progressBar.stop()
 
-                if (currentTime >= endOfWait)
+                if (System.currentTimeMillis() >= endOfWait)
                     ProcessHandle.of(prbPid).asScala match {
                         case Some(ph) =>
                             if (ph.destroy())
@@ -927,14 +924,14 @@ object NCCli extends NCCliBase {
 
             spinner.start()
 
-            val startMs = currentTime
+            val startMs = System.currentTimeMillis()
 
             try
                 restHealth(endpoint) match {
                     case 200 =>
                         spinner.stop()
 
-                        logln(g("OK") + " " + c(s"[${currentTime - 
startMs}ms]"))
+                        logln(g("OK") + " " + 
c(s"[${System.currentTimeMillis() - startMs}ms]"))
 
                     case code: Int =>
                         spinner.stop()
@@ -969,17 +966,15 @@ object NCCli extends NCCliBase {
      */
     private def loadServerBeacon(autoSignIn: Boolean = false): 
Option[NCCliServerBeacon] = {
         val beaconOpt = try {
-            val beacon = (
-                Using.resource(
-                    new ObjectInputStream(
-                        new FileInputStream(
-                            new File(SystemUtils.getUserHome, SRV_BEACON_PATH)
-                        )
+            val beacon = Using.resource(
+                new ObjectInputStream(
+                    new FileInputStream(
+                        new File(SystemUtils.getUserHome, SRV_BEACON_PATH)
                     )
-                ) {
-                    _.readObject()
-                }
-            )
+                )
+            ) {
+                _.readObject()
+            }
             .asInstanceOf[NCCliServerBeacon]
 
             ProcessHandle.of(beacon.pid).asScala match {
@@ -1073,17 +1068,15 @@ object NCCli extends NCCliBase {
      */
     private def loadProbeBeacon(): Option[NCCliProbeBeacon] = {
         val beaconOpt = try {
-            val beacon = (
-                Using.resource(
-                    new ObjectInputStream(
-                        new FileInputStream(
-                            new File(SystemUtils.getUserHome, PRB_BEACON_PATH)
-                        )
+            val beacon = Using.resource(
+                new ObjectInputStream(
+                    new FileInputStream(
+                        new File(SystemUtils.getUserHome, PRB_BEACON_PATH)
                     )
-                ) {
-                    _.readObject()
-                }
-            )
+                )
+            ) {
+                _.readObject()
+            }
             .asInstanceOf[NCCliProbeBeacon]
 
             ProcessHandle.of(beacon.pid).asScala match {
@@ -1301,7 +1294,7 @@ object NCCli extends NCCliBase {
                 }
             }
 
-            lines
+            lines.toSeq
         }
 
         def helpHelp(): Unit =
@@ -1491,7 +1484,7 @@ object NCCli extends NCCliBase {
                     s"  ${c("guid")}: ${probe.probeGuid}",
                     s"  ${c("tok")}: ${probe.probeToken}"
                 ),
-                DurationFormatUtils.formatDurationHMS(currentTime - 
probe.startTstamp),
+                
DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - 
probe.startTstamp),
                 Seq(
                     s"${probe.hostName} (${probe.hostAddr})",
                     s"${probe.osName} ver. ${probe.osVersion}"
@@ -2803,7 +2796,7 @@ object NCCli extends NCCliBase {
         if (buf.nonEmpty)
             lines += buf.toString()
 
-        lines.map(_.strip)
+        lines.map(_.strip).toSeq
     }
 
     /**
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/date/NCDateEnricher.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/date/NCDateEnricher.scala
index b729d48..b4f9440 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/date/NCDateEnricher.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/date/NCDateEnricher.scala
@@ -19,7 +19,7 @@ package org.apache.nlpcraft.server.nlp.enrichers.date
 
 import io.opencensus.trace.Span
 import org.apache.nlpcraft.common.config.NCConfigurable
-import org.apache.nlpcraft.common.nlp.{NCNlpSentence ⇒ Sentence, 
NCNlpSentenceNote ⇒ Note, NCNlpSentenceToken ⇒ Token}
+import org.apache.nlpcraft.common.nlp.{NCNlpSentence => Sentence, 
NCNlpSentenceNote => Note, NCNlpSentenceToken => Token}
 import org.apache.nlpcraft.common.pool.NCThreadPoolManager
 import org.apache.nlpcraft.common.{NCService, _}
 import org.apache.nlpcraft.server.nlp.enrichers.NCServerEnricher
@@ -228,7 +228,7 @@ object NCDateEnricher extends NCServerEnricher {
                 for (pair <- dates.sliding(2) if !pair.exists(_.isProcessed)) {
                     val from = pair.head
                     val to = pair.last
-                    val between = ns.slice(from.tokens.last.index + 1, 
to.tokens.head.index)
+                    val between = ns.slice(from.tokens.last.index + 1, 
to.tokens.head.index).toSeq
                     
                     if (between.nonEmpty && isDash(between)) {
                         mark(from, to)
@@ -236,7 +236,7 @@ object NCDateEnricher extends NCServerEnricher {
                     }
                 }
                 
-                buf
+                buf.toSeq
             }
     
             def findSimples[T](ps: Seq[P], mkHolder: (F, P) => T): Seq[T] = {
@@ -251,7 +251,7 @@ object NCDateEnricher extends NCServerEnricher {
                         case None => None
                     }
                 
-                buf
+                buf.toSeq
             }
     
             def withBefore(tokens: Seq[Token], lenBefore: Int) =
@@ -270,7 +270,7 @@ object NCDateEnricher extends NCServerEnricher {
                 val body = s"${r.from.body}:${r.to.body}"
                 val toks = withBefore(r.from.tokens, r.fromLength) ++ 
withBefore(r.to.tokens, r.toLength)
                 
-                addNote(body, r.fromInclusive, r.toInclusive, toks, base)
+                addNote(body, r.fromInclusive, r.toInclusive, toks.toSeq, base)
             }
             
             // From, to - simple ranges.
@@ -281,7 +281,7 @@ object NCDateEnricher extends NCServerEnricher {
             for (r <- simpleRanges) {
                 val b = r.function.body
                 val body = if (r.isFromType) s"$b:" else s":$b"
-                val toks = withBefore(r.function.tokens, r.length)
+                val toks = withBefore(r.function.tokens, r.length).toSeq
                 
                 addNote(body, r.inclusive, r.inclusive, toks, base)
             }
@@ -298,7 +298,7 @@ object NCDateEnricher extends NCServerEnricher {
             
             for (d <- simpleDates) {
                 val body = d.function.body
-                val toks = withBefore(d.function.tokens, d.length)
+                val toks = withBefore(d.function.tokens, d.length).toSeq
             
                 addNote(body, fromIncl = true, toIncl = true, toks, base)
             }
@@ -350,12 +350,12 @@ object NCDateEnricher extends NCServerEnricher {
                 }
             }
 
-            process(toks)
+            process(toks.toSeq)
 
             val nnToks = toks.filter(!_.isStopWord)
 
             if (nnToks != toks)
-                process(nnToks)
+                process(nnToks.toSeq)
         }
 
         res.sortBy(h => ns.indexOfSlice(h.tokens)).toSeq
@@ -543,7 +543,7 @@ object NCDateEnricher extends NCServerEnricher {
             val from = s.head.tokenFrom
             val to = s.last.tokenTo
 
-            val note = mkNote(mkSumRange(notes), from, to, ns.filter(t => 
t.index >= from && t.index <= to))
+            val note = mkNote(mkSumRange(notes), from, to, ns.filter(t => 
t.index >= from && t.index <= to).toSeq)
 
             if (isValidRange(note)) {
                 ns.
@@ -581,7 +581,7 @@ object NCDateEnricher extends NCServerEnricher {
 
         case class Wrapper(holder: Note, var group: Int)
 
-        val wrappers = hs.map(Wrapper(_, 0))
+        val wrappers = hs.map(Wrapper(_, 0)).toSeq
 
         val grouped = wrappers.map(w => {
             val grp =
@@ -607,7 +607,7 @@ object NCDateEnricher extends NCServerEnricher {
             w
         }).map(w => w.holder -> w.group).toMap
 
-        hs.groupBy(grouped(_)).toSeq.sortBy(_._1).map(_._2).filter(_.size > 1)
+        
hs.groupBy(grouped(_)).toSeq.sortBy(_._1).map(_._2.toSeq).filter(_.size > 1)
     }
 
     private def removeDuplicates(ns: Sentence): Unit = {
@@ -626,7 +626,7 @@ object NCDateEnricher extends NCServerEnricher {
 
             // Groups ordered to keep node with maximum information (max 
periods count in date).
             val hs: Iterable[Seq[Note]] =
-                grouped.map(_._2.sortBy(h => 
-h("periods").asInstanceOf[java.util.List[String]].asScala.length))
+                grouped.map(_._2.sortBy(h => 
-h("periods").asInstanceOf[java.util.List[String]].asScala.toSeq.length))
 
             // First holder will be kept in group, others (tail) should be 
deleted.
             hs.flatMap(_.tail)
@@ -661,7 +661,7 @@ object NCDateEnricher extends NCServerEnricher {
     private def mkDateRange(n1: Note, n2: Note): NCDateRange = 
NCDateRange(n1("from").asInstanceOf[Long], n2("to").asInstanceOf[Long])
     private def mkDateRange(n: Note): NCDateRange = mkDateRange(n, n)
     private def getField(d: Long, field: Int): Int = mkCalendar(d).get(field)
-    private def equalHolder(h: Note, ps: String*): Boolean = 
h("periods").asInstanceOf[java.util.List[String]].asScala.sorted == ps.sorted
+    private def equalHolder(h: Note, ps: String*): Boolean = 
h("periods").asInstanceOf[java.util.List[String]].asScala.toSeq.sorted == 
ps.sorted
     private def equalHolders(hs: Seq[Note], ps: String*): Boolean = 
hs.forall(equalHolder(_, ps: _*))
     private def getPrevious[T](s: T, seq: Seq[T]): T = seq(seq.indexOf(s) - 1)
     private def nearRanges(ns: Seq[Note]): Boolean =
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 dce1ec6..58f2e89 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
@@ -367,7 +367,7 @@ object NCStopWordEnricher extends NCServerEnricher {
      */
     @tailrec
     private def markBefore(
-        ns: NCNlpSentence, stopPoses: Seq[String], lastIdx: Int, isException: 
Seq[NCNlpSentenceToken] => Boolean
+        ns: NCNlpSentence, stopPoses: Seq[String], lastIdx: Int, isException: 
IndexedSeq[NCNlpSentenceToken] => Boolean
     ): Boolean = {
         var stop = true
 
@@ -375,7 +375,7 @@ object NCStopWordEnricher extends NCServerEnricher {
             (tok, idx) <- ns.zipWithIndex
             if idx != lastIdx &&
                 !tok.isStopWord &&
-                !isException(Seq(tok)) &&
+                !isException(IndexedSeq(tok)) &&
                 stopPoses.contains(tok.pos) &&
                 ns(idx + 1).isStopWord) {
             ns.fixNote(tok.getNlpNote, "stopWord" -> true)
@@ -548,9 +548,8 @@ object NCStopWordEnricher extends NCServerEnricher {
             val cacheSw = mutable.HashMap.empty[Seq[NCNlpSentenceToken], 
Boolean]
             val cacheEx = mutable.HashMap.empty[Seq[NCNlpSentenceToken], 
Boolean]
     
-            def isStop(toks: Seq[NCNlpSentenceToken]): Boolean = exists(toks, 
cacheSw, stopWords.matches)
-    
-            def isException(toks: Seq[NCNlpSentenceToken]): Boolean = 
exists(toks, cacheEx, exceptions.matches)
+            def isStop(toks: IndexedSeq[NCNlpSentenceToken]): Boolean = 
exists(toks, cacheSw, stopWords.matches)
+            def isException(toks: IndexedSeq[NCNlpSentenceToken]): Boolean = 
exists(toks, cacheEx, exceptions.matches)
     
             for (p <- ns.zipWithIndex) {
                 val tok = p._1
@@ -574,7 +573,7 @@ object NCStopWordEnricher extends NCServerEnricher {
                 // | POS tags and manual resolution. |
                 // +---------------------------------+
                 val stop =
-                !tok.isQuoted && !isException(Seq(tok)) &&
+                !tok.isQuoted && !isException(IndexedSeq(tok)) &&
                     (// Percents after numbers.
                         // 1. Word from 'percentage' list.
                         percents.contains(stem) &&
@@ -603,7 +602,7 @@ object NCStopWordEnricher extends NCServerEnricher {
             }
             
             // Capture the token mix at this point minus the initial stop 
words found up to this point.
-            val origToks: Seq[(Seq[NCNlpSentenceToken], String)] = (for (toks 
<- mix) yield toks).map(s => s -> toStemKey(s))
+            val origToks: Seq[(IndexedSeq[NCNlpSentenceToken], String)] = (for 
(toks <- mix) yield toks).map(s => s -> toStemKey(s))
     
             // +--------------------------------------------+
             // | Pass #4.                                   |

Reply via email to