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 df98336  WIP.
df98336 is described below

commit df98336976ace891c40267ec72f9181a912366a8
Author: Sergey Kamov <[email protected]>
AuthorDate: Mon Jul 5 23:11:54 2021 +0300

    WIP.
---
 .../enrichers/ctxword/NCContextWordEnricher.scala  | 25 +++++++++--------
 .../nlpcraft/model/ctxword/NCContextWordSpec.scala | 32 +++++++++++++---------
 2 files changed, 33 insertions(+), 24 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/ctxword/NCContextWordEnricher.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/ctxword/NCContextWordEnricher.scala
index 6978967..f19a342 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/ctxword/NCContextWordEnricher.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/ctxword/NCContextWordEnricher.scala
@@ -48,15 +48,18 @@ object NCContextWordEnricher extends NCServerEnricher {
     private final val DEBUG_MODE = true
 
     private final val CONVERTER = new DefaultNameConverter
-
-    private final val FN = new DecimalFormat("#0.00000")
+    private final val FMT = new DecimalFormat("#0.00000")
 
     private case class Score(score: Double, reason: Option[String] = None) {
-        override def toString: String =
-            reason match {
-                case Some(v) => s"${FN.format(score)}(via: '$v')}"
-                case None => s"${FN.format(score)}(direct)}"
-            }
+        override def toString: String = {
+            val s =
+                reason match {
+                    case Some(v) => s"via:'$v'"
+                    case None => "direct"
+                }
+
+            s"${FMT.format(score)}($s)}"
+        }
     }
     private case class ModelProbeKey(probeId: String, modelId: String)
     private case class ElementScore(elementId: String, scores: Score*) {
@@ -99,8 +102,8 @@ object NCContextWordEnricher extends NCServerEnricher {
 
         private def sort(m: ScoreFactors): String =
             m.toSeq.
-                sortBy(p => -p._2.max).map(
-                    { case (k, factors) => s"$k=${factors.sortBy(-_).map(p => 
FN.format(p)).mkString("{ ", ", ", " }")}" }
+                sortBy(p => (-p._2.max, -p._2.size)).map(
+                    { case (k, factors) => s"$k=${factors.sortBy(-_).map(p => 
FMT.format(p)).mkString("{ ", ", ", " }")}" }
                 ).mkString("{ ", ", ", " }")
 
         override def toString: String = s"Score: ${sort(normals)}"
@@ -332,7 +335,7 @@ object NCContextWordEnricher extends NCServerEnricher {
                 for ((req, resp) <- resps) {
                     t += (
                         req,
-                        s"${resp.map(p => 
s"${p.word}=${FN.format(normalize(p.score))}").mkString(", ")}"
+                        s"${resp.map(p => 
s"${p.word}=${FMT.format(normalize(p.score))}").mkString(", ")}"
                     )
                 }
 
@@ -498,7 +501,7 @@ object NCContextWordEnricher extends NCServerEnricher {
                                 t += (
                                     sorted.head._2,
                                     s"${sorted.map(_._1).
-                                    map(p => 
s"${p.word}=${FN.format(normalize(p.score))}").
+                                    map(p => 
s"${p.word}=${FMT.format(normalize(p.score))}").
                                     mkString(", ")}"
                                 )
                             }
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 5a902f9..3dfeee3 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
@@ -50,7 +50,7 @@ class NCContextWordSpecModel extends NCModel {
     override def getName: String = this.getClass.getSimpleName
     override def getVersion: String = "1.0.0"
 
-    val MDL_LEVEL = 0.4
+    val MDL_LEVEL = 0.8
     val MDL_POLICY = AVERAGE
 
     override def getContextWordModelConfig: Optional[NCContextWordModelConfig] 
= {
@@ -73,6 +73,11 @@ class NCContextWordSpecModel extends NCModel {
                         "BMW has the best engine",
                         "Luxury cars like Mercedes and BMW  are prime targets",
                         "BMW will install side air bags up front",
+                        "I want to change BMW engine",
+                        "I want to try BMW driver dynamics",
+                        "BMW has excellent driver protection",
+                        "BMW pricing are going up",
+                        "BMW drivers have the highest loyalty",
 
                         "A wild cat is very dangerous",
                         "A fox eats hens",
@@ -138,17 +143,18 @@ class NCContextWordSpec extends NCTestContext {
 
     @Test
     private[ctxword] def test(): Unit = {
-        check("I want to have dogs and foxes", "class:animal", "dogs", "foxes")
-        check("I bought dog's meat", "class:animal", "dog")
-        check("I bought meat dog's", "class:animal", "dog")
-
-        check("I want to have a dog and fox", "class:animal", "dog", "fox")
-        check("I fed your fish", "class:animal", "fish")
-
-        check("I like to drive my Porsche and Volkswagen", "class:cars", 
"Porsche", "Volkswagen")
-        check("Peugeot added motorcycles to its range in 1901", "class:cars", 
"Peugeot", "motorcycles")
-
-        check("The frost is possible today", "class:weather", "frost")
-        check("There's a very strong wind from the east now", "class:weather", 
"wind")
+//        check("I want to have dogs and foxes", "class:animal", "dogs", 
"foxes")
+//        check("I bought dog's meat", "class:animal", "dog")
+//        check("I bought meat dog's", "class:animal", "dog")
+//
+//        check("I want to have a dog and fox", "class:animal", "dog", "fox")
+//        check("I fed your fish", "class:animal", "fish")
+
+        // check("I like to drive my Porsche and Volkswagen", "class:cars", 
"Porsche", "Volkswagen")
+//        check("Peugeot added motorcycles to its range in 1901", 
"class:cars", "Peugeot", "motorcycles")
+//
+        //check("The frost is possible today", "class:weather", "frost")
+        check("Is vehicle a reliable car ?", "class:weather", "frost")
+        //check("There's a very strong wind from the east now", 
"class:weather", "wind")
     }
 }

Reply via email to