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/08/16 20:38:41 UTC
[incubator-nlpcraft] branch NLPCRAFT-41 updated: WIP on review.
This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch NLPCRAFT-41
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-41 by this push:
new 5b3d1d7 WIP on review.
5b3d1d7 is described below
commit 5b3d1d7c49245ed6f781329316f2a64933eb0f6e
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Sun Aug 16 13:38:30 2020 -0700
WIP on review.
---
.../apache/nlpcraft/common/socket/NCSocket.scala | 13 +++++++++++
.../model/intent/impl/NCIntentScanner.scala | 5 +++--
.../nlpcraft/model/tools/test/NCTestResult.java | 7 +++++-
.../nlpcraft/probe/embedded/NCEmbeddedResult.java | 7 +++++-
.../probe/mgrs/conn/NCConnectionManager.scala | 26 +++++++++-------------
.../probe/mgrs/deploy/NCDeployManager.scala | 2 +-
.../nlpcraft/probe/mgrs/deploy/NCModelHolder.scala | 7 +++---
.../model/tools/NCSqlModelEngineSpec.scala | 2 +-
8 files changed, 45 insertions(+), 24 deletions(-)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/socket/NCSocket.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/socket/NCSocket.scala
index e2e3b35..f80ad85 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/socket/NCSocket.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/socket/NCSocket.scala
@@ -142,4 +142,17 @@ case class NCSocket(socket: Socket, host: String, soTimeout: Int = 20000) extend
writer.flush()
}
}
+}
+
+object NCSocket {
+ /**
+ * Additional c-tor.
+ *
+ * @param host
+ * @param port
+ * @param soTimeout
+ * @return
+ */
+ def apply(host: String, port: Integer, soTimeout: Int = 20000): NCSocket =
+ NCSocket(new Socket(host, port), host, soTimeout)
}
\ No newline at end of file
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/NCIntentScanner.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/NCIntentScanner.scala
index 3a6b79d..fa42310 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/NCIntentScanner.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/NCIntentScanner.scala
@@ -419,8 +419,9 @@ object NCIntentScanner extends LazyLogging {
.toMap
/**
- * TODO:
- * @param mdl
+ * Scans given model for intent samples.
+ *
+ * @param mdl Model to scan.
*/
@throws[NCE]
def scanIntentsSamples(mdl: NCModel): Map[String, Seq[String]] = {
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestResult.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestResult.java
index 2fff3ec..44157be 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestResult.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestResult.java
@@ -95,6 +95,11 @@ public interface NCTestResult {
return getResult().isPresent() && getResultType().isPresent();
}
- // TODO:
+ /**
+ * Gets ID of the intent that was matched against the input sentence. Only set if {@link #isOk()} method
+ * returns {@code true}.
+ *
+ * @return ID of the matching intent.
+ */
String getIntentId();
}
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/embedded/NCEmbeddedResult.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/embedded/NCEmbeddedResult.java
index 7feb005..fe087e7 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/embedded/NCEmbeddedResult.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/embedded/NCEmbeddedResult.java
@@ -178,6 +178,11 @@ public interface NCEmbeddedResult {
*/
String getLogHolder();
- // TODO:
+ /**
+ * Gets ID of the intent that was matched against the input sentence. Only set if result was
+ * successful.
+ *
+ * @return ID of the matching intent.
+ */
String getIntentId();
}
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conn/NCConnectionManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conn/NCConnectionManager.scala
index 906c9f2..5377cb1 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conn/NCConnectionManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conn/NCConnectionManager.scala
@@ -18,7 +18,7 @@
package org.apache.nlpcraft.probe.mgrs.conn
import java.io.{EOFException, IOException, InterruptedIOException}
-import java.net.{InetAddress, NetworkInterface, Socket}
+import java.net.{InetAddress, NetworkInterface}
import java.util
import java.util.concurrent.CountDownLatch
import java.util.concurrent.atomic.AtomicInteger
@@ -131,7 +131,7 @@ object NCConnectionManager extends NCService {
logger.trace(s"Opening downlink to '$host:$port'")
// Connect down socket.
- val sock = NCSocket(new Socket(host, port), host)
+ val sock = NCSocket(host, port)
sock.write(U.mkSha256Hash(Config.token)) // Hash.
sock.write(NCProbeMessage( // Handshake.
@@ -147,12 +147,10 @@ object NCConnectionManager extends NCService {
val resp = sock.read[NCProbeMessage](cryptoKey) // Get handshake response.
- def err(msg: String) = throw new HandshakeError(msg)
-
resp.getType match {
case "P2S_PROBE_OK" ⇒ logger.trace("Downlink handshake OK.") // Bingo!
- case "P2S_PROBE_NOT_FOUND" ⇒ err("Probe failed to start due to unknown error.")
- case _ ⇒ err(s"Unexpected REST server message: ${resp.getType}")
+ case "P2S_PROBE_NOT_FOUND" ⇒ throw new HandshakeError("Probe failed to start due to unknown error.")
+ case _ ⇒ throw new HandshakeError(s"Unexpected REST server message: ${resp.getType}")
}
sock
@@ -180,8 +178,8 @@ object NCConnectionManager extends NCService {
logger.trace(s"Opening uplink to '$host:$port'")
- // Connect down socket.
- val sock = NCSocket(new Socket(host, port), host)
+ // Connect up socket.
+ val sock = NCSocket(host, port)
sock.write(U.mkSha256Hash(Config.token)) // Hash, sent clear text.
@@ -257,16 +255,14 @@ object NCConnectionManager extends NCService {
), cryptoKey)
val resp = sock.read[NCProbeMessage](cryptoKey) // Get handshake response.
-
- def err(msg: String) = throw new HandshakeError(msg)
resp.getType match {
- case "S2P_PROBE_MULTIPLE_INSTANCES" ⇒ err("Duplicate probes ID detected. Each probe has to have a unique ID.")
- case "S2P_PROBE_NOT_FOUND" ⇒ err("Probe failed to start due to unknown error.")
- case "S2P_PROBE_VERSION_MISMATCH" ⇒ err(s"REST server does not support probe version: ${ver.version}")
- case "S2P_PROBE_UNSUPPORTED_TOKENS_TYPES" ⇒ err(s"REST server does not support some model enabled tokes types.")
+ case "S2P_PROBE_MULTIPLE_INSTANCES" ⇒ throw new HandshakeError("Duplicate probes ID detected. Each probe has to have a unique ID.")
+ case "S2P_PROBE_NOT_FOUND" ⇒ throw new HandshakeError("Probe failed to start due to unknown error.")
+ case "S2P_PROBE_VERSION_MISMATCH" ⇒ throw new HandshakeError(s"REST server does not support probe version: ${ver.version}")
+ case "S2P_PROBE_UNSUPPORTED_TOKENS_TYPES" ⇒ throw new HandshakeError(s"REST server does not support some model enabled tokes types.")
case "S2P_PROBE_OK" ⇒ logger.trace("Uplink handshake OK.") // Bingo!
- case _ ⇒ err(s"Unknown REST server message: ${resp.getType}")
+ case _ ⇒ throw new HandshakeError(s"Unknown REST server message: ${resp.getType}")
}
sock
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
index 8bda420..12823a7 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
@@ -122,7 +122,7 @@ object NCDeployManager extends NCService with DecorateAsScala {
@throws[NCE]
private def checkCollection(name: String, col: Any): Unit =
if (col == null)
- throw new NCE(s"Collection '$name' can be empty but cannot be null")
+ throw new NCE(s"Collection '$name' can be empty but cannot be null.")
/**
*
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCModelHolder.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCModelHolder.scala
index 4786571..372f890 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCModelHolder.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCModelHolder.scala
@@ -20,9 +20,10 @@ package org.apache.nlpcraft.probe.mgrs.deploy
import org.apache.nlpcraft.model.NCModel
/**
- * TODO:
- * @param model
- * @param intentSamples
+ * Holder for the model and its intent samepls.
+ *
+ * @param model Model.
+ * @param intentSamples Map of intent samples.
*/
case class NCModelHolder(model: NCModel, intentSamples: Map[String, Seq[String]]) {
require(model != null)
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/tools/NCSqlModelEngineSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/tools/NCSqlModelEngineSpec.scala
index c9c5dd2..e51b51f 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/tools/NCSqlModelEngineSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/tools/NCSqlModelEngineSpec.scala
@@ -21,7 +21,7 @@ import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
/**
- * TODO: add description.
+ * SQL model engine test.
*/
class NCSqlModelEngineSpec {
/**