You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2020/03/24 22:11:09 UTC
[incubator-nlpcraft] branch master updated: Fix for NLPCRAFT-24.
This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/master by this push:
new 219211d Fix for NLPCRAFT-24.
219211d is described below
commit 219211dd70ac3e48e87f48f2a7394ec4df649298
Author: Aaron Radzinzski <ar...@datalingvo.com>
AuthorDate: Tue Mar 24 15:11:02 2020 -0700
Fix for NLPCRAFT-24.
---
...herTestModel.scala => NCDefaultTestModel.scala} | 17 +++-----
.../mgrs/nlp/enrichers/NCEnricherBaseSpec.scala | 14 +++----
.../model/NCEnricherNestedModelSpec.scala | 47 ++++++++++++++++++++++
.../nlp/enrichers/model}/NCNestedTestModel.scala | 28 +++++--------
4 files changed, 69 insertions(+), 37 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 83%
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..f0e55fa 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] =
@@ -49,29 +49,24 @@ class NCEnricherTestModel extends NCModelAdapter(ID, "Model enrichers test", "1.
new NCElement {
override def getId: String = id
override def getSynonyms: util.List[String] = syns.asJava
- override def getGroups: util.List[String] = Collections.singletonList(GROUP)
}
private def mkValueElement(id: String, vals: String*): NCElement =
new NCElement {
override def getId: String = id
override def getSynonyms: util.List[String] = Collections.singletonList(id)
- override def getGroups: util.List[String] = Collections.singletonList(GROUP)
override def getValues: util.List[NCValue] = vals.map(v ⇒ new NCValue {
override def getName: String = v
override def getSynonyms: util.List[String] = Collections.singletonList(v)
}).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"
-
- private final val GROUP = "test-enricher-group"
+object NCDefaultTestModel {
+ final val ID = "dflt.enricher.test.model"
}
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..ac426c6
--- /dev/null
+++ b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec.scala
@@ -0,0 +1,47 @@
+/*
+ * 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 = "x3")
+ ),
+ _ ⇒ checkExists(
+ "tomorrow yesterday",
+ usr(text = "tomorrow", id = "x3"),
+ usr(text = "yesterday", id = "x3")
+ ),
+ _ ⇒ checkExists(
+ "y y",
+ usr(text = "y y", id = "y3")
+ )
+ )
+ }
+}
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 58%
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..8d6b9df 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,27 +15,28 @@
* 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'^^"),
- mkElement("x:nested1", "{test1|*} ^^id == 'x:nested'^^"),
- mkElement("x:nested2", "{test2|*} ^^id == 'x:nested1'^^")
+ 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 =
@@ -43,13 +44,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"
}