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

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


The following commit(s) were added to refs/heads/NLPCRAFT-70_NEW by this push:
     new 70ca228  WIP.
70ca228 is described below

commit 70ca228b0fb2bdd783862a99bd9761c015e7d1b5
Author: Sergey Kamov <[email protected]>
AuthorDate: Tue Jun 29 21:34:12 2021 +0300

    WIP.
---
 .../apache/nlpcraft/model/impl/NCTokenLogger.scala | 10 ++++-
 .../nlpcraft/model/ctxword/NCContextWordSpec.scala | 49 +---------------------
 .../model/ctxword/NCContextWordSpec2.scala         | 40 ++++++------------
 3 files changed, 22 insertions(+), 77 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCTokenLogger.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCTokenLogger.scala
index 717f0b7..0e4c541 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCTokenLogger.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCTokenLogger.scala
@@ -17,10 +17,9 @@
 
 package org.apache.nlpcraft.model.impl
 
-import java.text.SimpleDateFormat
+import java.text.{DecimalFormat, SimpleDateFormat}
 import java.util
 import java.util.{List => JList}
-
 import com.typesafe.scalalogging.LazyLogging
 import org.apache.nlpcraft.common._
 import org.apache.nlpcraft.common.ascii._
@@ -38,6 +37,8 @@ import scala.jdk.CollectionConverters.{CollectionHasAsScala, 
MapHasAsScala}
 //noinspection DuplicatedCode
 object NCTokenLogger extends LazyLogging {
     case class NoteMetadata(noteType: String, filtered: Seq[String], isFull: 
Boolean)
+
+    private final val FMT_NUM = new DecimalFormat("#0.00000")
     
     // Order and sorting of notes for ASCII output.
     private final val NOTE_TYPES = Seq[String](
@@ -617,6 +618,11 @@ object NCTokenLogger extends LazyLogging {
                                 if (parts.nonEmpty)
                                     s = s"$s, parts=[$parts]"
 
+                                
t.meta(s"${t.getId}:scores").asInstanceOf[java.util.List[Double]] match {
+                                    case null => // No-op.
+                                    case scores => s = s"$s, 
scores='${scores.asScala.map(FMT_NUM.format).mkString(",")}'"
+                                }
+
                                 s
                             }
 
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/ctxword/NCContextWordSpec.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/ctxword/NCContextWordSpec.scala
index 736f5be..cd5dfdc 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/ctxword/NCContextWordSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/ctxword/NCContextWordSpec.scala
@@ -17,22 +17,13 @@
 
 package org.apache.nlpcraft.model.ctxword
 
-import org.apache.nlpcraft.common.ascii.NCAsciiTable
 import org.apache.nlpcraft.model.{NCElement, NCIntent, NCIntentMatch, 
NCIntentSample, NCIntentTerm, NCModel, NCResult, NCToken, NCValue}
 import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
-import org.junit.jupiter.api.{AfterEach, BeforeEach, Test}
+import org.junit.jupiter.api.Test
 
-import java.text.DecimalFormat
 import java.util.{Collections, Optional}
 import java.{lang, util}
-import scala.collection.mutable.ArrayBuffer
-import scala.jdk.CollectionConverters.{ListHasAsScala, SeqHasAsJava, 
SetHasAsJava}
-
-object NCContextWordSpecModel {
-    val tables: ArrayBuffer[(String, NCAsciiTable)] = 
ArrayBuffer.empty[(String, NCAsciiTable)]
-}
-
-import org.apache.nlpcraft.model.ctxword.NCContextWordSpecModel._
+import scala.jdk.CollectionConverters.{SeqHasAsJava, SetHasAsJava}
 
 /**
   * Test model.
@@ -42,8 +33,6 @@ class NCContextWordSpecModel extends NCModel {
     override def getName: String = this.getClass.getSimpleName
     override def getVersion: String = "1.0.0"
 
-    private final val FMT = new DecimalFormat("#0.00000")
-
     val level = 0.4
 
     case class Value(name: String, syns: String*) extends NCValue {
@@ -91,25 +80,6 @@ class NCContextWordSpecModel extends NCModel {
     )
     @NCIntent("intent=classification term(toks)~{has(tok_groups(), 
'testGroup')}*")
     def onMatch(ctx: NCIntentMatch, @NCIntentTerm("toks") toks: 
List[NCToken]): NCResult = {
-        val table = NCAsciiTable()
-
-        table #= ("Token text", "Element ID", "Scores")
-
-        for (t <- toks)
-            table += (
-                t.getOriginalText,
-                t.getId,
-                t.getMetadata.
-                    get(s"${t.getId}:scores").
-                    asInstanceOf[java.util.List[Double]].
-                    asScala.
-                    sortBy(-_).
-                    map(FMT.format).
-                    mkString(", ")
-            )
-
-        tables += ctx.getContext.getRequest.getNormalizedText -> table
-
         val elemIds = toks.map(_.getId).distinct.mkString(" ")
         val words = toks.map(_.getOriginalText).mkString(" ")
 
@@ -129,21 +99,6 @@ class NCContextWordSpec extends NCTestContext {
         require(exp == res, s"Expected: $exp, result: $res")
     }
 
-    @BeforeEach
-    private[ctxword] def before(): Unit = tables.clear()
-
-    @AfterEach
-    private[ctxword] def after(): Unit = {
-        println("MATCHED:")
-
-        for ((txt, table) <- tables) {
-            println(s"Text: $txt")
-            table.render()
-        }
-
-        tables.clear()
-    }
-
     @Test
     private[ctxword] def test(): Unit = {
         check("I want to have dogs and foxes", "class:animal", "dogs", "foxes")
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/ctxword/NCContextWordSpec2.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/ctxword/NCContextWordSpec2.scala
index 2a0f407..9b1beff 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/ctxword/NCContextWordSpec2.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/ctxword/NCContextWordSpec2.scala
@@ -17,9 +17,8 @@
 
 package org.apache.nlpcraft.model.ctxword
 
-import org.apache.nlpcraft.model.ctxword.NCContextWordSpecModel._
 import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
-import org.junit.jupiter.api.{AfterEach, BeforeEach, Test}
+import org.junit.jupiter.api.Test
 
 /**
   * Test model.
@@ -37,36 +36,21 @@ class NCContextWordSpec2 extends NCTestContext {
         for (txt <- txts)
             checkIntent(txt, "classification")
 
-    @BeforeEach
-    private[ctxword] def before(): Unit = tables.clear()
-
-    @AfterEach
-    private[ctxword] def after(): Unit = {
-        println("MATCHED:")
-
-        for ((txt, table) <- tables) {
-            println(s"Text: $txt")
-            table.render()
-        }
-
-        tables.clear()
-    }
-
     @Test
     private[ctxword] def test(): Unit = {
         check(
             "I want to have dogs and foxes",
-//            "I bought dog's meat",
-//            "I bought meat dog's",
-//
-//            "I want to have a dog and fox",
-//            "I fed your fish",
-//
-//            "I like to drive my Porsche and Volkswagen",
-//            "Peugeot added motorcycles to its range in 1901",
-//
-//            "The frost is possible today",
-//            "There's a very strong wind from the east now"
+            "I bought dog's meat",
+            "I bought meat dog's",
+
+            "I want to have a dog and fox",
+            "I fed your fish",
+
+            "I like to drive my Porsche and Volkswagen",
+            "Peugeot added motorcycles to its range in 1901",
+
+            "The frost is possible today",
+            "There's a very strong wind from the east now"
         )
     }
 }

Reply via email to