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

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


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

commit 553d59e341c498cb286d4ffcc6b62cbdf156fbc5
Author: Sergey Kamov <skhdlem...@gmail.com>
AuthorDate: Mon Feb 7 12:36:02 2022 +0300

    WIP.
---
 .../internal/intent/matcher/NCIntentSolverVariant.scala        | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/matcher/NCIntentSolverVariant.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/matcher/NCIntentSolverVariant.scala
index 1d3435b..3251864 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/matcher/NCIntentSolverVariant.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/matcher/NCIntentSolverVariant.scala
@@ -30,11 +30,11 @@ case class NCIntentSolverVariant(entities: Seq[NCEntity]) 
extends Ordered[NCInte
 
     /**
       *
-      * @param idx
-      * @return
+      * @param toks
       */
-    private def calcSparsity(idx: Seq[Int]): Int =
-        idx.zipWithIndex.tail.map { case (v, i) => Math.abs(v - idx(i - 1)) 
}.sum - idx.length + 1
+    private def calcSparsity(toks: Seq[NCToken]): Int =
+        val idxs = toks.map(_.getIndex)
+        idxs.zipWithIndex.tail.map { case (v, i) => Math.abs(v - idxs(i - 1)) 
}.sum - idxs.length + 1
 
     /**
      * Calculates weight components.
@@ -43,7 +43,7 @@ case class NCIntentSolverVariant(entities: Seq[NCEntity]) 
extends Ordered[NCInte
         val toks: Seq[Seq[NCToken]] = entities.map(_.getTokens.asScala.toSeq)
 
         val toksCnt = toks.map(_.size).sum
-        val totalSparsity = -toks.map(seq => 
calcSparsity(seq.map(_.getIndex))).sum  // Less is better.
+        val totalSparsity = -toks.map(calcSparsity).sum  // Less is better.
         val avgWordsPerEntity = if toksCnt > 0 then 
Math.round((entities.size.toFloat / toksCnt) * 100) else 0
 
         // Order is important.

Reply via email to