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

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

commit 9d800f6f36eca9ec238f91bc9d0ce2fb8671adc8
Author: Sergey Kamov <[email protected]>
AuthorDate: Tue Mar 24 16:25:13 2020 +0300

    WIP.
---
 ...herTestModel.scala => NCDefaultTestModel.scala} | 14 +++----
 .../mgrs/nlp/enrichers/NCEnricherBaseSpec.scala    | 14 +++----
 .../model/NCEnricherNestedModelSpec.scala          | 43 ++++++++++++++++++++++
 .../nlp/enrichers/model}/NCNestedTestModel.scala   | 19 ++--------
 4 files changed, 59 insertions(+), 31 deletions(-)

diff --git 
a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherTestModel.scala
 
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCDefaultTestModel.scala
similarity index 90%
rename from 
src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherTestModel.scala
rename to 
src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCDefaultTestModel.scala
index 701372d..5031faf 100644
--- 
a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherTestModel.scala
+++ 
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCDefaultTestModel.scala
@@ -24,12 +24,12 @@ import org.apache.nlpcraft.model.{NCContext, NCElement, 
NCModelAdapter, NCResult
 
 import scala.collection.JavaConverters._
 import scala.language.implicitConversions
-import NCEnricherTestModel._
+import NCDefaultTestModel._
 
 /**
-  * Enrichers test model.
+  * Enrichers default test model.
   */
-class NCEnricherTestModel extends NCModelAdapter(ID, "Model enrichers test", 
"1.0") {
+class NCDefaultTestModel extends NCModelAdapter(ID, "Model enrichers test", 
"1.0") {
     private implicit def convert(s: String): NCResult = NCResult.text(s)
 
     override def getElements: util.Set[NCElement] =
@@ -63,15 +63,13 @@ class NCEnricherTestModel extends NCModelAdapter(ID, "Model 
enrichers test", "1.
             }).asJava
         }
 
-
-    override def onContext(ctx: NCContext): NCResult =
+    override final def onContext(ctx: NCContext): NCResult =
         NCResult.text(
             NCTestSentence.serialize(ctx.getVariants.asScala.map(v ⇒ 
NCTestSentence(v.asScala.map(NCTestToken(_)))))
         )
 }
 
-object NCEnricherTestModel {
-    final val ID = "test.enricher"
-
+object NCDefaultTestModel {
+    final val ID = "dflt.enricher.test.model"
     private final val GROUP = "test-enricher-group"
 }
diff --git 
a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
 
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
index 5a8784d..9f755c9 100644
--- 
a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
+++ 
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
@@ -17,7 +17,6 @@
 
 package org.apache.nlpcraft.probe.mgrs.nlp.enrichers
 
-import org.apache.nlpcraft.model.NCModel
 import org.apache.nlpcraft.model.tools.test.{NCTestClient, NCTestClientBuilder}
 import org.apache.nlpcraft.probe.embedded.NCEmbeddedProbe
 import org.junit.jupiter.api.Assertions.{assertTrue, fail}
@@ -30,25 +29,24 @@ import org.scalatest.Assertions
 class NCEnricherBaseSpec {
     private var client: NCTestClient = _
 
-    // TODO:
-    def getModelClass[T <: NCModel]: Option[Class[NCModel]] = 
Some(classOf[NCEnricherTestModel].asInstanceOf[Class[NCModel]])
+    def getModelClass: Option[Class[_ <: NCDefaultTestModel]] = 
Some(classOf[NCDefaultTestModel])
 
     @BeforeEach
     private[enrichers] def setUp(): Unit = {
+        val mdlId = NCDefaultTestModel.ID
+
         getModelClass match {
             case Some(claxx) ⇒
-                println(s"Embedded probe is going to start with model: $claxx")
+                println(s"Embedded probe is going to start with model: $mdlId")
 
                 NCEmbeddedProbe.start(claxx)
             case None ⇒
-                println("Embedded probe will not be started")
-
-                None
+                println(s"Probe should be already started as external process: 
$mdlId")
         }
 
         client = new 
NCTestClientBuilder().newBuilder.setResponseLog(false).build
 
-        client.open(NCEnricherTestModel.ID)
+        client.open(mdlId)
     }
 
     @AfterEach
diff --git 
a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec.scala
 
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec.scala
new file mode 100644
index 0000000..8afe312
--- /dev/null
+++ 
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec.scala
@@ -0,0 +1,43 @@
+/*
+ * 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 org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{NCDefaultTestModel, 
NCEnricherBaseSpec, NCTestUserToken ⇒ usr}
+import org.junit.jupiter.api.Test
+
+/**
+ * Nested elements model enricher test.
+ */
+class NCEnricherNestedModelSpec extends NCEnricherBaseSpec {
+    override def getModelClass: Option[Class[_ <: NCDefaultTestModel]] = 
Some(classOf[NCNestedTestModel])
+
+    @Test
+    def test(): Unit = {
+        runBatch(
+            _ ⇒ checkExists(
+                "tomorrow",
+                usr(text = "tomorrow", id = "x:nested2")
+            ),
+            _ ⇒ checkExists(
+                "tomorrow tomorrow",
+                usr(text = "tomorrow", id = "x:nested2"),
+                usr(text = "tomorrow", id = "x:nested2")
+            )
+        )
+    }
+}
diff --git 
a/src/test/scala/org/apache/nlpcraft/models/nested/NCNestedTestModel.scala 
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCNestedTestModel.scala
similarity index 68%
rename from 
src/test/scala/org/apache/nlpcraft/models/nested/NCNestedTestModel.scala
rename to 
src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCNestedTestModel.scala
index f55815a..2dfc872 100644
--- a/src/test/scala/org/apache/nlpcraft/models/nested/NCNestedTestModel.scala
+++ 
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCNestedTestModel.scala
@@ -15,22 +15,20 @@
  * limitations under the License.
  */
 
-package org.apache.nlpcraft.models.nested
+package org.apache.nlpcraft.probe.mgrs.nlp.enrichers.model
 
 import java.util
 import java.util.Collections
 
-import org.apache.nlpcraft.model.{NCIntentMatch, _}
+import org.apache.nlpcraft.model._
+import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.NCDefaultTestModel
 
 import scala.collection.JavaConverters._
-import scala.language.implicitConversions
 
 /**
   * Nested Elements test model.
   */
-class NCNestedTestModel extends NCModelAdapter("nlpcraft.nested.test", "Nested 
Elements Test Model", "1.0") {
-    private implicit def convert(s: String): NCResult = NCResult.text(s)
-
+class NCNestedTestModel extends NCDefaultTestModel {
     override def getElements: util.Set[NCElement] =
         Set(
             mkElement("x:nested", "{test|*} ^^id == 'nlpcraft:date'^^"),
@@ -43,13 +41,4 @@ class NCNestedTestModel extends 
NCModelAdapter("nlpcraft.nested.test", "Nested E
             override def getId: String = id
             override def getSynonyms: util.List[String] = 
Collections.singletonList(syn)
         }
-
-    @NCIntent("intent=nested term={id=='x:nested'}")
-    private def onNested(ctx: NCIntentMatch): NCResult = "nested"
-
-    @NCIntent("intent=nested1 term={id=='x:nested1'}")
-    private def onNested1(ctx: NCIntentMatch): NCResult = "nested1"
-
-    @NCIntent("intent=nested2 term={id=='x:nested2'}")
-    private def onNested2(ctx: NCIntentMatch): NCResult = "nested2"
 }

Reply via email to