This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-16
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-16 by this push:
new 4551f6f WIP.
4551f6f is described below
commit 4551f6f170a9723fd20ef9655a0eb372ab1a54a3
Author: Sergey Kamov <[email protected]>
AuthorDate: Mon Mar 16 15:50:02 2020 +0300
WIP.
---
.../nlp/enrichers/post/NCPostEnrichProcessor.scala | 13 +++--
.../mgrs/nlp/enrichers/NCEnricherBaseSpec.scala | 58 ++++++++++++++++------
.../nlp/enrichers/sort/NCEnricherSortSpec.scala | 29 +++++------
3 files changed, 65 insertions(+), 35 deletions(-)
diff --git
a/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/post/NCPostEnrichProcessor.scala
b/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/post/NCPostEnrichProcessor.scala
index 1ecfb14..176e4a6 100644
---
a/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/post/NCPostEnrichProcessor.scala
+++
b/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/post/NCPostEnrichProcessor.scala
@@ -359,16 +359,15 @@ object NCPostEnrichProcessor extends NCService with
LazyLogging {
history.foreach { case (idxOld, idxNew) ⇒ fixed =
fixed.map(_.map(i ⇒ if (i == idxOld) idxNew else i).distinct) }
- if (idxs != fixed) {
- fixed.foreach(p ⇒ require(p.size == 1))
+ fixed.foreach(p ⇒ require(p.size == 1))
- // Fix double dimension array to one dimension.
- n += idxsField →
fixed.map(_.head).asJava.asInstanceOf[java.io.Serializable]
+ // Fix double dimension array to one dimension,
+ // so it should be called always inspite of
fixIndexesReferences method.
+ n += idxsField →
fixed.map(_.head).asJava.asInstanceOf[java.io.Serializable]
- def x(seq: Seq[Seq[Int]]): String = s"[${seq.map(p ⇒
s"[${p.mkString(",")}]").mkString(", ")}]"
+ def x(seq: Seq[Seq[Int]]): String = s"[${seq.map(p ⇒
s"[${p.mkString(",")}]").mkString(", ")}]"
- logger.trace(s"`$noteType` note `indexes` fixed
[old=${x(idxs)}}, new=${x(fixed)}]")
- }
+ logger.trace(s"`$noteType` note `indexes` fixed
[old=${x(idxs)}}, new=${x(fixed)}]")
case None ⇒ // No-op.
}
)
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 4937301..cb8319e 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
@@ -19,8 +19,9 @@ package org.apache.nlpcraft.probe.mgrs.nlp.enrichers
import org.apache.nlpcraft.model.tools.test.{NCTestClient, NCTestClientBuilder}
import org.apache.nlpcraft.probe.embedded.NCEmbeddedProbe
-import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue}
+import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.{AfterEach, BeforeEach}
+import org.scalatest.Assertions
/**
* Enrichers tests utility base class.
@@ -43,48 +44,77 @@ class NCEnricherBaseSpec {
/**
* Checks single variant.
*
- * @param reqTxt
+ * @param txt
* @param expToks
*/
- private[enrichers] def checkExists(reqTxt: String, expToks: NCTestToken*):
Unit = {
- val res = client.ask(reqTxt)
+ private[enrichers] def checkExists(txt: String, expToks: NCTestToken*):
Unit = {
+ val res = client.ask(txt)
- assertTrue(res.isOk)
- assertTrue(res.getResult.isPresent)
+ assertTrue(res.isOk, s"Result is not successful, error:
${res.getResultError.get()}")
+ assertTrue(res.getResult.isPresent, s"Result is not successful, error:
${res.getResultError.get()}")
val sens = NCTestSentence.deserialize(res.getResult.get())
val expSen = NCTestSentence(expToks)
assertTrue(
sens.exists(_ == expSen),
- s"Required sentence not found [expected=$expSen,
found=${sens.mkString("\n")}]"
+ s"Required sentence not found [request=$txt, expected=$expSen,
found=${sens.mkString("\n")}]"
)
}
/**
* Checks multiple variants.
*
- * @param reqTxt
+ * @param txt
* @param expToks
*/
- private[enrichers] def checkAll(reqTxt: String, expToks:
Seq[Seq[NCTestToken]]): Unit = {
- val res = client.ask(reqTxt)
+ private[enrichers] def checkAll(txt: String, expToks:
Seq[Seq[NCTestToken]]): Unit = {
+ val res = client.ask(txt)
- assertTrue(res.isOk)
- assertTrue(res.getResult.isPresent)
+ assertTrue(res.isOk, s"Result is not successful, error:
${res.getResultError.get()}")
+ assertTrue(res.getResult.isPresent, s"Result is not successful, error:
${res.getResultError.get()}")
val expSens = expToks.map(NCTestSentence(_))
val sens = NCTestSentence.deserialize(res.getResult.get())
require(
expSens.size == sens.size,
- s"Unexpected response size [expected=${expSens.size},
received=${sens.size}]"
+ s"Unexpected response size [request=$txt,
expected=${expSens.size}, received=${sens.size}]"
)
for (expSen ← expSens)
require(
sens.exists(_ == expSen),
- s"Required sentence not found [expected=$expSen,
found=${sens.mkString("\n")}]"
+ s"Required sentence not found [request=$txt, expected=$expSen,
found=${sens.mkString("\n")}]"
)
}
+
+ /**
+ *
+ * @param tests
+ */
+ private[enrichers] def runBatch(tests: Unit ⇒ Unit*): Unit = {
+ val errs = tests.zipWithIndex.flatMap { case (test, i) ⇒
+ try {
+ test.apply(())
+
+ None
+ }
+ catch {
+ case e: Throwable ⇒ Some(e, i)
+ }
+ }
+
+ if (errs.nonEmpty) {
+ errs.foreach { case (err, i) ⇒
+ System.err.println(s"${i + 1} test failed.")
+
+ err.printStackTrace()
+ }
+
+ Assertions.fail(s"Failed ${errs.size} tests. See errors list
above.")
+ }
+ else
+ println("All tests passed")
+ }
}
diff --git
a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCEnricherSortSpec.scala
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCEnricherSortSpec.scala
index b02eb0d..47dbc77 100644
---
a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCEnricherSortSpec.scala
+++
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCEnricherSortSpec.scala
@@ -17,7 +17,7 @@
package org.apache.nlpcraft.probe.mgrs.nlp.enrichers.sort
-import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{NCEnricherBaseSpec,
NCTestNlpToken ⇒ Nlp, NCTestSortToken ⇒ Sort, NCTestUserToken ⇒ User}
+import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{NCEnricherBaseSpec,
NCTestNlpToken ⇒ nlp, NCTestSortToken ⇒ sort, NCTestUserToken ⇒ user}
import org.junit.jupiter.api.Test
/**
@@ -29,18 +29,19 @@ class NCEnricherSortSpec extends NCEnricherBaseSpec {
* @throws Exception
*/
@Test
- def test(): Unit = {
- checkExists(
- "sort A",
- Sort(origText = "sort", subjNote = "A", subjIndex = 1),
- User("A", "A")
+ def test(): Unit =
+ runBatch(
+ _ ⇒ checkExists(
+ "sort A",
+ sort(origText = "sort", subjNote = "A", subjIndex = 1),
+ user("A", "A")
+ ),
+ _ ⇒ checkExists(
+ "sort A by A",
+ sort(origText = "sort", subjNote = "A", subjIndex = 1, byNote
= "A", byIndex = 3),
+ user("A", "A"),
+ nlp("by", true),
+ user("A", "A")
+ )
)
- checkExists(
- "sort A by A",
- Sort(origText = "sort", subjNote = "A", subjIndex = 1, byNote =
"A", byIndex = 3),
- User("A", "A"),
- Nlp("by", true),
- User("A", "A")
- )
- }
}