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 2022/08/06 13:12:17 UTC

[incubator-nlpcraft] branch NLPCRAFT-509 created (now e7836144)

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

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


      at e7836144 Result trait refactoring.

This branch includes the following new commits:

     new 0496e2aa Config trait refactoring.
     new e7836144 Result trait refactoring.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-nlpcraft] 01/02: Config trait refactoring.

Posted by se...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0496e2aae0230d65d74005401c7d5c1f8e2c6485
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Sat Aug 6 15:43:39 2022 +0300

    Config trait refactoring.
---
 .../examples/lightswitch/LightSwitchFrModel.scala  |  2 +-
 .../examples/lightswitch/LightSwitchRuModel.scala  |  2 +-
 .../lightswitch/LightSwitchScalaModel.scala        |  2 +-
 .../nlpcraft/examples/pizzeria/PizzeriaModel.scala |  2 +-
 .../apache/nlpcraft/examples/time/TimeModel.scala  |  2 +-
 .../nlpcraft/nlp/util/stanford/NCTestConfig.scala  |  2 +-
 .../scala/org/apache/nlpcraft/NCModelClient.scala  |  6 +--
 .../scala/org/apache/nlpcraft/NCModelConfig.scala  | 44 +++++++++++++++-------
 .../conversation/NCConversationManager.scala       |  6 +--
 .../internal/dialogflow/NCDialogFlowManager.scala  |  6 +--
 .../nlpcraft/internal/impl/NCModelScanner.scala    | 16 ++++----
 .../intent/compiler/NCIDLCodeGenerator.scala       |  8 ++--
 .../internal/intent/compiler/NCIDLCompiler.scala   | 10 ++---
 .../intent/matcher/NCIntentSolverManager.scala     |  4 +-
 .../conversation/NCConversationManagerSpec.scala   | 23 ++++++-----
 .../conversation/NCConversationTimeoutSpec.scala   |  2 +-
 .../dialogflow/NCDialogFlowManagerSpec.scala       |  8 ++--
 .../compiler/functions/NCIDLFunctionsModel.scala   |  8 ++--
 .../apache/nlpcraft/nlp/NCEntityEnricherSpec.scala |  2 +-
 .../nlpcraft/nlp/NCEntityValidatorSpec.scala       |  2 +-
 .../apache/nlpcraft/nlp/NCTokenEnricherSpec.scala  |  2 +-
 .../apache/nlpcraft/nlp/NCTokenValidatorSpec.scala |  2 +-
 .../apache/nlpcraft/nlp/NCVariantFilterSpec.scala  |  2 +-
 .../apache/nlpcraft/nlp/util/NCTestConfig.scala    |  2 +-
 24 files changed, 91 insertions(+), 74 deletions(-)

diff --git a/nlpcraft-examples/lightswitch-fr/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchFrModel.scala b/nlpcraft-examples/lightswitch-fr/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchFrModel.scala
index d3ab533e..ac7bca22 100644
--- a/nlpcraft-examples/lightswitch-fr/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchFrModel.scala
+++ b/nlpcraft-examples/lightswitch-fr/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchFrModel.scala
@@ -42,7 +42,7 @@ import scala.jdk.CollectionConverters.*
   * See 'README.md' file in the same folder for running and testing instructions.
   */
 class LightSwitchFrModel extends NCModelAdapter(
-    new NCModelConfig("nlpcraft.lightswitch.fr.ex", "LightSwitch Example Model FR", "1.0"),
+    NCModelConfig("nlpcraft.lightswitch.fr.ex", "LightSwitch Example Model FR", "1.0"),
     new NCPipelineBuilder().
         withTokenParser(new NCFrTokenParser()).
         withTokenEnricher(new NCFrLemmaPosTokenEnricher()).
diff --git a/nlpcraft-examples/lightswitch-ru/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchRuModel.scala b/nlpcraft-examples/lightswitch-ru/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchRuModel.scala
index 60e7399c..10eca4ca 100644
--- a/nlpcraft-examples/lightswitch-ru/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchRuModel.scala
+++ b/nlpcraft-examples/lightswitch-ru/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchRuModel.scala
@@ -35,7 +35,7 @@ import scala.jdk.CollectionConverters.*
   * See 'README.md' file in the same folder for running and testing instructions.
   */
 class LightSwitchRuModel extends NCModelAdapter(
-    new NCModelConfig("nlpcraft.lightswitch.ru.ex", "LightSwitch Example Model RU", "1.0"),
+    NCModelConfig("nlpcraft.lightswitch.ru.ex", "LightSwitch Example Model RU", "1.0"),
     new NCPipelineBuilder().
         withTokenParser(new NCRuTokenParser()).
         withTokenEnricher(new NCRuLemmaPosTokenEnricher()).
diff --git a/nlpcraft-examples/lightswitch/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchScalaModel.scala b/nlpcraft-examples/lightswitch/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchScalaModel.scala
index 39727959..2320e128 100644
--- a/nlpcraft-examples/lightswitch/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchScalaModel.scala
+++ b/nlpcraft-examples/lightswitch/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchScalaModel.scala
@@ -40,7 +40,7 @@ import org.apache.nlpcraft.nlp.token.parser.NCOpenNLPTokenParser
   */
 
 class LightSwitchScalaModel extends NCModelAdapter(
-    new NCModelConfig("nlpcraft.lightswitch.java.ex", "LightSwitch Example Model", "1.0"),
+    NCModelConfig("nlpcraft.lightswitch.java.ex", "LightSwitch Example Model", "1.0"),
     new NCPipelineBuilder().withSemantic("en", "lightswitch_model.yaml").build
 ):
     /**
diff --git a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
index 4f528796..d661b813 100644
--- a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
+++ b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
@@ -123,7 +123,7 @@ import org.apache.nlpcraft.examples.pizzeria.PizzeriaModel.*
   * Each order can in one of 5 state (org.apache.nlpcraft.examples.pizzeria.OrderState)
   * Note that there is used custom states logic instead of STM, because complex states flow.
   */
-class PizzeriaModel extends NCModelAdapter(new NCModelConfig("nlpcraft.pizzeria.ex", "Pizzeria Example Model", "1.0"), PizzeriaModelPipeline.PIPELINE) with LazyLogging:
+class PizzeriaModel extends NCModelAdapter(NCModelConfig("nlpcraft.pizzeria.ex", "Pizzeria Example Model", "1.0"), PizzeriaModelPipeline.PIPELINE) with LazyLogging:
     // This method is defined in class scope and has package access level for tests reasons.
     private[pizzeria] def doExecute(o: Order)(using ctx: NCContext, im: NCIntentMatch): Result =
         require(o.isValid)
diff --git a/nlpcraft-examples/time/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.scala b/nlpcraft-examples/time/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.scala
index 2a7e0bf3..245b80f0 100644
--- a/nlpcraft-examples/time/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.scala
+++ b/nlpcraft-examples/time/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.scala
@@ -34,7 +34,7 @@ import java.time.*
 @NCIntent("intent=intent2 term~{# == 'x:time'} fragment(city)")
 @NCIntent("intent=intent1 term={# == 'x:time'}")
 class TimeModel extends NCModelAdapter(
-    new NCModelConfig("nlpcraft.time.ex", "Time Example Model", "1.0"),
+    NCModelConfig("nlpcraft.time.ex", "Time Example Model", "1.0"),
     new NCPipelineBuilder().
         withSemantic("en", "time_model.yaml").
         withEntityParser(NCOpenNLPEntityParser(NCResourceReader.getPath("opennlp/en-ner-location.bin"))).
diff --git a/nlpcraft-stanford/src/test/scala/org/apache/nlpcraft/nlp/util/stanford/NCTestConfig.scala b/nlpcraft-stanford/src/test/scala/org/apache/nlpcraft/nlp/util/stanford/NCTestConfig.scala
index 74e7ca33..64d31f9d 100644
--- a/nlpcraft-stanford/src/test/scala/org/apache/nlpcraft/nlp/util/stanford/NCTestConfig.scala
+++ b/nlpcraft-stanford/src/test/scala/org/apache/nlpcraft/nlp/util/stanford/NCTestConfig.scala
@@ -24,7 +24,7 @@ import org.apache.nlpcraft.nlp.util.NCTestPipeline
 
 import java.util.Properties
 
-final val CFG = new NCModelConfig("testId", "test", "1.0")
+final val CFG = NCModelConfig("testId", "test", "1.0")
 
 /**
   *
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala
index 6c46a4af..07c626d1 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala
@@ -56,9 +56,9 @@ class NCModelClient(mdl: NCModel) extends LazyLogging, AutoCloseable:
         val cfg = mdl.getConfig
         val pipeline = mdl.getPipeline
 
-        require(cfg.id != null, "Model ID cannot be null.")
-        require(cfg.name != null, "Model name cannot be null.")
-        require(cfg.version != null, "Model version cannot be null.")
+        require(cfg.getId != null, "Model ID cannot be null.")
+        require(cfg.getName != null, "Model name cannot be null.")
+        require(cfg.getVersion != null, "Model version cannot be null.")
         require(pipeline.getTokenParser != null, "Token parser cannot be null.")
         require(pipeline.getEntityParsers != null, "List of entity parsers in the pipeline cannot be null.")
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelConfig.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelConfig.scala
index e3ff4186..757ddf24 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelConfig.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelConfig.scala
@@ -27,10 +27,29 @@ object NCModelConfig:
     val DFLT_CONV_TIMEOUT: Long = Duration.ofMinutes(60).toMillis
     val DFLT_CONV_DEPTH = 3
 
-    def apply(id: String, name: String, ver: String) = new NCModelConfig(id, name, ver)
-    def apply(id: String, name: String, ver: String, desc: String, orig: String) =
-        new NCModelConfig(id, name, ver, Option(desc), Option(orig))
-        
+    def apply(id: String, name: String, ver: String): NCModelConfig =
+        new NCModelConfig ():
+            override val getId: String = id
+            override val getName: String = name
+            override val getVersion: String = ver
+
+    def apply(id: String, name: String, ver: String, desc: String, orig: String): NCModelConfig =
+        new NCModelConfig() :
+            override val getId: String = id
+            override val getName: String = name
+            override val getVersion: String = ver
+            override val getDescription: Option[String] = Option(desc)
+            override val getOrigin: Option[String] = Option(orig)
+
+    def apply(id: String, name: String, ver: String, desc: String, orig: String, conversationTimeout: Long, conversationDepth: Int): NCModelConfig = new NCModelConfig() :
+        override val getId: String = id
+        override val getName: String = name
+        override val getVersion: String = ver
+        override val getDescription: Option[String] = Option(desc)
+        override val getOrigin: Option[String] = Option(orig)
+        override val getConversationTimeout: Long = conversationTimeout
+        override val getConversationDepth: Int = conversationDepth
+
 import org.apache.nlpcraft.NCModelConfig.*
 
 /**
@@ -43,12 +62,11 @@ import org.apache.nlpcraft.NCModelConfig.*
   * @param conversationTimeout
   * @param conversationDepth
   */
-case class NCModelConfig(
-    id: String,
-    name: String,
-    version: String,
-    description: Option[String] = None,
-    origin: Option[String] = None,
-    conversationTimeout: Long = DFLT_CONV_TIMEOUT,
-    conversationDepth: Int = DFLT_CONV_DEPTH
-) extends NCPropertyMapAdapter
\ No newline at end of file
+trait NCModelConfig extends NCPropertyMapAdapter:
+    def getId: String
+    def getName: String
+    def getVersion: String
+    def getDescription: Option[String] = None
+    def getOrigin: Option[String] = None
+    def getConversationTimeout: Long = DFLT_CONV_TIMEOUT
+    def getConversationDepth: Int = DFLT_CONV_DEPTH
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/conversation/NCConversationManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/conversation/NCConversationManager.scala
index 1af4e448..7a47de2c 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/conversation/NCConversationManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/conversation/NCConversationManager.scala
@@ -41,7 +41,7 @@ class NCConversationManager(cfg: NCModelConfig) extends LazyLogging:
         convs.synchronized {
             val v = convs.getOrElseUpdate(
                 usrId,
-                Value(NCConversationData(usrId, cfg.id, cfg.conversationTimeout, cfg.conversationDepth))
+                Value(NCConversationData(usrId, cfg.getId, cfg.getConversationTimeout, cfg.getConversationDepth))
             )
 
             v.tstamp = NCUtils.nowUtcMs()
@@ -59,7 +59,7 @@ class NCConversationManager(cfg: NCModelConfig) extends LazyLogging:
         val delKeys = mutable.HashSet.empty[String]
 
         for ((key, value) <- convs)
-            if value.tstamp < now - cfg.conversationTimeout then
+            if value.tstamp < now - cfg.getConversationTimeout then
                 value.conv.clear()
                 delKeys += key
 
@@ -73,7 +73,7 @@ class NCConversationManager(cfg: NCModelConfig) extends LazyLogging:
       * @return
       */
     def start(): Unit =
-        gc = NCUtils.mkThread("conv-mgr-gc", cfg.id) { t =>
+        gc = NCUtils.mkThread("conv-mgr-gc", cfg.getId) { t =>
             while (!t.isInterrupted)
                 try
                     convs.synchronized {
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/dialogflow/NCDialogFlowManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/dialogflow/NCDialogFlowManager.scala
index 9cc9bbb8..5b9be5e0 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/dialogflow/NCDialogFlowManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/dialogflow/NCDialogFlowManager.scala
@@ -40,7 +40,7 @@ class NCDialogFlowManager(cfg: NCModelConfig) extends LazyLogging:
     private def clearForTimeout(): Long =
         require(Thread.holdsLock(flow))
 
-        val timeout = cfg.conversationTimeout
+        val timeout = cfg.getConversationTimeout
         val bound = NCUtils.now() - timeout
         var next = Long.MaxValue
 
@@ -77,7 +77,7 @@ class NCDialogFlowManager(cfg: NCModelConfig) extends LazyLogging:
       * @return
       */
     def start(): Unit =
-        gc = NCUtils.mkThread("dialog-mgr-gc", cfg.id) { t =>
+        gc = NCUtils.mkThread("dialog-mgr-gc", cfg.getId) { t =>
             while (!t.isInterrupted)
                 try
                     flow.synchronized {
@@ -171,7 +171,7 @@ class NCDialogFlowManager(cfg: NCModelConfig) extends LazyLogging:
             )
         }
 
-        logger.info(s"""Current dialog flow (oldest first) for [mdlId=${cfg.id}, usrId=$usrId]\n${tbl.toString()}""")
+        logger.info(s"""Current dialog flow (oldest first) for [mdlId=${cfg.getId}, usrId=$usrId]\n${tbl.toString()}""")
 
     /**
       * Clears dialog history for given user ID.
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala
index 14a58aab..89bdf13d 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala
@@ -146,7 +146,7 @@ object NCModelScanner extends LazyLogging:
         prmClss.zip(argsList).zipWithIndex.map { case ((paramCls, argList), i) =>
             def mkArg(): String = arg2Str(mtd, i)
 
-            lazy val z = s"mdlId=${cfg.id}, type=$paramCls, arg=${mkArg()}"
+            lazy val z = s"mdlId=${cfg.getId}, type=$paramCls, arg=${mkArg()}"
             val entsCnt = argList.size
 
             // Single entity.
@@ -182,7 +182,7 @@ object NCModelScanner extends LazyLogging:
     private def invoke(cfg: NCModelConfig, mtd: Method, obj: AnyRef, args: scala.Array[AnyRef]): NCResult =
         val methodObj = if Modifier.isStatic(mtd.getModifiers) then null else obj
         var flag = mtd.canAccess(methodObj)
-        lazy val z = s"mdlId=${cfg.id}, callback=${method2Str(mtd)}"
+        lazy val z = s"mdlId=${cfg.getId}, callback=${method2Str(mtd)}"
         try
             if !flag then
                 mtd.setAccessible(true)
@@ -214,7 +214,7 @@ object NCModelScanner extends LazyLogging:
         lazy val fStr = field2Str(field)
         val fieldObj = if Modifier.isStatic(field.getModifiers) then null else obj
         var flag = field.canAccess(fieldObj)
-        lazy val z = s"mdlId=${cfg.id}, field=$fStr"
+        lazy val z = s"mdlId=${cfg.getId}, field=$fStr"
         val res =
             try
                 if !flag then
@@ -318,7 +318,7 @@ object NCModelScanner extends LazyLogging:
         argClasses.zip(paramGenTypes).zipWithIndex.foreach { case ((argClass, paramGenType), i) =>
             def mkArg(): String = arg2Str(mtd, i)
 
-            lazy val z = s"mdlId=${cfg.id}, type=${class2Str(argClass)}, arg=${mkArg()}"
+            lazy val z = s"mdlId=${cfg.getId}, type=${class2Str(argClass)}, arg=${mkArg()}"
 
             // Entity.
             if argClass == CLS_ENTITY then () // No-op.
@@ -374,7 +374,7 @@ object NCModelScanner extends LazyLogging:
             def mkArg(): String = arg2Str(mtd, i)
 
             val p1 = "its $IT annotated argument"
-            val p2 = s"mdlId=${cfg.id}, arg=${mkArg()}"
+            val p2 = s"mdlId=${cfg.getId}, arg=${mkArg()}"
 
             // Argument is single entity but defined as not single entity.
             if cls == CLS_ENTITY && (min != 1 || max != 1) then
@@ -399,7 +399,7 @@ object NCModelScanner extends LazyLogging:
       * @return
       */
     private def prepareCallback(cfg: NCModelConfig, method: Method, obj: AnyRef, intent: NCIDLIntent): NCCallbackInput => NCResult =
-        lazy val z = s"mdlId=${cfg.id}, intentId=${intent.id}, type=${class2Str(method.getReturnType)}, callback=${method2Str(method)}"
+        lazy val z = s"mdlId=${cfg.getId}, intentId=${intent.id}, type=${class2Str(method.getReturnType)}, callback=${method2Str(method)}"
 
         // Checks method result type.
         if method.getReturnType != CLS_QRY_RES && !CLS_QRY_RES.isAssignableFrom(method.getReturnType) then
@@ -471,7 +471,7 @@ object NCModelScanner extends LazyLogging:
         require(mdl != null)
 
         val cfg = mdl.getConfig
-        lazy val z = s"mdlId=${cfg.id}"
+        lazy val z = s"mdlId=${cfg.getId}"
         val intentsMtds = mutable.HashMap.empty[Method, IntentHolder]
         val intentDecls = mutable.HashMap.empty[String, NCIDLIntent]
         val objs = mutable.Buffer.empty[AnyRef]
@@ -548,6 +548,6 @@ object NCModelScanner extends LazyLogging:
                 case ids if ids.nonEmpty => E(s"Duplicate intent IDs [$z, ids=${col2Str(ids)}]")
                 case _ => // No-op.
         else
-            logger.warn(s"Model has no intent: ${cfg.id}")
+            logger.warn(s"Model has no intent: ${cfg.getId}")
 
         intents.map(i => NCModelIntent(i.intent, i.function, samples.getOrElse(i.method, Map.empty).getOrElse(i.intent.id, Seq.empty))).toSeq
\ No newline at end of file
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCodeGenerator.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCodeGenerator.scala
index 17456e5e..2bd957ec 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCodeGenerator.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCodeGenerator.scala
@@ -911,10 +911,10 @@ trait NCIDLCodeGenerator:
                 case "or_else" => doOrElse()
 
                 // Model configuration.
-                case "mdl_id" => z0(() => Z(idlCtx.mdlCfg.id, 0))
-                case "mdl_name" => z0(() => Z(idlCtx.mdlCfg.name, 0))
-                case "mdl_ver" => z0(() => Z(idlCtx.mdlCfg.version, 0))
-                case "mdl_origin" => z0(() => Z(idlCtx.mdlCfg.origin, 0))
+                case "mdl_id" => z0(() => Z(idlCtx.mdlCfg.getId, 0))
+                case "mdl_name" => z0(() => Z(idlCtx.mdlCfg.getName, 0))
+                case "mdl_ver" => z0(() => Z(idlCtx.mdlCfg.getVersion, 0))
+                case "mdl_origin" => z0(() => Z(idlCtx.mdlCfg.getOrigin, 0))
 
                 // Entity functions.
                 case "ent_id" => arg1Tok() match { case x => stack.push(() => Z(toEntity(x().value).impl.getId, 1)) }
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCompiler.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCompiler.scala
index 322e7542..9f8a1ee9 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCompiler.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCompiler.scala
@@ -181,12 +181,12 @@ object NCIDLCompiler extends LazyLogging:
 
         override def exitFragId(ctx: IDP.FragIdContext): Unit =
             fragId = ctx.id().getText
-            if NCIDLGlobal.getFragment(mdlCfg.id, fragId).isDefined then SE(s"Duplicate fragment ID: $fragId")(ctx.id())
+            if NCIDLGlobal.getFragment(mdlCfg.getId, fragId).isDefined then SE(s"Duplicate fragment ID: $fragId")(ctx.id())
 
         override def exitFragRef(ctx: IDP.FragRefContext): Unit =
             val id = ctx.id().getText
 
-            NCIDLGlobal.getFragment(mdlCfg.id, id) match
+            NCIDLGlobal.getFragment(mdlCfg.getId, id) match
                 case Some(frag) =>
                     val meta = if fragMeta == null then Map.empty[String, Any] else fragMeta
                     for (fragTerm <- frag.terms)
@@ -256,7 +256,7 @@ object NCIDLCompiler extends LazyLogging:
             }
 
         override def exitFrag(ctx: IDP.FragContext): Unit =
-            NCIDLGlobal.addFragment(mdlCfg.id, NCIDLFragment(fragId, terms.toList))
+            NCIDLGlobal.addFragment(mdlCfg.getId, NCIDLFragment(fragId, terms.toList))
             terms.clear()
             fragId = null
 
@@ -393,8 +393,8 @@ object NCIDLCompiler extends LazyLogging:
             case s: String => s"$s."
 
         s"""IDL $kind error in '$srcName' at line $line - $aMsg
-          |-- Model ID: ${mdlCfg.id}
-          |-- Model origin: ${mdlCfg.origin}
+          |-- Model ID: ${mdlCfg.getId}
+          |-- Model origin: ${mdlCfg.getOrigin}
           |-- Intent origin: $origin
           |--
           |-- Line:  ${hold.origStr}
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 4637a01f..4ce87943 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
@@ -748,7 +748,7 @@ class NCIntentSolverManager(
                         case SEARCH_NO_HISTORY =>
                             finishSearch()
                 else
-                    logger.info(s"Model '${ctx.getModelConfig.id}' triggered rematching of intents by intent '${intentRes.intentId}' on variant #${intentRes.variantIdx + 1}.")
+                    logger.info(s"Model '${ctx.getModelConfig.getId}' triggered rematching of intents by intent '${intentRes.intentId}' on variant #${intentRes.variantIdx + 1}.")
                     Loop.finish()
                 catch
                     case e: NCIntentSkip =>
@@ -769,7 +769,7 @@ class NCIntentSolverManager(
     def solve(mdl: NCModel, ctx: NCContext, typ: NCIntentSolveType): ResultData =
         import NCIntentSolveType.REGULAR
 
-        val key = UserModelKey(ctx.getRequest.getUserId, mdl.getConfig.id)
+        val key = UserModelKey(ctx.getRequest.getUserId, mdl.getConfig.getId)
         reqIds.synchronized { reqIds.put(key, ctx.getRequest.getRequestId)}
 
         mdl.onContext(ctx) match
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationManagerSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationManagerSpec.scala
index 4889f2b9..f2fb54ce 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationManagerSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationManagerSpec.scala
@@ -27,20 +27,19 @@ import java.util.function.Predicate
   *
   */
 class NCConversationManagerSpec:
-    class ModelConfigMock(timeout: Long = Long.MaxValue) extends NCModelConfig(
-        "testId",
-        "test",
-        "1.0",
-        Some("Test description"),
-        Some("Test origin"),
-        NCModelConfig.DFLT_CONV_TIMEOUT,
-        NCModelConfig.DFLT_CONV_DEPTH
-    ):
-        override val conversationTimeout: Long = timeout
+    def mkConfig(timeout: Long = Long.MaxValue):NCModelConfig =
+        NCModelConfig(
+            "testId",
+            "test", "1.0",
+            "Test description",
+            "Test origin",
+            timeout,
+            NCModelConfig.DFLT_CONV_DEPTH
+        )
 
     @Test
     def test(): Unit =
-        val mgr = NCConversationManager(ModelConfigMock())
+        val mgr = NCConversationManager(mkConfig())
         val t = NCTestToken()
         val reqId = "req1"
 
@@ -69,7 +68,7 @@ class NCConversationManagerSpec:
     def testTimeout(): Unit =
         val timeout = 1000
 
-        val mgr = NCConversationManager(ModelConfigMock(timeout))
+        val mgr = NCConversationManager(mkConfig(timeout))
         val t = NCTestToken()
         val reqId = "req1"
 
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationTimeoutSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationTimeoutSpec.scala
index 61442ad6..ee8537c8 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationTimeoutSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationTimeoutSpec.scala
@@ -45,7 +45,7 @@ class NCConversationTimeoutSpec:
         val mdl: NCModel =
             new NCTestModelAdapter:
                 override val getConfig: NCModelConfig =
-                    new NCModelConfig(CFG.id, CFG.name, CFG.version, CFG.description, CFG.origin, TIMEOUT, CFG.conversationDepth)
+                    NCModelConfig(CFG.getId, CFG.getName, CFG.getVersion, "Test desc", "Test origin", TIMEOUT, CFG.getConversationDepth)
 
                 override val getPipeline: NCPipeline =
                     val pl = mkEnPipeline
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/dialogflow/NCDialogFlowManagerSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/dialogflow/NCDialogFlowManagerSpec.scala
index 57a1be15..b14c4ffd 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/dialogflow/NCDialogFlowManagerSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/dialogflow/NCDialogFlowManagerSpec.scala
@@ -44,8 +44,8 @@ class NCDialogFlowManagerSpec:
         override def getVariants: List[NCVariant] = null
         override def getTokens: List[NCToken] = null
 
-    class ModelConfigMock(timeout: Long = Long.MaxValue) extends NCModelConfig("testId", "test", "1.0", Some("Test description"), Some("Test origin"), NCModelConfig.DFLT_CONV_TIMEOUT, NCModelConfig.DFLT_CONV_DEPTH):
-        override val conversationTimeout: Long = timeout
+    def mkConfig(timeout: Long = Long.MaxValue): NCModelConfig =
+        NCModelConfig("testId", "test", "1.0", "Test description", "Test origin", timeout, NCModelConfig.DFLT_CONV_DEPTH)
 
     private var mgr: NCDialogFlowManager = _
 
@@ -79,7 +79,7 @@ class NCDialogFlowManagerSpec:
 
     @Test
     def test(): Unit =
-        mgr = NCDialogFlowManager(ModelConfigMock())
+        mgr = NCDialogFlowManager(mkConfig())
 
         val now = NCUtils.now()
 
@@ -111,7 +111,7 @@ class NCDialogFlowManagerSpec:
         val delay = 10
         val timeout = delay * 1000
 
-        mgr = NCDialogFlowManager(ModelConfigMock(timeout))
+        mgr = NCDialogFlowManager(mkConfig(timeout))
 
         val now = NCUtils.now()
 
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/intent/compiler/functions/NCIDLFunctionsModel.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/intent/compiler/functions/NCIDLFunctionsModel.scala
index ea5d2459..fa2f41f3 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/intent/compiler/functions/NCIDLFunctionsModel.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/intent/compiler/functions/NCIDLFunctionsModel.scala
@@ -34,8 +34,8 @@ class NCIDLFunctionsModel extends NCIDLFunctions:
         def mkTestDesc(truth: String): TestDesc = TestDesc(truth = truth, idlCtx = idlCtx)
 
         test(
-            mkTestDesc(s"mdl_id == '${idlCtx.mdlCfg.id}'"),
-            mkTestDesc(s"mdl_name == '${idlCtx.mdlCfg.name}'"),
-            mkTestDesc(s"mdl_ver == '${idlCtx.mdlCfg.version}'"),
-            mkTestDesc(s"mdl_origin == '${idlCtx.mdlCfg.origin}'")
+            mkTestDesc(s"mdl_id == '${idlCtx.mdlCfg.getId}'"),
+            mkTestDesc(s"mdl_name == '${idlCtx.mdlCfg.getName}'"),
+            mkTestDesc(s"mdl_ver == '${idlCtx.mdlCfg.getVersion}'"),
+            mkTestDesc(s"mdl_origin == '${idlCtx.mdlCfg.getOrigin}'")
         )
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityEnricherSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityEnricherSpec.scala
index f9333c93..056ec772 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityEnricherSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityEnricherSpec.scala
@@ -32,7 +32,7 @@ import scala.util.Using
   */
 class NCEntityEnricherSpec:
     private def test0(pipeline: NCPipeline, ok: Boolean): Unit =
-        val mdl: NCModel = new NCModelAdapter(new NCModelConfig("test.id", "Test model", "1.0"), pipeline):
+        val mdl: NCModel = new NCModelAdapter(NCModelConfig("test.id", "Test model", "1.0"), pipeline):
             @NCIntent("intent=i term(any)={meta_ent('k1') == 'v1'}")
             def onMatch(ctx: NCContext, im: NCIntentMatch): NCResult = NCResult("OK", NCResultType.ASK_RESULT)
 
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityValidatorSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityValidatorSpec.scala
index a09cb0b6..909930be 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityValidatorSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityValidatorSpec.scala
@@ -31,7 +31,7 @@ import scala.util.Using
   */
 class NCEntityValidatorSpec:
     private def test0(pipeline: NCPipeline, ok: Boolean): Unit =
-        val mdl: NCModel = new NCModelAdapter(new NCModelConfig("test.id", "Test model", "1.0"), pipeline):
+        val mdl: NCModel = new NCModelAdapter(NCModelConfig("test.id", "Test model", "1.0"), pipeline):
             override def onContext(ctx: NCContext): Option[NCResult] = Option(NCResult("OK", NCResultType.ASK_RESULT))
 
         NCTestUtils.askSomething(mdl, ok)
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCTokenEnricherSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCTokenEnricherSpec.scala
index b5facb78..e31f04fe 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCTokenEnricherSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCTokenEnricherSpec.scala
@@ -32,7 +32,7 @@ import scala.util.Using
   */
 class NCTokenEnricherSpec:
     private def test0(pipeline: NCPipeline, ok: Boolean): Unit =
-        val mdl: NCModel = new NCModelAdapter(new NCModelConfig("test.id", "Test model", "1.0"), pipeline):
+        val mdl: NCModel = new NCModelAdapter(NCModelConfig("test.id", "Test model", "1.0"), pipeline):
             @NCIntent("intent=i term(any)={meta_ent('nlp:token:k1') == 'v1'}")
             def onMatch(ctx: NCContext, im: NCIntentMatch): NCResult = NCResult("OK", NCResultType.ASK_RESULT)
 
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCTokenValidatorSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCTokenValidatorSpec.scala
index 1b9fb256..f7a71c8b 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCTokenValidatorSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCTokenValidatorSpec.scala
@@ -31,7 +31,7 @@ import scala.util.Using
   */
 class NCTokenValidatorSpec:
     private def test0(pipeline: NCPipeline, ok: Boolean): Unit =
-        val mdl: NCModel = new NCModelAdapter(new NCModelConfig("test.id", "Test model", "1.0"), pipeline):
+        val mdl: NCModel = new NCModelAdapter(NCModelConfig("test.id", "Test model", "1.0"), pipeline):
             override def onContext(ctx: NCContext): Option[NCResult] = Option(NCResult("OK", NCResultType.ASK_RESULT))
 
         NCTestUtils.askSomething(mdl, ok)
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCVariantFilterSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCVariantFilterSpec.scala
index cdd3e994..b893d520 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCVariantFilterSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCVariantFilterSpec.scala
@@ -33,7 +33,7 @@ import scala.util.Using
   */
 class NCVariantFilterSpec:
     private def test0(pipeline: NCPipeline, ok: Boolean): Unit =
-        val mdl: NCModel = new NCModelAdapter(new NCModelConfig("test.id", "Test model", "1.0"), pipeline):
+        val mdl: NCModel = new NCModelAdapter(NCModelConfig("test.id", "Test model", "1.0"), pipeline):
             @NCIntent("intent=i term(any)={true}")
             def onMatch(ctx: NCContext, im: NCIntentMatch): NCResult = NCResult("OK", NCResultType.ASK_RESULT)
 
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestConfig.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestConfig.scala
index c5fc8591..d127c055 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestConfig.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestConfig.scala
@@ -23,7 +23,7 @@ import org.apache.nlpcraft.nlp.token.enricher.*
 import org.apache.nlpcraft.nlp.token.parser.NCOpenNLPTokenParser
 import org.apache.nlpcraft.nlp.util.*
 
-final val CFG = new NCModelConfig("testId", "test", "1.0", description = Some("Test description"), origin = Some("Test origin"))
+final val CFG = NCModelConfig("testId", "test", "1.0", desc = "Test description", orig = "Test origin")
 final val EN_TOK_PARSER = new NCOpenNLPTokenParser(R.getPath("opennlp/en-token.bin"))
 final val EN_TOK_STOP_ENRICHER = new NCEnStopWordsTokenEnricher
 final val EN_TOK_LEMMA_POS_ENRICHER =


[incubator-nlpcraft] 02/02: Result trait refactoring.

Posted by se...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e7836144dfd6b8c0794ac716c4c481a393da8602
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Sat Aug 6 16:12:11 2022 +0300

    Result trait refactoring.
---
 .../examples/pizzeria/PizzeriaModelSpec.scala      |  6 ++--
 .../pizzeria/cli/PizzeriaModelServer.scala         |  4 +--
 .../scala/org/apache/nlpcraft/NCModelClient.scala  |  2 +-
 .../main/scala/org/apache/nlpcraft/NCResult.scala  | 35 ----------------------
 .../intent/matcher/NCIntentSolverManager.scala     |  2 +-
 .../conversation/NCConversationTimeoutSpec.scala   |  2 +-
 .../internal/impl/NCModelCallbacksSpec.scala       |  2 +-
 .../nlpcraft/internal/impl/NCModelClientSpec.scala |  4 +--
 .../internal/impl/NCModelClientSpec3.scala         |  2 +-
 .../internal/impl/NCModelPingPongSpec.scala        | 16 ++++++----
 .../apache/nlpcraft/nlp/NCEntityMapperSpec.scala   |  2 +-
 .../apache/nlpcraft/nlp/util/NCTestResult.scala    |  4 +--
 .../org/apache/nlpcraft/nlp/util/NCTestUtils.scala |  2 +-
 13 files changed, 26 insertions(+), 57 deletions(-)

diff --git a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
index f0f80a75..8d5c3723 100644
--- a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
+++ b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
@@ -87,10 +87,10 @@ class PizzeriaModelSpec:
                 val resp = client.ask(txt, "userId")
 
                 testMsgs += s">> Request: $txt"
-                testMsgs += s">> Response: '${resp.resultType}': ${resp.body}"
+                testMsgs += s">> Response: '${resp.getType}': ${resp.getBody}"
 
-                if expType != resp.resultType then
-                    errs += testNum -> new Exception(s"Unexpected result type [num=$testNum, txt=$txt, expected=$expType, type=${resp.resultType}]")
+                if expType != resp.getType then
+                    errs += testNum -> new Exception(s"Unexpected result type [num=$testNum, txt=$txt, expected=$expType, type=${resp.getType}]")
 
                 // Check execution result on last request.
                 if idx == reqs.size - 1 then
diff --git a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelServer.scala b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelServer.scala
index 056d071a..aa8fd12a 100644
--- a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelServer.scala
+++ b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelServer.scala
@@ -64,8 +64,8 @@ object PizzeriaModelServer:
                     if req == null || req.isEmpty then Exception(s"Empty request.")
 
                     val resp = nlpClient.ask(req, null, "userId")
-                    val prompt = if resp.resultType == ASK_DIALOG then "(Your should answer on the model's question below)\n" else ""
-                    doResponse(s"$prompt${resp.body}")
+                    val prompt = if resp.getType == ASK_DIALOG then "(Your should answer on the model's question below)\n" else ""
+                    doResponse(s"$prompt${resp.getBody}")
                 catch
                     case e: NCRejection => doResponse(s"Request rejected: ${e.getMessage}")
                     case e: Throwable =>
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala
index 07c626d1..4b5553e1 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.isEmpty || r.intentId.get!= i.intent.id)(s"Unexpected intent ID: '${r.intentId.getOrElse("(not set)")}'")
+                        Option.when(r.getIntentId.isEmpty || r.getIntentId.get != i.intent.id)(s"Unexpected intent ID: '${r.getIntentId.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
deleted file mode 100644
index 63c5cd60..00000000
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCResult.scala
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.nlpcraft
-
-import org.apache.nlpcraft.NCResultType.*
-
-/**
-  *
-  */
-object NCResult:
-    def apply(body: Any, resultType: NCResultType, intentId: String): NCResult = new NCResult(body = body, resultType = resultType, Option(intentId))
-    def apply(body: Any, resultType: NCResultType): NCResult = apply(body, resultType, intentId = None)
-
-/**
-  *
-  * @param body
-  * @param resultType
-  * @param intentId
-  */
-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 4ce87943..1f04f9f1 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.isEmpty then cbRes = NCResult(cbRes.body, cbRes.resultType, intentRes.intentId)
+                        if cbRes.getIntentId.isEmpty then cbRes = NCResult(cbRes.getBody, cbRes.getType, intentRes.intentId)
                         cbRes
 
                     def finishSearch(): Unit =
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationTimeoutSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationTimeoutSpec.scala
index ee8537c8..62e5119b 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationTimeoutSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationTimeoutSpec.scala
@@ -64,7 +64,7 @@ class NCConversationTimeoutSpec:
 
         Using.resource(new NCModelClient(mdl)) { cli =>
             def check(hasValue: Boolean): Unit =
-                require(cli.ask("test", "userId").body.toString == (if hasValue then VALUE else EMPTY))
+                require(cli.ask("test", "userId").getBody.toString == (if hasValue then VALUE else EMPTY))
 
             check(false)
             check(true)
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelCallbacksSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelCallbacksSpec.scala
index 02f07d66..706c0641 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelCallbacksSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelCallbacksSpec.scala
@@ -100,7 +100,7 @@ class NCModelCallbacksSpec:
       */
     private def testOk(client: NCModelClient, exp: NCResult, states: State*): Unit =
         set(states*)
-        require(client.ask("x", "userId").body == exp.body)
+        require(client.ask("x", "userId").getBody == exp.getBody)
 
     /**
       *
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec.scala
index a9f7c5b2..4452a1c4 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec.scala
@@ -49,8 +49,8 @@ class NCModelClientSpec:
         Using.resource(new NCModelClient(mdl)) { client =>
             val res = client.ask("Lights on at second floor kitchen", "userId")
 
-            println(s"Intent: ${res.intentId}")
-            println(s"Body: ${res.body}")
+            println(s"Intent: ${res.getIntentId}")
+            println(s"Body: ${res.getBody}")
 
             client.validateSamples()
 
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec3.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec3.scala
index f98408be..332822ed 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec3.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec3.scala
@@ -49,7 +49,7 @@ class NCModelClientSpec3:
         Using.resource(new NCModelClient(mdl)) { client =>
             def ask(): NCCallbackData = client.debugAsk("e1", "userId", true)
             def execCallback(cb: NCCallbackData): NCResult = cb.getCallback.apply(cb.getCallbackArguments)
-            def execCallbackOk(cb: NCCallbackData): Unit = println(s"Result: ${execCallback(cb).body}")
+            def execCallbackOk(cb: NCCallbackData): Unit = println(s"Result: ${execCallback(cb).getBody}")
             def execCallbackFail(cb: NCCallbackData): Unit =
                 try execCallback(cb)
                 catch case e: NCException => println(s"Expected error: ${e.getMessage}")
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 49168b2b..8f47d0cd 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,14 +34,18 @@ import scala.util.Using
 class NCModelPingPongSpec:
     private var client: NCModelClient = _
 
-    private class R(resType: NCResultType, txt: String) extends NCResult(txt, resType):
-        override def toString: String = s"$resType ($txt)"
+    def mkResult(resType: NCResultType, txt: String): NCResult =
+        new NCResult ():
+            override def getBody: Any = txt
+            override def getType: NCResultType = resType
+            override def getIntentId: Option[String] = None
+            override def toString: String = s"$resType ($txt)"
 
     private val MDL: NCTestModelAdapter =
         new NCTestModelAdapter():
             @NCIntent("intent=command term(command)={# == 'command'}")
             def onCommand(ctx: NCContext, im: NCIntentMatch, @NCIntentTerm("command") command: NCEntity): NCResult =
-                R(ASK_DIALOG, s"Confirm your request 'command'")
+                mkResult(ASK_DIALOG, s"Confirm your request 'command'")
 
             @NCIntent("intent=confirmCommand term(confirm)={# == 'confirm'}")
             def onConfirmCommand(ctx: NCContext, im: NCIntentMatch, @NCIntentTerm("confirm") confirm: NCEntity): NCResult =
@@ -56,11 +60,11 @@ class NCModelPingPongSpec:
 
                 println("'Command' confirmed and can be be executed here.")
 
-                R(ASK_RESULT, s"'dialog' confirmed.")
+                mkResult(ASK_RESULT, s"'dialog' confirmed.")
 
             @NCIntent("intent=other term(other)={# == 'other'}")
             def onOther(ctx: NCContext, im: NCIntentMatch, @NCIntentTerm("other") other: NCEntity): NCResult =
-                R(ASK_RESULT, s"Some request by: ${other.mkText}")
+                mkResult(ASK_RESULT, s"Some request by: ${other.mkText}")
 
     MDL.pipeline.entParsers += NCTestUtils.mkEnSemanticParser(List(STE("command"), STE("confirm"), STE("other")))
 
@@ -73,7 +77,7 @@ class NCModelPingPongSpec:
     private def ask(txt: String, typ: NCResultType): Unit =
         val res = client.ask(txt, "userId")
         println(s"Request [text=$txt, result=$res]")
-        require(res.resultType == typ)
+        require(res.getType == typ)
 
     private def askForDialog(txt: String): Unit = ask(txt, ASK_DIALOG)
     private def askForResult(txt: String): Unit = ask(txt, ASK_RESULT)
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 0d07e058..277a621a 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.orNull == "abcd")
+        require(client.ask("a b c d", "userId").getIntentId.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 77b74906..14b86626 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
@@ -23,10 +23,10 @@ import org.apache.nlpcraft.{NCResult, NCResultType}
   *
   */
 object  NCTestResult {
-    def apply(): NCTestResult = new NCTestResult()
+    def apply(): NCResult = TEST_RESULT
 }
 
 /**
   *
   */
-class NCTestResult extends NCResult("test", NCResultType.ASK_RESULT)
+val TEST_RESULT = NCResult("test", NCResultType.ASK_RESULT)
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestUtils.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestUtils.scala
index 7e4da7e9..d64924ca 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestUtils.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestUtils.scala
@@ -113,7 +113,7 @@ object NCTestUtils:
             def ask(): NCResult = client.ask("test", "userId")
 
             if expectedOk then
-                println(ask().body)
+                println(ask().getBody)
             else
                 try
                     ask()