You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by se...@apache.org on 2020/09/18 07:10:22 UTC

[incubator-nlpcraft] 07/12: WIP.

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

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

commit e93767b3c4b7a976154f4a76f3f1b6d199580317
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Thu Sep 17 23:00:06 2020 -0700

    WIP.
---
 .../nlpcraft/model/intent/impl/NCIntentSolverEngine.scala   | 13 +++++++++----
 .../nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala    | 10 ++++------
 .../org/apache/nlpcraft/server/rest/NCRestModelSpec.scala   | 10 +++++-----
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/NCIntentSolverEngine.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/NCIntentSolverEngine.scala
index 4a38cc1..dd7f876 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/NCIntentSolverEngine.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/NCIntentSolverEngine.scala
@@ -442,7 +442,7 @@ object NCIntentSolverEngine extends LazyLogging with NCOpenCensusTrace {
             }
             
             if (abort) {
-                logger.info(s"Intent '$intentId' didn't match because of missing term $varStr.")
+                logger.info(s"Intent '$intentId' didn't match because of unmatched term $varStr.")
 
                 None
             }
@@ -458,20 +458,25 @@ object NCIntentSolverEngine extends LazyLogging with NCOpenCensusTrace {
                 None
             }
             else if (!senToks.exists(tok ⇒ tok.used && !tok.conv)) {
-                logger.info(s"Intent '$intentId' didn't match because all tokens came from STM $varStr.")
+                logger.info(s"Intent '$intentId' didn't match because all its matched tokens came from STM $varStr.")
 
                 None
             }
             else {
-                val exactMatch = !(senToks ++ convToks).exists(tok ⇒ !tok.used && !tok.token.isFreeWord)
+                // Exact match calculation DOES NOT include tokens from conversation, if any.
+                val exactMatch = !senToks.exists(tok ⇒ !tok.used && !tok.token.isFreeWord)
 
-                val mainWeight =
+                val mainWeight = {
+                    // Best weight if the match is exact and conversation WAS NOT used.
                     if (exactMatch && convToks.isEmpty)
                         2
+                    // Second best weight if the match is exact and conversation WAS used.
                     else if (exactMatch)
                         1
+                    // Third best (i.e. worst) weight if match WAS NOT EXACT.
                     else
                         0
+                }
 
                 intentW.setWeight(0, mainWeight)
                 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala
index 8acee4d..6500bd4 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala
@@ -223,7 +223,7 @@ object NCSuggestSynonymManager extends NCService {
 
                                 if (ids.nonEmpty)
                                     warns +=
-                                        s"Following model intent have too few samples: ${ids.mkString(", ")}. " +
+                                        s"Following model intent have too few samples (${ids.mkString(", ")}). " +
                                         s"It will negatively affect the quality of suggestions. " +
                                         s"Try to increase overall sample count to at least $MIN_CNT_INTENT."
                             }
@@ -298,13 +298,11 @@ object NCSuggestSynonymManager extends NCService {
                             val allReqsCnt = allReqs.map(_._2.size).sum
                             val allSynsCnt = elemSyns.map(_._2.size).sum
 
-                            logger.trace(
-                                s"Request is going to execute on 'ctxword' server [" +
+                            logger.trace(s"Request is going to execute on 'ctxword' server [" +
                                 s"exs=${exs.size}, " +
                                 s"syns=$allSynsCnt, " +
                                 s"reqs=$allReqsCnt" +
-                                s"]"
-                            )
+                            s"]")
 
                             if (allReqsCnt == 0)
                                 onError(s"Suggestions cannot be generated for model: '$mdlId'")
@@ -369,7 +367,7 @@ object NCSuggestSynonymManager extends NCService {
                                 cdl.await(Long.MaxValue, TimeUnit.MILLISECONDS)
 
                                 if (err.get() != null)
-                                    throw new NCE("Error during work with ContextWordServer", err.get())
+                                    throw new NCE("Error during work with 'ContextWordServer'.", err.get())
 
                                 val allSynsStems = elemSyns.flatMap(_._2).flatten.map(_.stem).toSet
 
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestModelSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestModelSpec.scala
index 2c4ef04..bafe71d 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestModelSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestModelSpec.scala
@@ -18,20 +18,20 @@
 package org.apache.nlpcraft.server.rest
 
 import org.apache.nlpcraft.NCTestEnvironment
-import org.apache.nlpcraft.examples.time.TimeModel
+import org.apache.nlpcraft.examples.alarm.AlarmModel
 import org.junit.jupiter.api.Assertions._
 import org.junit.jupiter.api.{Disabled, Test}
 
 // Enable it and run if context word server started.
-@Disabled
-@NCTestEnvironment(model = classOf[TimeModel], startClient = false)
+//@Disabled
+@NCTestEnvironment(model = classOf[AlarmModel], startClient = false)
 class NCRestModelSpec extends NCRestSpec {
     @Test
     def test(): Unit = {
-        post("model/sugsyn", "mdlId" → "nlpcraft.time.ex")(
+        post("model/sugsyn", "mdlId" → "nlpcraft.alarm.ex")(
             ("$.status", (status: String) ⇒ assertEquals("API_OK", status))
         )
-        post("model/sugsyn", "mdlId" → "nlpcraft.time.ex", "minScore" → 0.5)(
+        post("model/sugsyn", "mdlId" → "nlpcraft.alarm.ex", "minScore" → 0.5)(
             ("$.status", (status: String) ⇒ assertEquals("API_OK", status))
         )
     }