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

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


The following commit(s) were added to refs/heads/NLPCRAFT-495 by this push:
     new 6ccd8c0a API refactored.
6ccd8c0a is described below

commit 6ccd8c0a1936e146aaefae9f4f66d0524c69b8fc
Author: Sergey Kamov <skhdlem...@gmail.com>
AuthorDate: Tue Jul 5 14:59:04 2022 +0300

    API refactored.
---
 nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala     | 2 +-
 nlpcraft/src/main/scala/org/apache/nlpcraft/NCResult.scala          | 6 +++---
 .../nlpcraft/internal/intent/matcher/NCIntentSolverManager.scala    | 2 +-
 .../org/apache/nlpcraft/internal/impl/NCModelPingPongSpec.scala     | 2 +-
 .../src/test/scala/org/apache/nlpcraft/nlp/NCEntityMapperSpec.scala | 2 +-
 .../src/test/scala/org/apache/nlpcraft/nlp/util/NCTestResult.scala  | 2 +-
 6 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala
index e7ed8411..6c46a4af 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala
@@ -174,7 +174,7 @@ class NCModelClient(mdl: NCModel) extends LazyLogging, 
AutoCloseable:
                     try
                         val r = ask(sample, Map.empty, userId)
 
-                        Option.when(r.intentId != i.intent.id)(s"Unexpected 
intent ID: '${r.intentId}'")
+                        Option.when(r.intentId.isEmpty || r.intentId.get!= 
i.intent.id)(s"Unexpected intent ID: '${r.intentId.getOrElse("(not set)")}'")
                     catch case e: Throwable =>
                         logger.warn("Unexpected error.", e) 
                         Option(e.getLocalizedMessage)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCResult.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCResult.scala
index 12d8c4e2..d10fbe8f 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCResult.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCResult.scala
@@ -23,8 +23,8 @@ import org.apache.nlpcraft.NCResultType.*
   *
   */
 object NCResult:
-    def apply(body: Any, resultType: NCResultType, intentId: String): NCResult 
= new NCResult(body = body, resultType = resultType, intentId)
-    def apply(body: Any, resultType: NCResultType): NCResult = apply(body, 
resultType, intentId = null)
+    def apply(body: Any, resultType: NCResultType, intentId: String): NCResult 
= new NCResult(body = body, resultType = resultType, Some(intentId))
+    def apply(body: Any, resultType: NCResultType): NCResult = apply(body, 
resultType, intentId = None)
 
 
 /**
@@ -33,4 +33,4 @@ object NCResult:
   * @param resultType
   * @param intentId
   */
-case class NCResult(body: Any, resultType: NCResultType, intentId: String)
+case class NCResult(body: Any, resultType: NCResultType, intentId: 
Option[String] = None)
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/matcher/NCIntentSolverManager.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/matcher/NCIntentSolverManager.scala
index b2dc4d31..d8b5208f 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/matcher/NCIntentSolverManager.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/matcher/NCIntentSolverManager.scala
@@ -711,7 +711,7 @@ class NCIntentSolverManager(
                     def executeCallback(in: NCCallbackInput): NCResult =
                         var cbRes = intentRes.fn(in)
                         // Store winning intent match in the input.
-                        if cbRes.intentId == null then cbRes = 
NCResult(cbRes.body, cbRes.resultType, intentRes.intentId)
+                        if cbRes.intentId.isEmpty then cbRes = 
NCResult(cbRes.body, cbRes.resultType, intentRes.intentId)
                         cbRes
 
                     def finishSearch(): Unit =
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelPingPongSpec.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelPingPongSpec.scala
index ba5115a3..49168b2b 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelPingPongSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelPingPongSpec.scala
@@ -34,7 +34,7 @@ import scala.util.Using
 class NCModelPingPongSpec:
     private var client: NCModelClient = _
 
-    private class R(resType: NCResultType, txt: String) extends NCResult(txt, 
resType, null):
+    private class R(resType: NCResultType, txt: String) extends NCResult(txt, 
resType):
         override def toString: String = s"$resType ($txt)"
 
     private val MDL: NCTestModelAdapter =
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityMapperSpec.scala 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityMapperSpec.scala
index 28727124..0d07e058 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityMapperSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityMapperSpec.scala
@@ -72,5 +72,5 @@ class NCEntityMapperSpec:
 
     @Test
     def test(): Unit = Using.resource(new NCModelClient(mdl)) { client =>
-        require(client.ask("a b c d", "userId").intentId == "abcd")
+        require(client.ask("a b c d", "userId").intentId.orNull == "abcd")
     }
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestResult.scala 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestResult.scala
index 7ff8e907..77b74906 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestResult.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestResult.scala
@@ -29,4 +29,4 @@ object  NCTestResult {
 /**
   *
   */
-class NCTestResult extends NCResult("test", NCResultType.ASK_RESULT, null)
+class NCTestResult extends NCResult("test", NCResultType.ASK_RESULT)

Reply via email to