WIP.
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModelApp.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModelApp.java
index fd82494..d6ddf54 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModelApp.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModelApp.java
@@ -32,7 +32,7 @@
*/
public static void main(String[] args) throws Exception {
// Start the data probe "in place" with 'TimeModel' model.
- if (NCEmbeddedProbe.start(TimeModel.class))
+ if (NCEmbeddedProbe.start(null, TimeModel.class.getName()))
Thread.currentThread().join();
}
}
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/embedded/NCEmbeddedProbe.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/embedded/NCEmbeddedProbe.java
index 1017bc0..a25da3f 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/embedded/NCEmbeddedProbe.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/embedded/NCEmbeddedProbe.java
@@ -18,7 +18,6 @@
package org.apache.nlpcraft.model.tools.embedded;
import org.apache.nlpcraft.common.*;
-import org.apache.nlpcraft.model.*;
import org.apache.nlpcraft.model.tools.test.*;
import org.apache.nlpcraft.probe.*;
import org.apache.nlpcraft.probe.mgrs.nlp.*;
@@ -81,68 +80,22 @@
}
/**
+ * Start the embedded probe with optional configuration file and models overrides.
*
- * @param classes
- */
- private static void checkModelClasses(Class<? extends NCModel>[] classes) {
- if (classes.length == 0)
- throw new NCException("At least one model class must be provided when starting embedded probe.");
- }
-
- /**
- * Start the embedded probe with given configuration file. It is equivalent to starting a probe using
- * <code>-config=cfgFile</code> command line argument.
- *
- * @param cfgFile Configuration file path. It should be either a full path or the file name
+ * @param cfgFile Optional configuration file path. It should be either a full path or the file name
* that can be found in the current working directory or on the classpath as a class loader
- * resource.
+ * resource. If provided - it is equivalent to starting a probe using <code>-config=cfgFile</code>
+ * command line argument. If {@code null} - the probe will start with the default configuration.
+ * @param mdlClasses Optional data model classes to be deployed by the embedded probe. If provided -
+ * these will override {@code nlpcraft.probe.models} configuration property. If {@code null} - the models
+ * defined in the configuration (default or provided via {@code cfgFile} parameter) will be used.
* @throws NCException Thrown in case of any errors starting the data probe.
* @return Whether or not probe started ok.
*/
- public static boolean start(String cfgFile) {
+ public static boolean start(String cfgFile, String... mdlClasses) {
CompletableFuture<Integer> fut = new CompletableFuture<>();
- NCProbeBoot$.MODULE$.start(cfgFile, fut);
-
- return waitForFuture(fut);
- }
-
- /**
- * Start the embedded probe with given configuration file and models overrides. It is equivalent to starting
- * a probe using <code>-config=cfgFile</code> command line argument.
- *
- * @param cfgFile Configuration file path. It should be either a full path or the file name
- * that can be found in the current working directory or on the classpath as a class loader
- * resource.
- * @param mdlClasses One or more data model classes to be deployed by the embedded probe. These will
- * override {@code nlpcraft.probe.models} configuration property in the provided configuration file.
- * @throws NCException Thrown in case of any errors starting the data probe.
- * @return Whether or not probe started ok.
- */
- @SafeVarargs
- public static boolean start(String cfgFile, Class<? extends NCModel>... mdlClasses) {
- CompletableFuture<Integer> fut = new CompletableFuture<>();
-
- NCProbeBoot$.MODULE$.start(cfgFile, mdlClasses, fut);
-
- return waitForFuture(fut);
- }
-
- /**
- * Starts the embedded probe with default configuration and specified models to deploy.
- *
- * @param mdlClasses One or more data model classes to be deployed by the embedded probe. These will
- * override {@code nlpcraft.probe.models} configuration property in the default configuration file.
- * @throws NCException Thrown in case of any errors starting the data probe.
- * @return Whether or not probe started ok.
- */
- @SafeVarargs
- public static boolean start(Class<? extends NCModel>... mdlClasses) {
- checkModelClasses(mdlClasses);
-
- CompletableFuture<Integer> fut = new CompletableFuture<>();
-
- NCProbeBoot$.MODULE$.start(mdlClasses, fut);
+ NCProbeBoot$.MODULE$.startEmbedded(cfgFile, mdlClasses, fut);
return waitForFuture(fut);
}
@@ -154,22 +107,23 @@
* @param tok Probe token override.
* @param upLink Probe up-link to the server override.
* @param dnLink Probe down-link from the server override.
- * @param mdlClasses One or more data model classes overrides to be deployed by the embedded probe.
+ * @param mdlClasses One or more data model classes overrides to be deployed by the embedded probe. At least
+ * model must be provided.
* @throws NCException Thrown in case of any errors starting the data probe.
* @return Whether or not probe started ok.
*/
- @SafeVarargs
public static boolean start(
String probeId,
String tok,
String upLink,
String dnLink,
- Class<? extends NCModel>... mdlClasses) {
- checkModelClasses(mdlClasses);
+ String... mdlClasses) {
+ if (mdlClasses.length == 0)
+ throw new NCException("At least one model class must be provided when starting embedded probe.");
CompletableFuture<Integer> fut = new CompletableFuture<>();
- NCProbeBoot$.MODULE$.start(probeId, tok, upLink, dnLink, mdlClasses, fut);
+ NCProbeBoot$.MODULE$.startEmbedded(probeId, tok, upLink, dnLink, mdlClasses, fut);
return waitForFuture(fut);
}
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestAutoModelValidator.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestAutoModelValidator.java
index 3b0386c..a2635b2 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestAutoModelValidator.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/test/NCTestAutoModelValidator.java
@@ -121,21 +121,6 @@
/**
* Performs validation based on {@link NCIntentSample} annotations for given models.
*
- * @param mdlIds Comma separate list of one or more model IDs to validate.
- * @return <code>True</code> if no validation errors found, <code>false</code> otherwise. Note that
- * standard validation output will be printed out to the configured logger.
- * @throws Exception Thrown in case of any unexpected errors during validation. Note that standard validation
- * output will be printed out to the configured logger.
- *
- * @see NCModelView#getId()
- */
- public static boolean isValid(String mdlIds) throws Exception {
- return NCTestAutoModelValidatorImpl.isValidForModelIds(mdlIds);
- }
-
- /**
- * Performs validation based on {@link NCIntentSample} annotations for given models.
- *
* @param mdlIds Collection of model IDs to validate.
* @return <code>True</code> if no validation errors found, <code>false</code> otherwise. Note that
* standard validation output will be printed out to the configured logger (e.g. log4j), if any.
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbe.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbe.scala
index 33d7aa6..44abbef 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbe.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbe.scala
@@ -35,7 +35,7 @@
while (!fut.isDone)
ignoring(classOf[Exception]) {
- fut.get();
+ fut.get()
}
System.exit(fut.get)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
index 85c7d67..bf1ffa7 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
@@ -33,7 +33,6 @@
import org.apache.nlpcraft.common.extcfg.NCExternalConfigManager
import org.apache.nlpcraft.common.version.NCVersion
import org.apache.nlpcraft.common.{NCE, NCException, NCService, U}
-import org.apache.nlpcraft.model.NCModel
import org.apache.nlpcraft.probe.mgrs.cmd.NCCommandManager
import org.apache.nlpcraft.probe.mgrs.conn.NCConnectionManager
import org.apache.nlpcraft.probe.mgrs.conversation.NCConversationManager
@@ -312,45 +311,34 @@
private def checkStarted(): Unit =
if (started)
throw new NCException(s"Probe has already been started (only one probe per JVM is allowed).")
-
+
/**
- *
- * @param cfgFile Configuration file to use.
- * @param fut
- */
- private [probe] def start(cfgFile: String, fut: CompletableFuture[Integer]): Unit = {
- checkStarted()
-
- val cfg = initializeConfig(Array(s"-config=$cfgFile"), None)
-
- new Thread() {
- override def run(): Unit = start0(cfg, fut)
- }.start()
- }
-
- /**
- * Starts the embedded probe with given configuration file and provided overrides.
+ * Starts the embedded probe with optional configuration file and provided overrides.
*
- * @param cfgFile Configuration file to use.
- * @param mdlClasses Overrides for 'nlpcraft.probe.models' configuration property.
+ * @param cfgFile Optional configuration file to use. If `null` - the default configuration will be used.
+ * @param mdlClasses Optional overrides for 'nlpcraft.probe.models' configuration property. If `null` -
+ * the models configured in the configuration (default or provided) will be used.
* @param fut
*/
- private [probe] def start(
+ private [probe] def startEmbedded(
cfgFile: String,
- mdlClasses: Array[java.lang.Class[_ <: NCModel]],
+ mdlClasses: Array[String],
fut: CompletableFuture[Integer]): Unit = {
checkStarted()
import ConfigValueFactory._
-
+
val cfg = initializeConfig(
- Array(s"-config=$cfgFile"),
- Some(
- ConfigFactory.empty().withValue(
- "nlpcraft.probe.models",
- fromAnyRef(mdlClasses.map(_.getName).mkString(","))
+ if (cfgFile == null) Array.empty else Array(s"-config=$cfgFile"),
+ if (mdlClasses == null)
+ None
+ else
+ Some(
+ ConfigFactory.empty().withValue(
+ "nlpcraft.probe.models",
+ fromAnyRef(mdlClasses.mkString(","))
+ )
)
- )
)
new Thread() {
@@ -359,35 +347,8 @@
}
/**
- * Starts the embedded probe with the default configuration.
+ * Starts the embedded probe with specified configuration values.
*
- * @param mdlClasses Overrides for 'nlpcraft.probe.models' configuration property.
- * @param fut
- */
- private [probe] def start(
- mdlClasses: Array[java.lang.Class[_ <: NCModel]],
- fut: CompletableFuture[Integer]): Unit = {
- checkStarted()
-
- import ConfigValueFactory._
-
- val cfg = initializeConfig(
- Array.empty,
- Some(
- ConfigFactory.empty().withValue(
- "nlpcraft.probe.models",
- fromAnyRef(mdlClasses.map(_.getName).mkString(","))
- )
- )
- )
-
- new Thread() {
- override def run(): Unit = start0(cfg, fut)
- }.start()
- }
-
- /**
- *
* @param probeId Probe ID.
* @param tok
* @param upLinkStr
@@ -395,12 +356,12 @@
* @param mdlClasses
* @param fut
*/
- private [probe] def start(
+ private [probe] def startEmbedded(
probeId: String,
tok: String,
upLinkStr: String,
dnLinkStr: String,
- mdlClasses: Array[java.lang.Class[_ <: NCModel]],
+ mdlClasses: Array[String],
fut: CompletableFuture[Integer]): Unit = {
checkStarted()
@@ -412,7 +373,7 @@
val upLink: (String, Integer) = getHostPort(upLinkStr)
val dnLink: (String, Integer) = getHostPort(dnLinkStr)
val jarsFolder: Option[String] = getStringOpt(s"$prefix.jarsFolder")
- val models: String = mdlClasses.map(_.getName).mkString(",")
+ val models: String = mdlClasses.mkString(",")
val lifecycle: Seq[String] = getStringList(s"$prefix.lifecycle")
}
@@ -444,14 +405,6 @@
}
/**
- *
- * @param args
- * @param fut
- */
- private [probe] def start(args: Array[String], fut: CompletableFuture[Integer]): Unit =
- start0(initializeConfig(args, None), fut)
-
- /**
* Prints ASCII-logo.
*/
private def asciiLogo() {