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/05/18 20:44:12 UTC
[incubator-nlpcraft] 02/02: CR,
This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch NLPCRAFT-30
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
commit c6c1719a3b664858da442084c0ac954db4af4713
Author: Aaron Radzinzski <ar...@datalingvo.com>
AuthorDate: Mon May 18 13:44:04 2020 -0700
CR,
---
src/main/resources/nlpcraft.conf | 12 ++++----
.../model/tools/test/NCTestClientBuilder.java | 15 ++++++----
.../mgrs/nlp/enrichers/NCEnricherBaseSpec.scala | 34 +++++++++++++++++-----
.../mgrs/nlp/enrichers/NCEnrichersTestBeans.scala | 4 +--
.../nlp/enrichers/sort/NCEnricherSortSpec.scala | 7 ++++-
5 files changed, 49 insertions(+), 23 deletions(-)
diff --git a/src/main/resources/nlpcraft.conf b/src/main/resources/nlpcraft.conf
index b9d2bd0..70674c8 100644
--- a/src/main/resources/nlpcraft.conf
+++ b/src/main/resources/nlpcraft.conf
@@ -230,16 +230,14 @@ nlpcraft {
# Fully qualified class names for models that will be instantiated.
# Must be on the active class path for the probe.
# Can be empty but then 'jarsFolder' must be provided.
- #
- # NOTE: These is an example.
- # Start data probe with this configuration file to deploy example data model.
models = [
+ # Example of listing model for probe to start with.
"org.apache.nlpcraft.examples.echo.EchoModel"
- // Requires 'google' on the server side.
- // See https://nlpcraft.apache.org/integrations.html#nlp for more details
- // on how to configure 3rd party token providers.
- // "org.apache.nlpcraft.examples.phone.PhoneModel"
+ # Note that following models requires 'google' on the server side.
+ # See https://nlpcraft.apache.org/integrations.html#nlp for more details
+ # on how to configure 3rd party token providers.
+ # "org.apache.nlpcraft.examples.phone.PhoneModel"
]
# Specify class names for probe life cycle components.
diff --git a/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestClientBuilder.java b/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestClientBuilder.java
index 7ad9f72..ad9b7a5 100644
--- a/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestClientBuilder.java
+++ b/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestClientBuilder.java
@@ -153,7 +153,12 @@ public class NCTestClientBuilder {
return this;
}
- // TODO: add description.
+ /**
+ * Sets whether or not to log responses from the probe.
+ *
+ * @param respLog {@code True} to log responses, {@code false} otherwise.
+ * @return Builder instance for chaining calls.
+ */
public NCTestClientBuilder setResponseLog(boolean respLog) {
impl.setResponseLog(respLog);
@@ -361,7 +366,7 @@ public class NCTestClientBuilder {
/**
* Client implementation.
*/
- private class NCTestClientImpl implements NCTestClient {
+ private static class NCTestClientImpl implements NCTestClient {
private static final String STATUS_API_OK = "API_OK";
private final Type TYPE_RESP = new TypeToken<HashMap<String, Object>>() {}.getType();
@@ -384,7 +389,7 @@ public class NCTestClientBuilder {
private volatile boolean opened = false;
private volatile boolean closed = false;
- private Map<String, NCEmbeddedResult> embeddedResMap = new ConcurrentHashMap<>();
+ private final Map<String, NCEmbeddedResult> embeddedResMap = new ConcurrentHashMap<>();
private Consumer<NCEmbeddedResult> embeddedCb;
@@ -807,7 +812,7 @@ public class NCTestClientBuilder {
post.setHeader("Content-Type", "application/json");
post.setEntity(entity);
- ResponseHandler<String> respHdlr = resp -> {
+ ResponseHandler<String> respHdl = resp -> {
int code = resp.getStatusLine().getStatusCode();
HttpEntity e = resp.getEntity();
@@ -827,7 +832,7 @@ public class NCTestClientBuilder {
}
};
- return httpCli.execute(post, respHdlr);
+ return httpCli.execute(post, respHdl);
}
finally {
post.releaseConnection();
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 aeb2d80..bba8fe5 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
@@ -61,13 +61,16 @@ class NCEnricherBaseSpec {
* Checks single variant.
*
* @param txt
- * @param expToks
+ * @param expToks Expected tokens.
*/
protected def checkExists(txt: String, expToks: NCTestToken*): Unit = {
val res = client.ask(txt)
if (res.isFailed)
- fail(s"Result failed [text=$txt, error=${res.getResultError.get()}]")
+ fail(s"Result failed [" +
+ s"text=$txt, " +
+ s"error=${res.getResultError.get()}" +
+ s"]")
assertTrue(res.getResult.isPresent, s"Missed result data")
@@ -76,7 +79,11 @@ class NCEnricherBaseSpec {
assertTrue(
sens.contains(expSen),
- s"Required sentence not found [request=$txt, \nexpected=\n$expSen, \nfound=\n${sens.mkString("\n")}\n]"
+ s"Required token sequence not found [" +
+ s"request=$txt, " +
+ s"\nexpected=\n$expSen, " +
+ s"\nfound=\n${sens.mkString("\n")}" +
+ "\n]"
)
}
@@ -90,7 +97,10 @@ class NCEnricherBaseSpec {
val res = client.ask(txt)
if (res.isFailed)
- fail(s"Result failed [text=$txt, error=${res.getResultError.get()}]")
+ fail(s"Result failed [" +
+ s"text=$txt, " +
+ s"error=${res.getResultError.get()}" +
+ s"]")
assertTrue(res.getResult.isPresent, s"Missed result data")
@@ -99,13 +109,21 @@ class NCEnricherBaseSpec {
require(
expSens.size == sens.size,
- s"Unexpected response size [request=$txt, expected=${expSens.size}, received=${sens.size}]"
+ s"Unexpected response size [" +
+ s"request=$txt, " +
+ s"expected=${expSens.size}, " +
+ s"received=${sens.size}" +
+ s"]"
)
for (expSen ← expSens)
require(
sens.contains(expSen),
- s"Required sentence not found [request=$txt, \nexpected=\n$expSen, \nfound=\n${sens.mkString("\n")}\n]"
+ s"Required token sequence not found [" +
+ s"request=$txt, " +
+ s"\nexpected=\n$expSen, " +
+ s"\nfound=\n${sens.mkString("\n")}" +
+ "\n]"
)
}
@@ -132,9 +150,9 @@ class NCEnricherBaseSpec {
err.printStackTrace(System.out)
}
- Assertions.fail(s"Failed ${errs.size} from ${tests.size} tests. See errors list above.")
+ Assertions.fail(s"\n!!! Failed ${errs.size} from ${tests.size} tests. See errors list above. !!!\n")
}
else
- println(s"All tests passed: ${tests.size}")
+ println(s"\n>>> All ${tests.size} tests passed. <<<\n")
}
}
diff --git a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnrichersTestBeans.scala b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnrichersTestBeans.scala
index 548c559..8ff7e65 100644
--- a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnrichersTestBeans.scala
+++ b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnrichersTestBeans.scala
@@ -34,7 +34,7 @@ import scala.compat.java8.OptionConverters._
sealed trait NCTestToken {
def id: String
- def text: String
+ def text: String // Case-sensitive
def isStop: Boolean = false
}
@@ -48,7 +48,7 @@ case class NCTestNlpToken(text: String, override val isStop: Boolean = false) ex
override def toString: String = s"$text(nlp)<isStop=$isStop>"
}
-// Skip non-deteministric properties verification.
+// Skip non-deterministic properties verification.
case class NCTestDateToken(text: String) extends NCTestToken {
require(text != null)
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 c3afde1..815f7fa 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
@@ -18,7 +18,12 @@
package org.apache.nlpcraft.probe.mgrs.nlp.enrichers.sort
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.{
+ NCEnricherBaseSpec,
+ NCTestNlpToken ⇒ nlp,
+ NCTestSortToken ⇒ srt,
+ NCTestUserToken ⇒ usr
+}
import org.junit.jupiter.api.Test
/**