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

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

commit 606768ce6e428c17c66acdd4877d99767458bb4c
Author: Sergey Kamov <[email protected]>
AuthorDate: Tue Nov 8 15:09:22 2022 +0400

    Adapter changed to trait with parameters.
---
 .../nlpcraft/examples/time/CalculatorModel.scala   |  2 +-
 .../examples/lightswitch/LightSwitchFrModel.scala  |  2 +-
 .../examples/lightswitch/LightSwitchRuModel.scala  |  2 +-
 .../examples/lightswitch/LightSwitchModel.scala    |  2 +-
 .../nlpcraft/examples/pizzeria/PizzeriaModel.scala |  2 +-
 .../apache/nlpcraft/examples/time/TimeModel.scala  |  2 +-
 .../main/scala/org/apache/nlpcraft/NCModel.scala   |  8 +++----
 .../scala/org/apache/nlpcraft/NCModelAdapter.scala | 28 ----------------------
 .../internal/impl/NCModelClientSpec4.scala         |  2 +-
 .../intent/compiler/NCIDLFragmentsSpec.scala       | 14 +++++------
 .../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 +-
 .../nlpcraft/nlp/util/NCTestModelAdapter.scala     | 11 +++++----
 16 files changed, 29 insertions(+), 56 deletions(-)

diff --git 
a/nlpcraft-examples/calculator/src/main/scala/org/apache/nlpcraft/examples/time/CalculatorModel.scala
 
b/nlpcraft-examples/calculator/src/main/scala/org/apache/nlpcraft/examples/time/CalculatorModel.scala
index 93d9bc8f..0aecbc86 100644
--- 
a/nlpcraft-examples/calculator/src/main/scala/org/apache/nlpcraft/examples/time/CalculatorModel.scala
+++ 
b/nlpcraft-examples/calculator/src/main/scala/org/apache/nlpcraft/examples/time/CalculatorModel.scala
@@ -49,7 +49,7 @@ import CalculatorModel.*
 /**
  * 
  */
-class CalculatorModel extends 
NCModelAdapter(NCModelConfig("nlpcraft.calculator.ex", "Calculator Example 
Model", "1.0"), PIPELINE) :
+class CalculatorModel extends NCModel(NCModelConfig("nlpcraft.calculator.ex", 
"Calculator Example Model", "1.0"), PIPELINE) :
     private var mem: Option[Int] = None
 
     private def calc(x: Int, op: String, y: Int): NCResult =
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 459f8e65..d93cc571 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
@@ -37,7 +37,7 @@ import scala.jdk.CollectionConverters.*
   *
   * See 'README.md' file in the same folder for running and testing 
instructions.
   */
-class LightSwitchFrModel extends NCModelAdapter(
+class LightSwitchFrModel extends NCModel(
     NCModelConfig("nlpcraft.lightswitch.fr.ex", "LightSwitch Example Model 
FR", "1.0"),
     new NCPipelineBuilder().
         withTokenParser(new NCFrTokenParser()).
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 457719e7..c7169f47 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
@@ -31,7 +31,7 @@ import scala.jdk.CollectionConverters.*
   *
   * See 'README.md' file in the same folder for running and testing 
instructions.
   */
-class LightSwitchRuModel extends NCModelAdapter(
+class LightSwitchRuModel extends NCModel(
     NCModelConfig("nlpcraft.lightswitch.ru.ex", "LightSwitch Example Model 
RU", "1.0"),
     new NCPipelineBuilder().
         withTokenParser(new NCRuTokenParser()).
diff --git 
a/nlpcraft-examples/lightswitch/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala
 
b/nlpcraft-examples/lightswitch/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala
index 1974b7fc..9f73bb3a 100644
--- 
a/nlpcraft-examples/lightswitch/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala
+++ 
b/nlpcraft-examples/lightswitch/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala
@@ -36,7 +36,7 @@ import org.apache.nlpcraft.nlp.parsers.{NCOpenNLPTokenParser, 
NCSemanticEntityPa
   *
   * See 'README.md' file in the same folder for running and testing 
instructions.
   */
-class LightSwitchModel extends NCModelAdapter(
+class LightSwitchModel extends NCModel(
     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/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
 
b/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
index a01dccac..82560df7 100644
--- 
a/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
+++ 
b/nlpcraft-examples/pizzeria/src/main/scala/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(NCModelConfig("nlpcraft.pizzeria.ex", "Pizzeria Example Model", 
"1.0"), PizzeriaModelPipeline.PIPELINE) with LazyLogging:
+class PizzeriaModel extends NCModel(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 a9702929..bf225828 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
@@ -33,7 +33,7 @@ import java.time.*
 @NCIntent("fragment=city term(city)~{# == 'opennlp:location'}")
 @NCIntent("intent=intent2 term~{# == 'x:time'} fragment(city)")
 @NCIntent("intent=intent1 term={# == 'x:time'}")
-class TimeModel extends NCModelAdapter(
+class TimeModel extends NCModel(
     NCModelConfig("nlpcraft.time.ex", "Time Example Model", "1.0"),
     new NCPipelineBuilder().
         withSemantic("en", "time_model.yaml").
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModel.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModel.scala
index 05991e28..b45735be 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModel.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModel.scala
@@ -39,20 +39,20 @@ package org.apache.nlpcraft
   * @see [[NCModelConfig]]
   * @see [[NCPipeline]]
   */
-trait NCModel:
+trait NCModel(cfg: NCModelConfig, pipeline: NCPipeline):
     /**
       * Gets model configuration.
       *
       * @return Model configuration.
       */
-    def getConfig: NCModelConfig
+    def getConfig: NCModelConfig = cfg
 
     /**
       * Gets model NLP processing pipeline.
       *
       * @return NLP processing pipeline.
       */
-    def getPipeline: NCPipeline
+    def getPipeline: NCPipeline = pipeline
 
     /**
       * A callback that is called when a fully assembled query context is 
ready. This is the first of the callbacks
@@ -154,4 +154,4 @@ trait NCModel:
       *         behavior and existing query result or error processing, if 
any. If the method returns `None` - the
       *         default processing flow will continue.
       */
-    def onError(ctx: NCContext, e: Throwable): Option[NCResult] = None
+    def onError(ctx: NCContext, e: Throwable): Option[NCResult] = None
\ No newline at end of file
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelAdapter.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelAdapter.scala
deleted file mode 100644
index 933fbd43..00000000
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelAdapter.scala
+++ /dev/null
@@ -1,28 +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
-
-/**
-  * Convenient adapter for [[NCModel]] interface.
-  *
-  * @param cfg Model configuration.
-  * @param pipeline Model processing pipeline.
-  */
-class NCModelAdapter(cfg: NCModelConfig, pipeline: NCPipeline) extends NCModel:
-    override def getConfig: NCModelConfig = cfg
-    override def getPipeline: NCPipeline = pipeline
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec4.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec4.scala
index 80141f29..dc89f224 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec4.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec4.scala
@@ -29,7 +29,7 @@ import org.scalatest.funsuite.AnyFunSuite
 class NCModelClientSpec4 extends AnyFunSuite:
     test("test") {
         //  For intents matching, we have to add at least one entity parser.
-        val mdl: NCModelAdapter = new NCModelAdapter(CFG, mkEnPipeline(new 
NCNLPEntityParser)):
+        val mdl: NCModel = new NCModel(CFG, mkEnPipeline(new 
NCNLPEntityParser)):
             @NCIntent("intent=i term(any)={true}")
             def onMatch(ctx: NCContext, im: NCIntentMatch): NCResult = 
TEST_RESULT
 
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLFragmentsSpec.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLFragmentsSpec.scala
index 6c526667..ac6a271d 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLFragmentsSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLFragmentsSpec.scala
@@ -31,21 +31,21 @@ class NCIDLFragmentsSpec extends AnyFunSuite:
     // Fragment. One annotations order.
     @NCIntent("fragment=f term(x)~{# == 'x1'}")
     @NCIntent("intent=i1 term~{# == 'x2'} fragment(f)")
-    class M1 extends NCModelAdapter(CFG, mkEmptyEnPipeline)
+    class M1 extends NCModel(CFG, mkEmptyEnPipeline)
 
     // Fragment. Another annotations order.
     @NCIntent("intent=i1 term~{# == 'x2'} fragment(f)")
     @NCIntent("fragment=f term(x)~{# == 'x1'}")
-    class M2 extends NCModelAdapter(CFG, mkEmptyEnPipeline)
+    class M2 extends NCModel(CFG, mkEmptyEnPipeline)
 
     // Fragment. Reference from method to class.
     @NCIntent("fragment=f term(x)~{# == 'x1'}")
-    class M3 extends NCModelAdapter(CFG, mkEmptyEnPipeline):
+    class M3 extends NCModel(CFG, mkEmptyEnPipeline):
         @NCIntent("intent=i1 term~{# == 'x2'} fragment(f)")
         private def m(ctx: NCContext, im: NCIntentMatch): NCResult = null
 
     // Fragment. Reference from method (inside).
-    class M4 extends NCModelAdapter(CFG, mkEmptyEnPipeline) :
+    class M4 extends NCModel(CFG, mkEmptyEnPipeline) :
         @NCIntent("fragment=f term(x)~{# == 'x1'} intent=i1 term~{# == 'x2'} 
fragment(f)")
         private def m(ctx: NCContext, im: NCIntentMatch): NCResult = null
 
@@ -53,10 +53,10 @@ class NCIDLFragmentsSpec extends AnyFunSuite:
 
     // Missed fragment definition.
     @NCIntent("intent=i2 term~{# == 'x2'} fragment(f)")
-    class E1 extends NCModelAdapter(CFG, mkEmptyEnPipeline)
+    class E1 extends NCModel(CFG, mkEmptyEnPipeline)
 
     // Attempt to reference on fragment defined in method.
-    class E2 extends NCModelAdapter(CFG, mkEmptyEnPipeline):
+    class E2 extends NCModel(CFG, mkEmptyEnPipeline):
         @NCIntent("fragment=f term(x)~{# == 'x1'} intent=i1 term~{# == 'x2'} 
fragment(f)")
         private def m1(ctx: NCContext, im: NCIntentMatch): NCResult = null
 
@@ -64,7 +64,7 @@ class NCIDLFragmentsSpec extends AnyFunSuite:
         private def m2(ctx: NCContext, im: NCIntentMatch): NCResult = null
 
     // Attempt to reference on fragment defined in method.
-    class E3 extends NCModelAdapter(CFG, mkEmptyEnPipeline):
+    class E3 extends NCModel(CFG, mkEmptyEnPipeline):
         @NCIntent("fragment=f term(x)~{# == 'x1'} intent=i1 term~{# == 'x2'} 
fragment(f)")
         private def m2(ctx: NCContext, im: NCIntentMatch): NCResult = null
 
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 7a462408..4f5dc60d 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityEnricherSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityEnricherSpec.scala
@@ -30,7 +30,7 @@ import scala.util.Using
   */
 class NCEntityEnricherSpec extends AnyFunSuite:
     private def test0(pipeline: NCPipeline, ok: Boolean): Unit =
-        val mdl: NCModel = new NCModelAdapter(NCModelConfig("test.id", "Test 
model", "1.0"), pipeline):
+        val mdl: NCModel = new NCModel(NCModelConfig("test.id", "Test model", 
"1.0"), pipeline):
             @NCIntent("intent=i term(any)={meta_ent('k1') == 'v1'}")
             def onMatch(ctx: NCContext, im: NCIntentMatch): NCResult = 
TEST_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 488ab53a..e6303f20 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityValidatorSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityValidatorSpec.scala
@@ -30,7 +30,7 @@ import scala.util.Using
   */
 class NCEntityValidatorSpec extends AnyFunSuite:
     private def test0(pipeline: NCPipeline, ok: Boolean): Unit =
-        val mdl: NCModel = new NCModelAdapter(NCModelConfig("test.id", "Test 
model", "1.0"), pipeline):
+        val mdl: NCModel = new NCModel(NCModelConfig("test.id", "Test model", 
"1.0"), pipeline):
             override def onContext(ctx: NCContext): Option[NCResult] = 
TEST_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 9c19d687..4712b55e 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCTokenEnricherSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCTokenEnricherSpec.scala
@@ -30,7 +30,7 @@ import scala.util.Using
   */
 class NCTokenEnricherSpec extends AnyFunSuite:
     private def test0(pipeline: NCPipeline, ok: Boolean): Unit =
-        val mdl: NCModel = new NCModelAdapter(NCModelConfig("test.id", "Test 
model", "1.0"), pipeline):
+        val mdl: NCModel = new NCModel(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 = 
TEST_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 544a459e..1773c6c1 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCTokenValidatorSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCTokenValidatorSpec.scala
@@ -29,7 +29,7 @@ import scala.util.Using
   */
 class NCTokenValidatorSpec extends AnyFunSuite:
     private def test0(pipeline: NCPipeline, ok: Boolean): Unit =
-        val mdl: NCModel = new NCModelAdapter(NCModelConfig("test.id", "Test 
model", "1.0"), pipeline):
+        val mdl: NCModel = new NCModel(NCModelConfig("test.id", "Test model", 
"1.0"), pipeline):
             override def onContext(ctx: NCContext): Option[NCResult] = 
TEST_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 efea0866..10254a13 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCVariantFilterSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCVariantFilterSpec.scala
@@ -31,7 +31,7 @@ import scala.util.Using
   */
 class NCVariantFilterSpec extends AnyFunSuite:
     private def test0(pipeline: NCPipeline, ok: Boolean): Unit =
-        val mdl: NCModel = new NCModelAdapter(NCModelConfig("test.id", "Test 
model", "1.0"), pipeline):
+        val mdl: NCModel = new NCModel(NCModelConfig("test.id", "Test model", 
"1.0"), pipeline):
             @NCIntent("intent=i term(any)={true}")
             def onMatch(ctx: NCContext, im: NCIntentMatch): NCResult = 
TEST_RESULT
 
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestModelAdapter.scala 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestModelAdapter.scala
index 81be545d..77650131 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestModelAdapter.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestModelAdapter.scala
@@ -20,11 +20,12 @@ package org.apache.nlpcraft.nlp.util
 import org.apache.nlpcraft.*
 import org.apache.nlpcraft.nlp.util.*
 
+object NCTestModelAdapter:
+    private val TEST_PIPELINE: NCTestPipeline = mkEmptyEnPipeline
+
+import NCTestModelAdapter.*
 /**
   *
   */
-abstract class NCTestModelAdapter extends NCModel:
-    val pipeline: NCTestPipeline = mkEmptyEnPipeline
-
-    override val getConfig: NCModelConfig = CFG
-    override val getPipeline: NCPipeline = pipeline
\ No newline at end of file
+abstract class NCTestModelAdapter extends NCModel(CFG, TEST_PIPELINE):
+    val pipeline: NCTestPipeline = TEST_PIPELINE
\ No newline at end of file

Reply via email to