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/17 19:34:47 UTC

[incubator-nlpcraft] branch master updated (74b573e -> 3e8056c)

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

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


    from 74b573e  WIP.
     new bdfe2bc  WIP.
     new 4a9b645  WIP.
     new cd7340f  Merge branch 'master' into NLPCRAFT-124
     new 750b3e9  WIP.
     new c92cf62  WIP.
     new 3e8056c  Merge branch 'master' into NLPCRAFT-124

The 6 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.


Summary of changes:
 .../scala/org/apache/nlpcraft/NCTestContext.scala  | 116 +++++++++++++++++++++
 .../org/apache/nlpcraft/NCTestEnvironment.java}    |  32 +++---
 .../nlpcraft/examples/sql/NCSqlExampleSpec.scala   |  36 ++-----
 .../nlpcraft/examples/sql/NCSqlModelSpec.scala     |  27 ++---
 .../nlpcraft/examples/time/NCTimeModelSpec.scala   |  33 ++----
 .../model/conversation/NCConversationSpec.scala    |  33 ++----
 .../nlpcraft/models/stm/NCStmTestModelSpec.scala   |  34 +-----
 .../mgrs/nlp/enrichers/NCEnricherBaseSpec.scala    |  45 ++------
 .../nlp/enrichers/limit/NCEnricherLimitSpec.scala  |   7 +-
 .../model/NCEnricherNestedModelSpec.scala          |  34 +++++-
 .../nlp/enrichers/model/NCNestedTestModel.scala    |  47 ---------
 .../relation/NCEnricherRelationSpec.scala          |   7 +-
 .../nlp/enrichers/sort/NCEnricherSortSpec.scala    |   9 +-
 .../nlpcraft/server/rest/NCRestAskSpec.scala       |  10 +-
 .../nlpcraft/server/rest/NCRestClearSpec.scala     |  10 +-
 .../nlpcraft/server/rest/NCRestModelSpec.scala     |  11 +-
 .../nlpcraft/server/rest/NCRestProbeSpec.scala     |  14 +--
 .../apache/nlpcraft/server/rest/NCRestSpec.scala   |   3 +-
 18 files changed, 229 insertions(+), 279 deletions(-)
 create mode 100644 nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContext.scala
 copy nlpcraft/src/{main/scala/org/apache/nlpcraft/server/mdo/impl/NCMdoEntity.java => test/scala/org/apache/nlpcraft/NCTestEnvironment.java} (61%)
 delete mode 100644 nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCNestedTestModel.scala


[incubator-nlpcraft] 04/06: WIP.

Posted by se...@apache.org.
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 750b3e96bd5b549be4b7fb53f1226be40c77452f
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Thu Sep 17 11:58:16 2020 +0300

    WIP.
---
 .../scala/org/apache/nlpcraft/NCTestContext.scala  | 97 +++++++++++++++-------
 ...estContextModel.java => NCTestEnvironment.java} | 10 ++-
 .../nlpcraft/examples/sql/NCSqlExampleSpec.scala   | 36 ++------
 .../nlpcraft/examples/time/NCTimeModelSpec.scala   | 33 ++------
 .../model/conversation/NCConversationSpec.scala    | 10 +--
 .../nlpcraft/models/stm/NCStmTestModelSpec.scala   | 34 ++------
 .../nlpcraft/server/rest/NCRestAskSpec.scala       | 10 +--
 .../nlpcraft/server/rest/NCRestClearSpec.scala     | 10 +--
 .../nlpcraft/server/rest/NCRestModelSpec.scala     | 11 +--
 .../nlpcraft/server/rest/NCRestProbeSpec.scala     | 11 +--
 .../apache/nlpcraft/server/rest/NCRestSpec.scala   |  3 +-
 11 files changed, 113 insertions(+), 152 deletions(-)

diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContext.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContext.scala
index 7003cc4..892541f 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContext.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContext.scala
@@ -17,61 +17,100 @@
 
 package org.apache.nlpcraft
 
-import java.io.IOException
-
-import org.apache.nlpcraft.common.NCException
-import org.apache.nlpcraft.model.NCModel
 import org.apache.nlpcraft.model.tools.embedded.NCEmbeddedProbe
 import org.apache.nlpcraft.model.tools.test.{NCTestClient, NCTestClientBuilder}
 import org.apache.nlpcraft.probe.mgrs.model.NCModelManager
 import org.junit.jupiter.api.TestInstance.Lifecycle
-import org.junit.jupiter.api.{AfterEach, BeforeAll, BeforeEach, TestInfo, TestInstance}
+import org.junit.jupiter.api._
 
 /**
   *
   */
 @TestInstance(Lifecycle.PER_CLASS)
-class NCTestContext {
-    protected var cli: NCTestClient = _
+abstract class NCTestContext {
+    private final val MDL_CLASS = classOf[NCTestEnvironment]
 
+    private var cli: NCTestClient = _
     private var probeStarted = false
 
     @BeforeEach
-    @throws[NCException]
-    @throws[IOException]
-    private def beforeEach(ti: TestInfo): Unit = {
-        if (ti.getTestMethod.isPresent) {
-            val a = ti.getTestMethod.get().getAnnotation(classOf[NCTestContextModel])
+    @throws[Exception]
+    private def beforeEach(info: TestInfo): Unit = start0(() ⇒ getMethodAnnotation(info))
+
+    @BeforeAll
+    @throws[Exception]
+    private def beforeAll(info: TestInfo): Unit = start0(() ⇒ getClassAnnotation(info))
+
+    @AfterEach
+    @throws[Exception]
+    private def afterEach(info: TestInfo): Unit =
+        if (getMethodAnnotation(info).isDefined)
+            stop0()
+
+    @AfterAll
+    @throws[Exception]
+    private def afterAll(info: TestInfo): Unit =
+        if (getClassAnnotation(info).isDefined)
+            stop0()
+
+    private def getClassAnnotation(info: TestInfo) =
+        if (info.getTestClass.isPresent) Option(info.getTestClass.get().getAnnotation(MDL_CLASS)) else None
+
+    private def getMethodAnnotation(info: TestInfo): Option[NCTestEnvironment] =
+        if (info.getTestMethod.isPresent) Option(info.getTestMethod.get().getAnnotation(MDL_CLASS)) else None
+
+    @throws[Exception]
+    private def start0(extract: () ⇒ Option[NCTestEnvironment]): Unit =
+        extract() match {
+            case Some(ann) ⇒
+                if (probeStarted || cli != null)
+                    throw new IllegalStateException(
+                        "Model already initialized. " +
+                        s"Note that '@${classOf[NCTestEnvironment].getSimpleName}' can be set for class or method, " +
+                        s"but not both of them."
+                    )
+
+                preProbeStart()
 
-            if (a != null) {
                 probeStarted = false
-                NCEmbeddedProbe.start(a.value())
+
+                NCEmbeddedProbe.start(ann.model())
+
                 probeStarted = true
 
-                cli = new NCTestClientBuilder().newBuilder.build
+                if (ann.startClient()) {
+                    cli = new NCTestClientBuilder().newBuilder.build
 
-                cli.open(NCModelManager.getAllModels().head.model.getId)
-            }
+                    cli.open(NCModelManager.getAllModels().head.model.getId)
+                }
+            case None ⇒ // No-op.
         }
-    }
 
-    @AfterEach
-    @throws[NCException]
-    @throws[IOException]
-    private def afterEach(): Unit =
-        if (cli != null)
+    @throws[Exception]
+    private def stop0(): Unit = {
+        if (cli != null) {
             cli.close()
 
+            cli = null
+        }
+
         if (probeStarted) {
             NCEmbeddedProbe.stop()
 
             probeStarted = false
+
+            afterProbeStop()
         }
+    }
 
-    @BeforeAll
-    @throws[NCException]
-    @throws[IOException]
-    private def beforeAll(ti: TestInfo): Unit = {
-        println("!!!ti=" + ti)
+    protected def preProbeStart(): Unit = { }
+
+    protected def afterProbeStop(): Unit = { }
+
+    final protected def getClient: NCTestClient = {
+        if (cli == null)
+            throw new IllegalStateException("Client is not started.")
+
+        cli
     }
-}
+}
\ No newline at end of file
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContextModel.java b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestEnvironment.java
similarity index 84%
rename from nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContextModel.java
rename to nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestEnvironment.java
index 5537fc7..2461ee6 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContextModel.java
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestEnvironment.java
@@ -24,11 +24,13 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 
 import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
 @Documented
 @Retention(value=RUNTIME)
-@Target(value=METHOD)
-public @interface NCTestContextModel {
-    Class<? extends NCModel> value();
-}
+@Target(value = {METHOD, TYPE})
+public @interface NCTestEnvironment {
+    Class<? extends NCModel> model();
+    boolean startClient() default false;
+}
\ No newline at end of file
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/examples/sql/NCSqlExampleSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/examples/sql/NCSqlExampleSpec.scala
index 13736a3..10cd3e8 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/examples/sql/NCSqlExampleSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/examples/sql/NCSqlExampleSpec.scala
@@ -25,19 +25,19 @@ import com.google.gson.Gson
 import com.google.gson.reflect.TypeToken
 import org.apache.nlpcraft.common.ascii.NCAsciiTable
 import org.apache.nlpcraft.examples.sql.db.SqlServer
-import org.apache.nlpcraft.model.tools.embedded.NCEmbeddedProbe
-import org.apache.nlpcraft.model.tools.test.{NCTestClient, NCTestClientBuilder}
+import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
 import org.junit.jupiter.api.{AfterEach, BeforeEach, Test}
 
 import scala.collection.JavaConverters._
-import scala.compat.java8.OptionConverters._
+import scala.compat.java8.OptionConverters.RichOptionalGeneric
 
 /**
   * SQL model test.
   *
   * @see SqlModel
   */
-class NCSqlExampleSpec {
+@NCTestEnvironment(model = classOf[SqlModel], startClient = true)
+class NCSqlExampleSpec extends NCTestContext {
     private val GSON = new Gson
     private val TYPE_RESP = new TypeToken[util.Map[String, Object]]() {}.getType
     private val NORM = Seq("\n", "\r", "\t")
@@ -48,30 +48,10 @@ class NCSqlExampleSpec {
         newTag((_: java.lang.Boolean) ⇒ "**").
         build
 
-    private var client: NCTestClient = _
-
     case class Case(texts: Seq[String], sql: String)
 
-    @BeforeEach
-    def setUp(): Unit = {
-        SqlServer.start()
-
-        NCEmbeddedProbe.start(classOf[SqlModel])
-
-        client = new NCTestClientBuilder().newBuilder.setResponseLog(false).build
-
-        client.open("sql.model.id")
-    }
-
-    @AfterEach
-    def tearDown(): Unit = {
-        if (client != null)
-            client.close()
-
-        NCEmbeddedProbe.stop()
-
-        SqlServer.stop()
-    }
+    override protected def preProbeStart(): Unit = SqlServer.start()
+    override protected def afterProbeStop(): Unit = SqlServer.stop()
 
     private def normalize(s: String): String =
         NORM.
@@ -90,11 +70,13 @@ class NCSqlExampleSpec {
     private def check(cases: Case*): Unit = {
         val errs = collection.mutable.LinkedHashMap.empty[String, String]
 
+        val cli = getClient
+
         cases.
             flatMap(c ⇒ c.texts.map(t ⇒ t → normalize(c.sql))).
             foreach {
                 case (txt, expSqlNorm) ⇒
-                    val res = client.ask(txt)
+                    val res = cli.ask(txt)
 
                     if (res.isOk) {
                         require(res.getResult.asScala.isDefined)
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/examples/time/NCTimeModelSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/examples/time/NCTimeModelSpec.scala
index 93d6e0e..26ff1b8 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/examples/time/NCTimeModelSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/examples/time/NCTimeModelSpec.scala
@@ -20,39 +20,18 @@ package org.apache.nlpcraft.examples.time
 import java.io.IOException
 
 import org.apache.nlpcraft.common.NCException
-import org.apache.nlpcraft.model.tools.embedded.NCEmbeddedProbe
-import org.apache.nlpcraft.model.tools.test.{NCTestClient, NCTestClientBuilder}
+import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
 import org.junit.jupiter.api.Assertions.assertTrue
-import org.junit.jupiter.api.{AfterEach, BeforeEach, Test}
-
-class NCTimeModelSpec {
-    private var cli: NCTestClient = _
-
-    @BeforeEach
-    @throws[NCException]
-    @throws[IOException]
-    private[time] def setUp(): Unit = {
-        NCEmbeddedProbe.start(classOf[TimeModel])
-
-        cli = new NCTestClientBuilder().newBuilder.build
-
-        cli.open("nlpcraft.time.ex")
-    }
-
-    @AfterEach
-    @throws[NCException]
-    @throws[IOException]
-    private[time] def tearDown(): Unit = {
-        if (cli != null)
-            cli.close()
-
-        NCEmbeddedProbe.stop()
-    }
+import org.junit.jupiter.api.Test
 
+@NCTestEnvironment(model = classOf[TimeModel], startClient = true)
+class NCTimeModelSpec extends NCTestContext {
     @Test
     @throws[NCException]
     @throws[IOException]
     private[time] def testIntentsPriorities(): Unit = {
+        val cli = getClient
+
         def check(txt: String, id: String): Unit = {
             val res = cli.ask(txt)
 
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala
index 61bee87..8615995 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala
@@ -19,23 +19,23 @@ package org.apache.nlpcraft.model.conversation
 
 import java.io.IOException
 
-import org.apache.nlpcraft.{NCTestContext, NCTestContextModel}
 import org.apache.nlpcraft.common.NCException
 import org.apache.nlpcraft.examples.weather.WeatherModel
-import org.apache.nlpcraft.model.tools.embedded.NCEmbeddedProbe
-import org.apache.nlpcraft.model.tools.test.{NCTestClient, NCTestClientBuilder}
+import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
 import org.junit.jupiter.api.Assertions.assertTrue
-import org.junit.jupiter.api.{AfterEach, BeforeEach, Test}
+import org.junit.jupiter.api.Test
 
 /**
   * @see WeatherModel
   */
+@NCTestEnvironment(model = classOf[WeatherModel], startClient = true)
 class NCConversationSpec extends NCTestContext {
     @Test
     @throws[NCException]
     @throws[IOException]
-    @NCTestContextModel(value = classOf[WeatherModel])
     private[conversation] def test(): Unit = {
+        val cli = getClient
+
         assertTrue(cli.ask("What's the weather in Moscow?").isOk)
 
         // Can be answered with conversation.
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/NCStmTestModelSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/NCStmTestModelSpec.scala
index dee3675..842aca4 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/NCStmTestModelSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/NCStmTestModelSpec.scala
@@ -19,39 +19,15 @@ package org.apache.nlpcraft.models.stm
 
 import java.io.IOException
 
-import org.apache.nlpcraft.common.NCException
-import org.apache.nlpcraft.model.tools.embedded.NCEmbeddedProbe
-import org.apache.nlpcraft.model.tools.test.{NCTestClient, NCTestClientBuilder}
+import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
 import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue}
-import org.junit.jupiter.api.{AfterEach, BeforeEach, Test}
+import org.junit.jupiter.api.Test
 
 /**
  *
  */
-class NCStmTestModelSpec {
-    private var cli: NCTestClient = _
-
-    @BeforeEach
-    @throws[NCException]
-    @throws[IOException]
-    private[stm] def setUp(): Unit = {
-        NCEmbeddedProbe.start(classOf[NCStmTestModel])
-
-        cli = new NCTestClientBuilder().newBuilder.build
-
-        cli.open("nlpcraft.stm.test") // See phone_model.json
-    }
-
-    @AfterEach
-    @throws[NCException]
-    @throws[IOException]
-    private[stm] def tearDown(): Unit = {
-        if (cli != null)
-            cli.close()
-
-        NCEmbeddedProbe.stop()
-    }
-
+@NCTestEnvironment(model = classOf[NCStmTestModel], startClient = true)
+class NCStmTestModelSpec extends NCTestContext {
     /**
      * @param req
      * @param expResp
@@ -59,7 +35,7 @@ class NCStmTestModelSpec {
      */
     @throws[IOException]
     private def check(req: String, expResp: String): Unit = {
-        val res = cli.ask(req)
+        val res = getClient.ask(req)
 
         assertTrue(res.isOk)
         assertTrue(res.getResult.isPresent)
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestAskSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestAskSpec.scala
index b11b299..b33cb1d 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestAskSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestAskSpec.scala
@@ -17,28 +17,24 @@
 
 package org.apache.nlpcraft.server.rest
 
+import org.apache.nlpcraft.NCTestEnvironment
 import org.apache.nlpcraft.examples.time.TimeModel
-import org.apache.nlpcraft.model.tools.embedded.NCEmbeddedProbe
 import org.junit.jupiter.api.Assertions._
-import org.junit.jupiter.api.{AfterEach, BeforeEach, Test}
+import org.junit.jupiter.api.{BeforeEach, Test}
 
 import scala.collection.JavaConverters._
 
+@NCTestEnvironment(model = classOf[TimeModel], startClient = false)
 class NCRestAskSpec extends NCRestSpec {
     private var usrId: Long = 0
 
     @BeforeEach
     def setUp(): Unit = {
-        NCEmbeddedProbe.start(classOf[TimeModel])
-
         post("user/get")(("$.id", (id: Number) ⇒ usrId = id.longValue()))
 
         assertTrue(usrId > 0)
     }
 
-    @AfterEach
-    def tearDown(): Unit = NCEmbeddedProbe.stop()
-
     @Test
     def testSync(): Unit = {
         post(
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestClearSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestClearSpec.scala
index df7bb51..989045f 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestClearSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestClearSpec.scala
@@ -17,26 +17,22 @@
 
 package org.apache.nlpcraft.server.rest
 
+import org.apache.nlpcraft.NCTestEnvironment
 import org.apache.nlpcraft.examples.time.TimeModel
-import org.apache.nlpcraft.model.tools.embedded.NCEmbeddedProbe
 import org.junit.jupiter.api.Assertions.assertTrue
-import org.junit.jupiter.api.{AfterEach, BeforeEach, Test}
+import org.junit.jupiter.api.{BeforeEach, Test}
 
+@NCTestEnvironment(model = classOf[TimeModel], startClient = false)
 class NCRestClearSpec extends NCRestSpec {
     private var usrId: Long = 0
 
     @BeforeEach
     def setUp(): Unit = {
-        NCEmbeddedProbe.start(classOf[TimeModel])
-
         post("user/get")(("$.id", (id: Number) ⇒ usrId = id.longValue()))
 
         assertTrue(usrId > 0)
     }
 
-    @AfterEach
-    def tearDown(): Unit = NCEmbeddedProbe.stop()
-
     @Test
     def test(): Unit = {
         post("clear/conversation", "mdlId" → "nlpcraft.time.ex")()
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 d5eac07..2c4ef04 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
@@ -17,20 +17,15 @@
 
 package org.apache.nlpcraft.server.rest
 
+import org.apache.nlpcraft.NCTestEnvironment
 import org.apache.nlpcraft.examples.time.TimeModel
-import org.apache.nlpcraft.model.tools.embedded.NCEmbeddedProbe
 import org.junit.jupiter.api.Assertions._
-import org.junit.jupiter.api.{AfterEach, BeforeEach, Disabled, Test}
+import org.junit.jupiter.api.{Disabled, Test}
 
 // Enable it and run if context word server started.
 @Disabled
+@NCTestEnvironment(model = classOf[TimeModel], startClient = false)
 class NCRestModelSpec extends NCRestSpec {
-    @BeforeEach
-    def setUp(): Unit = NCEmbeddedProbe.start(classOf[TimeModel])
-
-    @AfterEach
-    def tearDown(): Unit = NCEmbeddedProbe.stop()
-
     @Test
     def test(): Unit = {
         post("model/sugsyn", "mdlId" → "nlpcraft.time.ex")(
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestProbeSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestProbeSpec.scala
index 7df192b..17329de 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestProbeSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestProbeSpec.scala
@@ -17,18 +17,13 @@
 
 package org.apache.nlpcraft.server.rest
 
+import org.apache.nlpcraft.NCTestEnvironment
 import org.apache.nlpcraft.examples.time.TimeModel
-import org.apache.nlpcraft.model.tools.embedded.NCEmbeddedProbe
 import org.junit.jupiter.api.Assertions._
-import org.junit.jupiter.api.{AfterEach, BeforeEach, Test}
+import org.junit.jupiter.api.Test
 
+@NCTestEnvironment(model = classOf[TimeModel], startClient = false)
 class NCRestProbeSpec extends NCRestSpec {
-    @BeforeEach
-    def setUp(): Unit = NCEmbeddedProbe.start(classOf[TimeModel])
-
-    @AfterEach
-    def tearDown(): Unit = NCEmbeddedProbe.stop()
-
     @Test
     def test(): Unit = {
         post("probe/all")(
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestSpec.scala
index 5eb1970..85f40c3 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestSpec.scala
@@ -29,6 +29,7 @@ import org.apache.http.entity.StringEntity
 import org.apache.http.impl.client.HttpClients
 import org.apache.http.util.EntityUtils
 import org.apache.http.{HttpEntity, HttpResponse}
+import org.apache.nlpcraft.NCTestContext
 import org.junit.jupiter.api.Assertions._
 import org.junit.jupiter.api.{AfterEach, BeforeEach}
 
@@ -121,7 +122,7 @@ private[rest] object NCRestSpec {
 
 import org.apache.nlpcraft.server.rest.NCRestSpec._
 
-private[rest] class NCRestSpec {
+private[rest] class NCRestSpec extends NCTestContext {
     type ResponseContent = java.util.Map[String, Object]
     type ResponseList = java.util.List[ResponseContent]
     type JList[T] = java.util.List[T]


[incubator-nlpcraft] 06/06: Merge branch 'master' into NLPCRAFT-124

Posted by se...@apache.org.
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 3e8056ce6ce69c53924f77bc1e0cde7eb50cf9c9
Merge: c92cf62 74b573e
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Thu Sep 17 02:37:32 2020 -0700

    Merge branch 'master' into NLPCRAFT-124

 .../nlp/core/stanford/NCStanfordCoreManager.scala  |  14 +-
 .../nlp/core/stanford/NCStanfordNerEnricher.scala  |  19 ++-
 .../nlp/core/stanford/NCStanfordParser.scala       |  13 +-
 .../org/apache/nlpcraft/common/NCService.scala     |  53 ++++---
 .../common/extcfg/NCExternalConfigManager.scala    |  15 +-
 .../common/nlp/core/NCNlpCoreManager.scala         |  21 ++-
 .../nlp/core/opennlp/NCOpenNlpTokenizer.scala      |  25 +++-
 .../common/nlp/dict/NCDictionaryManager.scala      |  12 +-
 .../common/nlp/numeric/NCNumericManager.scala      |  10 +-
 .../org/apache/nlpcraft/common/util/NCUtils.scala  |  19 +--
 .../model/intent/impl/NCIntentSolver.scala         |   4 +-
 .../test/impl/NCTestAutoModelValidatorImpl.scala   |   5 +-
 .../nlpcraft/probe/mgrs/NCProbeSynonym.scala       |   5 +-
 .../nlpcraft/probe/mgrs/cmd/NCCommandManager.scala |  18 +++
 .../probe/mgrs/conn/NCConnectionManager.scala      |   4 +-
 .../mgrs/conversation/NCConversationManager.scala  |  13 +-
 .../probe/mgrs/deploy/NCDeployManager.scala        | 159 ++++++++++-----------
 .../mgrs/dialogflow/NCDialogFlowManager.scala      |  13 +-
 .../probe/mgrs/lifecycle/NCLifecycleManager.scala  |  22 ++-
 .../nlpcraft/probe/mgrs/model/NCModelManager.scala |  32 +++--
 .../nlpcraft/probe/mgrs/nlp/NCProbeEnricher.scala  |   3 +-
 .../probe/mgrs/nlp/NCProbeEnrichmentManager.scala  |  35 +++--
 .../dictionary/NCDictionaryEnricher.scala          |  23 +--
 .../mgrs/nlp/enrichers/limit/NCLimitEnricher.scala |  16 ++-
 .../mgrs/nlp/enrichers/model/NCModelEnricher.scala |  13 +-
 .../enrichers/relation/NCRelationEnricher.scala    |  14 +-
 .../mgrs/nlp/enrichers/sort/NCSortEnricher.scala   |  19 ++-
 .../enrichers/stopword/NCStopWordEnricher.scala    |  37 +++--
 .../suspicious/NCSuspiciousNounsEnricher.scala     |  13 +-
 .../mgrs/nlp/validate/NCValidateManager.scala      |  17 ++-
 .../nlpcraft/server/company/NCCompanyManager.scala |  17 ++-
 .../server/feedback/NCFeedbackManager.scala        |  15 +-
 .../apache/nlpcraft/server/geo/NCGeoManager.scala  |  26 ++--
 .../geo/tools/NCGeoSyntheticNamesGenerator.scala   |   3 +-
 .../lifecycle/NCServerLifecycleManager.scala       |  21 ++-
 .../server/nlp/core/NCNlpNerEnricher.scala         |   4 +-
 .../server/nlp/core/NCNlpServerManager.scala       |  13 +-
 .../nlp/core/google/NCGoogleNerEnricher.scala      |  23 ++-
 .../nlp/core/opennlp/NCOpenNlpNerEnricher.scala    |  25 +++-
 .../server/nlp/core/opennlp/NCOpenNlpParser.scala  |  19 ++-
 .../server/nlp/core/spacy/NCSpaCyNerEnricher.scala |  21 ++-
 .../nlp/enrichers/NCServerEnrichmentManager.scala  |  14 +-
 .../nlp/enrichers/basenlp/NCBaseNlpEnricher.scala  |  26 +++-
 .../coordinate/NCCoordinatesEnricher.scala         |  19 ++-
 .../server/nlp/enrichers/date/NCDateEnricher.scala | 131 +++++++++--------
 .../server/nlp/enrichers/geo/NCGeoEnricher.scala   |  21 ++-
 .../nlp/enrichers/numeric/NCNumericEnricher.scala  |  23 ++-
 .../nlp/enrichers/quote/NCQuoteEnricher.scala      |  23 ++-
 .../enrichers/stopword/NCStopWordEnricher.scala    |  16 ++-
 .../server/nlp/preproc/NCPreProcessManager.scala   |  17 ++-
 .../server/nlp/spell/NCSpellCheckManager.scala     |  19 ++-
 .../server/nlp/wordnet/NCWordNetManager.scala      |  16 ++-
 .../nlpcraft/server/probe/NCProbeManager.scala     |  18 +--
 .../server/proclog/NCProcessLogManager.scala       |  13 +-
 .../nlpcraft/server/query/NCQueryManager.scala     |  21 ++-
 .../nlpcraft/server/rest/NCBasicRestApi.scala      |  16 +--
 .../nlpcraft/server/rest/NCRestManager.scala       |  15 +-
 .../apache/nlpcraft/server/sql/NCSqlManager.scala  |  16 ++-
 .../server/sugsyn/NCSuggestSynonymManager.scala    |  15 +-
 .../apache/nlpcraft/server/tx/NCTxManager.scala    |  29 ++--
 .../nlpcraft/server/user/NCUserManager.scala       |  13 +-
 61 files changed, 896 insertions(+), 438 deletions(-)


[incubator-nlpcraft] 05/06: WIP.

Posted by se...@apache.org.
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 c92cf62ac85b74d6943f257b11763e83a1e57522
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Thu Sep 17 12:18:36 2020 +0300

    WIP.
---
 .../org/apache/nlpcraft/NCTestEnvironment.java     |  9 +++++
 .../nlpcraft/examples/sql/NCSqlModelSpec.scala     | 27 ++++---------
 .../mgrs/nlp/enrichers/NCEnricherBaseSpec.scala    | 45 ++++-----------------
 .../nlp/enrichers/limit/NCEnricherLimitSpec.scala  |  7 ++--
 .../model/NCEnricherNestedModelSpec.scala          | 34 ++++++++++++++--
 .../nlp/enrichers/model/NCNestedTestModel.scala    | 47 ----------------------
 .../relation/NCEnricherRelationSpec.scala          |  7 ++--
 .../nlp/enrichers/sort/NCEnricherSortSpec.scala    |  9 ++---
 .../nlpcraft/server/rest/NCRestProbeSpec.scala     |  3 +-
 9 files changed, 67 insertions(+), 121 deletions(-)

diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestEnvironment.java b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestEnvironment.java
index 2461ee6..8388991 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestEnvironment.java
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestEnvironment.java
@@ -31,6 +31,15 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
 @Retention(value=RUNTIME)
 @Target(value = {METHOD, TYPE})
 public @interface NCTestEnvironment {
+    /**
+     *
+     * @return
+     */
     Class<? extends NCModel> model();
+
+    /**
+     *
+     * @return
+     */
     boolean startClient() default false;
 }
\ No newline at end of file
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/examples/sql/NCSqlModelSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/examples/sql/NCSqlModelSpec.scala
index ffb2ea5..40987f5 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/examples/sql/NCSqlModelSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/examples/sql/NCSqlModelSpec.scala
@@ -19,11 +19,12 @@ package org.apache.nlpcraft.examples.sql
 
 import java.util
 
+import org.apache.nlpcraft.NCTestEnvironment
 import org.apache.nlpcraft.examples.sql.db.SqlServer
 import org.apache.nlpcraft.model.NCElement
 import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.NCTestSortTokenType._
-import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{NCDefaultTestModel, NCEnricherBaseSpec, NCTestDateToken ⇒ dte, NCTestLimitToken ⇒ lim, NCTestNlpToken ⇒ nlp, NCTestSortToken ⇒ srt, NCTestUserToken ⇒ usr}
-import org.junit.jupiter.api.{AfterEach, BeforeEach, Test}
+import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{NCDefaultTestModel, NCEnricherBaseSpec, NCTestDateToken => dte, NCTestLimitToken => lim, NCTestNlpToken => nlp, NCTestSortToken => srt, NCTestUserToken => usr}
+import org.junit.jupiter.api.Test
 
 class NCSqlModelWrapper extends NCDefaultTestModel {
     private val delegate = new SqlModel()
@@ -32,24 +33,12 @@ class NCSqlModelWrapper extends NCDefaultTestModel {
     override def getMacros: util.Map[String, String] = delegate.getMacros
 }
 
+@NCTestEnvironment(model = classOf[NCSqlModelWrapper], startClient = true)
 class NCSqlModelSpec extends NCEnricherBaseSpec {
-    override def getModelClass: Option[Class[_ <: NCDefaultTestModel]] = Some(classOf[NCSqlModelWrapper])
-
-    @BeforeEach
-    override def setUp(): Unit = {
-        // org.apache.nlpcraft.examples.sql.SqlModel.SqlModel initialized via DB.
-        // (org.apache.nlpcraft.examples.sql.db.SqlValueLoader configured in its model yaml file.)
-        SqlServer.start()
-
-        super.setUp()
-    }
-
-    @AfterEach
-    override def tearDown(): Unit = {
-        super.tearDown()
-
-        SqlServer.stop()
-    }
+    // org.apache.nlpcraft.examples.sql.SqlModel.SqlModel initialized via DB.
+    // (org.apache.nlpcraft.examples.sql.db.SqlValueLoader configured in its model yaml file.)
+    override protected def preProbeStart(): Unit = SqlServer.start()
+    override protected def afterProbeStop(): Unit = SqlServer.stop()
 
     /**
       *
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
index bb0548c..cfd39d0 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
@@ -17,47 +17,14 @@
 
 package org.apache.nlpcraft.probe.mgrs.nlp.enrichers
 
-import org.apache.nlpcraft.model.tools.embedded.NCEmbeddedProbe
-import org.apache.nlpcraft.model.tools.test.{NCTestClient, NCTestClientBuilder}
+import org.apache.nlpcraft.NCTestContext
 import org.junit.jupiter.api.Assertions.{assertTrue, fail}
-import org.junit.jupiter.api.{AfterEach, BeforeEach}
 import org.scalatest.Assertions
 
 /**
   * Enrichers tests utility base class.
   */
-class NCEnricherBaseSpec {
-    private var client: NCTestClient = _
-
-    def getModelClass: Option[Class[_ <: NCDefaultTestModel]] = Some(classOf[NCDefaultTestModel])
-
-    @BeforeEach
-    protected def setUp(): Unit = {
-        val mdlId = NCDefaultTestModel.ID
-
-        getModelClass match {
-            case Some(claxx) ⇒
-                println(s"Embedded probe is going to start with model [id=$mdlId, class=${claxx.getName}]")
-
-                NCEmbeddedProbe.start(claxx)
-
-            case None ⇒
-                println(s"Probe should be already started as external process: $mdlId")
-        }
-
-        client = new NCTestClientBuilder().newBuilder.setResponseLog(false).build
-
-        client.open(mdlId)
-    }
-
-    @AfterEach
-    protected def tearDown(): Unit = {
-        if (client != null)
-            client.close()
-
-        NCEmbeddedProbe.stop()
-    }
-
+abstract class NCEnricherBaseSpec extends NCTestContext {
     /**
       * Checks single variant.
       *
@@ -65,7 +32,9 @@ class NCEnricherBaseSpec {
       * @param expToks Expected tokens.
       */
     protected def checkExists(txt: String, expToks: NCTestToken*): Unit = {
-        val res = client.ask(txt)
+        val cli = getClient
+
+        val res = cli.ask(txt)
 
         if (res.isFailed)
             fail(s"Result failed [" +
@@ -95,7 +64,9 @@ class NCEnricherBaseSpec {
       * @param expToks
       */
     protected def checkAll(txt: String, expToks: Seq[NCTestToken]*): Unit = {
-        val res = client.ask(txt)
+        val cli = getClient
+
+        val res = cli.ask(txt)
 
         if (res.isFailed)
             fail(s"Result failed [" +
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala
index d882790..00f21e6 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala
@@ -17,19 +17,21 @@
 
 package org.apache.nlpcraft.probe.mgrs.nlp.enrichers.limit
 
-import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{NCEnricherBaseSpec, NCTestLimitToken ⇒ lim, NCTestUserToken ⇒ usr}
+import org.apache.nlpcraft.NCTestEnvironment
+import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{NCDefaultTestModel, NCEnricherBaseSpec, NCTestLimitToken => lim, NCTestUserToken => usr}
 import org.junit.jupiter.api.Test
 
 /**
   * Limit enricher test.
   */
+@NCTestEnvironment(model = classOf[NCDefaultTestModel], startClient = true)
 class NCEnricherLimitSpec extends NCEnricherBaseSpec {
     /**
       *
       * @throws Exception
       */
     @Test
-    def test(): Unit = {
+    def test(): Unit =
         runBatch(
             _ ⇒ checkExists(
                 "top A",
@@ -52,5 +54,4 @@ class NCEnricherLimitSpec extends NCEnricherBaseSpec {
                 usr(text = "A B", id = "AB")
             )
         )
-    }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec.scala
index ac426c6..ddeab09 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec.scala
@@ -17,17 +17,44 @@
 
 package org.apache.nlpcraft.probe.mgrs.nlp.enrichers.model
 
+import java.util
+import java.util.Collections
+
+import org.apache.nlpcraft.NCTestEnvironment
+import org.apache.nlpcraft.model.NCElement
 import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{NCDefaultTestModel, NCEnricherBaseSpec, NCTestUserToken ⇒ usr}
 import org.junit.jupiter.api.Test
 
+import scala.collection.JavaConverters._
+
+/**
+  * Nested Elements test model.
+  */
+class NCNestedTestModel extends NCDefaultTestModel {
+    override def getElements: util.Set[NCElement] =
+        Set(
+            mkElement("x1", "{test|*} ^^id == 'nlpcraft:date'^^"),
+            mkElement("x2", "{test1|*} ^^id == 'x1'^^"),
+            mkElement("x3", "{test2|*} ^^id == 'x2'^^"),
+            mkElement("y1", "y"),
+            mkElement("y2", "^^id == 'y1'^^"),
+            mkElement("y3", "^^id == 'y2'^^ ^^id == 'y2'^^")
+        ).asJava
+
+    private def mkElement(id: String, syn: String): NCElement =
+        new NCElement {
+            override def getId: String = id
+            override def getSynonyms: util.List[String] = Collections.singletonList(syn)
+        }
+}
+
 /**
  * Nested elements model enricher test.
  */
+@NCTestEnvironment(model = classOf[NCNestedTestModel], startClient = true)
 class NCEnricherNestedModelSpec extends NCEnricherBaseSpec {
-    override def getModelClass: Option[Class[_ <: NCDefaultTestModel]] = Some(classOf[NCNestedTestModel])
-
     @Test
-    def test(): Unit = {
+    def test(): Unit =
         runBatch(
             _ ⇒ checkExists(
                 "tomorrow",
@@ -43,5 +70,4 @@ class NCEnricherNestedModelSpec extends NCEnricherBaseSpec {
                 usr(text = "y y", id = "y3")
             )
         )
-    }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCNestedTestModel.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCNestedTestModel.scala
deleted file mode 100644
index 8d6b9df..0000000
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCNestedTestModel.scala
+++ /dev/null
@@ -1,47 +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
- *
- *      http://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.probe.mgrs.nlp.enrichers.model
-
-import java.util
-import java.util.Collections
-
-import org.apache.nlpcraft.model._
-import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.NCDefaultTestModel
-
-import scala.collection.JavaConverters._
-
-/**
-  * Nested Elements test model.
-  */
-class NCNestedTestModel extends NCDefaultTestModel {
-    override def getElements: util.Set[NCElement] =
-        Set(
-            mkElement("x1", "{test|*} ^^id == 'nlpcraft:date'^^"),
-            mkElement("x2", "{test1|*} ^^id == 'x1'^^"),
-            mkElement("x3", "{test2|*} ^^id == 'x2'^^"),
-            mkElement("y1", "y"),
-            mkElement("y2", "^^id == 'y1'^^"),
-            mkElement("y3", "^^id == 'y2'^^ ^^id == 'y2'^^")
-        ).asJava
-
-    private def mkElement(id: String, syn: String): NCElement =
-        new NCElement {
-            override def getId: String = id
-            override def getSynonyms: util.List[String] = Collections.singletonList(syn)
-        }
-}
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/relation/NCEnricherRelationSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/relation/NCEnricherRelationSpec.scala
index 0b31149..73e3b20 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/relation/NCEnricherRelationSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/relation/NCEnricherRelationSpec.scala
@@ -17,19 +17,21 @@
 
 package org.apache.nlpcraft.probe.mgrs.nlp.enrichers.relation
 
-import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{NCEnricherBaseSpec, NCTestNlpToken ⇒ nlp, NCTestRelationToken ⇒ rel, NCTestUserToken ⇒ usr}
+import org.apache.nlpcraft.NCTestEnvironment
+import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{NCDefaultTestModel, NCEnricherBaseSpec, NCTestNlpToken ⇒ nlp, NCTestRelationToken ⇒ rel, NCTestUserToken ⇒ usr}
 import org.junit.jupiter.api.Test
 
 /**
   * Relation enricher test.
   */
+@NCTestEnvironment(model = classOf[NCDefaultTestModel], startClient = true)
 class NCEnricherRelationSpec extends NCEnricherBaseSpec {
     /**
       *
       * @throws Exception
       */
     @Test
-    def test(): Unit = {
+    def test(): Unit =
         runBatch(
             _ ⇒ checkExists(
                 "compare V1 and V2",
@@ -39,5 +41,4 @@ class NCEnricherRelationSpec extends NCEnricherBaseSpec {
                 usr(text = "V2", id = "V")
             )
         )
-    }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCEnricherSortSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCEnricherSortSpec.scala
index cf2081e..cc03066 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCEnricherSortSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCEnricherSortSpec.scala
@@ -17,18 +17,15 @@
 
 package org.apache.nlpcraft.probe.mgrs.nlp.enrichers.sort
 
+import org.apache.nlpcraft.NCTestEnvironment
 import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.NCTestSortTokenType._
-import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{
-    NCEnricherBaseSpec,
-    NCTestNlpToken ⇒ nlp,
-    NCTestSortToken ⇒ srt,
-    NCTestUserToken ⇒ usr
-}
+import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{NCDefaultTestModel, NCEnricherBaseSpec, NCTestNlpToken ⇒ nlp, NCTestSortToken ⇒ srt, NCTestUserToken ⇒ usr}
 import org.junit.jupiter.api.Test
 
 /**
  * Sort enricher test.
  */
+@NCTestEnvironment(model = classOf[NCDefaultTestModel], startClient = true)
 class NCEnricherSortSpec extends NCEnricherBaseSpec {
     /**
      *
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestProbeSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestProbeSpec.scala
index 17329de..0de88a5 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestProbeSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestProbeSpec.scala
@@ -25,10 +25,9 @@ import org.junit.jupiter.api.Test
 @NCTestEnvironment(model = classOf[TimeModel], startClient = false)
 class NCRestProbeSpec extends NCRestSpec {
     @Test
-    def test(): Unit = {
+    def test(): Unit =
         post("probe/all")(
             ("$.probes", (probes: ResponseList) ⇒ assertFalse(probes.isEmpty)),
             ("$.probes[:1].hostName", (names: JList[String]) ⇒ assertNotNull(names.get(0)))
         )
-    }
 }


[incubator-nlpcraft] 03/06: Merge branch 'master' into NLPCRAFT-124

Posted by se...@apache.org.
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 cd7340fc4ab4fbd06fb32a962882cd5b69bc5368
Merge: 4a9b645 f3c305c
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Thu Sep 17 10:44:54 2020 +0300

    Merge branch 'master' into NLPCRAFT-124

 .../apache/nlpcraft/model/intent/impl/NCIntentSolverVariant.scala   | 6 +++---
 .../apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala   | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)


[incubator-nlpcraft] 01/06: WIP.

Posted by se...@apache.org.
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 bdfe2bc536bc6067dd0d30466c5e2b43eaa2da80
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Wed Sep 16 19:12:47 2020 +0300

    WIP.
---
 ...CConversationSpec.scala => NCTestContext.scala} | 52 +++++++++-------------
 .../org/apache/nlpcraft/NCTestContextModel.java    | 32 +++++++++++++
 .../model/conversation/NCConversationSpec.scala    | 27 ++---------
 3 files changed, 56 insertions(+), 55 deletions(-)

diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContext.scala
similarity index 52%
copy from nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala
copy to nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContext.scala
index 198f47c..05d1937 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContext.scala
@@ -15,57 +15,47 @@
  * limitations under the License.
  */
 
-package org.apache.nlpcraft.model.conversation
+package org.apache.nlpcraft
 
 import java.io.IOException
 
 import org.apache.nlpcraft.common.NCException
-import org.apache.nlpcraft.examples.weather.WeatherModel
+import org.apache.nlpcraft.model.NCModel
 import org.apache.nlpcraft.model.tools.embedded.NCEmbeddedProbe
 import org.apache.nlpcraft.model.tools.test.{NCTestClient, NCTestClientBuilder}
-import org.junit.jupiter.api.Assertions.assertTrue
-import org.junit.jupiter.api.{AfterEach, BeforeEach, Test}
+import org.apache.nlpcraft.probe.mgrs.model.NCModelManager
+import org.junit.jupiter.api.{AfterEach, BeforeEach, TestInfo}
 
 /**
-  * @see WeatherModel
+  *
   */
-class NCConversationSpec {
-    private var cli: NCTestClient = _
+class NCTestContext {
+    protected var cli: NCTestClient = _
 
     @BeforeEach
     @throws[NCException]
     @throws[IOException]
-    private[conversation] def setUp(): Unit = {
-        NCEmbeddedProbe.start(classOf[WeatherModel])
+    private def setUp(ti: TestInfo): Unit = {
+        if (ti.getTestMethod.isPresent) {
+            val a = ti.getTestMethod.get().getAnnotation(classOf[NCTestContextModel])
 
-        cli = new NCTestClientBuilder().newBuilder.build
+            if (a != null) {
+                NCEmbeddedProbe.start(a.value().asInstanceOf[Class[NCModel]])
 
-        cli.open("nlpcraft.weather.ex") // See weather_model.json
+                cli = new NCTestClientBuilder().newBuilder.build
+
+                cli.open(NCModelManager.getAllModels().head.model.getId)
+            }
+        }
     }
 
     @AfterEach
     @throws[NCException]
     @throws[IOException]
-    private[conversation] def tearDown(): Unit = {
-        if (cli != null)
+    private def tearDown(): Unit =
+        if (cli != null) {
             cli.close()
 
-        NCEmbeddedProbe.stop()
-    }
-
-    @Test
-    @throws[NCException]
-    @throws[IOException]
-    private[conversation] def test(): Unit = {
-        assertTrue(cli.ask("What's the weather in Moscow?").isOk)
-
-        // Can be answered with conversation.
-        assertTrue(cli.ask("Chance of snow?").isOk)
-        assertTrue(cli.ask("Moscow").isOk)
-
-        cli.clearConversation()
-
-        // Cannot be answered without conversation.
-        assertTrue(cli.ask("Moscow").isFailed)
-    }
+            NCEmbeddedProbe.stop()
+        }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContextModel.java b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContextModel.java
new file mode 100644
index 0000000..c58bd5f
--- /dev/null
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContextModel.java
@@ -0,0 +1,32 @@
+/*
+ * 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
+ *
+ *      http://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 java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Documented
+@Retention(value=RUNTIME)
+@Target(value=METHOD)
+public @interface NCTestContextModel {
+    Class value();
+}
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala
index 198f47c..61bee87 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/conversation/NCConversationSpec.scala
@@ -19,6 +19,7 @@ package org.apache.nlpcraft.model.conversation
 
 import java.io.IOException
 
+import org.apache.nlpcraft.{NCTestContext, NCTestContextModel}
 import org.apache.nlpcraft.common.NCException
 import org.apache.nlpcraft.examples.weather.WeatherModel
 import org.apache.nlpcraft.model.tools.embedded.NCEmbeddedProbe
@@ -29,33 +30,11 @@ import org.junit.jupiter.api.{AfterEach, BeforeEach, Test}
 /**
   * @see WeatherModel
   */
-class NCConversationSpec {
-    private var cli: NCTestClient = _
-
-    @BeforeEach
-    @throws[NCException]
-    @throws[IOException]
-    private[conversation] def setUp(): Unit = {
-        NCEmbeddedProbe.start(classOf[WeatherModel])
-
-        cli = new NCTestClientBuilder().newBuilder.build
-
-        cli.open("nlpcraft.weather.ex") // See weather_model.json
-    }
-
-    @AfterEach
-    @throws[NCException]
-    @throws[IOException]
-    private[conversation] def tearDown(): Unit = {
-        if (cli != null)
-            cli.close()
-
-        NCEmbeddedProbe.stop()
-    }
-
+class NCConversationSpec extends NCTestContext {
     @Test
     @throws[NCException]
     @throws[IOException]
+    @NCTestContextModel(value = classOf[WeatherModel])
     private[conversation] def test(): Unit = {
         assertTrue(cli.ask("What's the weather in Moscow?").isOk)
 


[incubator-nlpcraft] 02/06: WIP.

Posted by se...@apache.org.
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 4a9b645e35ad2e8e320c8b3305fb07e104f46603
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Wed Sep 16 19:54:10 2020 +0300

    WIP.
---
 .../scala/org/apache/nlpcraft/NCTestContext.scala  | 26 +++++++++++++++++-----
 .../org/apache/nlpcraft/NCTestContextModel.java    |  4 +++-
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContext.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContext.scala
index 05d1937..7003cc4 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContext.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContext.scala
@@ -24,23 +24,29 @@ import org.apache.nlpcraft.model.NCModel
 import org.apache.nlpcraft.model.tools.embedded.NCEmbeddedProbe
 import org.apache.nlpcraft.model.tools.test.{NCTestClient, NCTestClientBuilder}
 import org.apache.nlpcraft.probe.mgrs.model.NCModelManager
-import org.junit.jupiter.api.{AfterEach, BeforeEach, TestInfo}
+import org.junit.jupiter.api.TestInstance.Lifecycle
+import org.junit.jupiter.api.{AfterEach, BeforeAll, BeforeEach, TestInfo, TestInstance}
 
 /**
   *
   */
+@TestInstance(Lifecycle.PER_CLASS)
 class NCTestContext {
     protected var cli: NCTestClient = _
 
+    private var probeStarted = false
+
     @BeforeEach
     @throws[NCException]
     @throws[IOException]
-    private def setUp(ti: TestInfo): Unit = {
+    private def beforeEach(ti: TestInfo): Unit = {
         if (ti.getTestMethod.isPresent) {
             val a = ti.getTestMethod.get().getAnnotation(classOf[NCTestContextModel])
 
             if (a != null) {
-                NCEmbeddedProbe.start(a.value().asInstanceOf[Class[NCModel]])
+                probeStarted = false
+                NCEmbeddedProbe.start(a.value())
+                probeStarted = true
 
                 cli = new NCTestClientBuilder().newBuilder.build
 
@@ -52,10 +58,20 @@ class NCTestContext {
     @AfterEach
     @throws[NCException]
     @throws[IOException]
-    private def tearDown(): Unit =
-        if (cli != null) {
+    private def afterEach(): Unit =
+        if (cli != null)
             cli.close()
 
+        if (probeStarted) {
             NCEmbeddedProbe.stop()
+
+            probeStarted = false
         }
+
+    @BeforeAll
+    @throws[NCException]
+    @throws[IOException]
+    private def beforeAll(ti: TestInfo): Unit = {
+        println("!!!ti=" + ti)
+    }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContextModel.java b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContextModel.java
index c58bd5f..5537fc7 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContextModel.java
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/NCTestContextModel.java
@@ -17,6 +17,8 @@
 
 package org.apache.nlpcraft;
 
+import org.apache.nlpcraft.model.NCModel;
+
 import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
@@ -28,5 +30,5 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
 @Retention(value=RUNTIME)
 @Target(value=METHOD)
 public @interface NCTestContextModel {
-    Class value();
+    Class<? extends NCModel> value();
 }