This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-510
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-510 by this push:
new a3aecc09 Test client.
a3aecc09 is described below
commit a3aecc092e1763cf26b4fd28caa4fb160a26c6b1
Author: Sergey Kamov <[email protected]>
AuthorDate: Sat Aug 6 20:50:28 2022 +0300
Test client.
---
.../examples/lightswitch/NCModelValidationSpec.scala | 4 ++--
.../examples/lightswitch/NCModelValidationSpec.scala | 4 ++--
.../examples/lightswitch/NCModelValidationSpec.scala | 4 ++--
.../nlpcraft/examples/time/NCModelValidationSpec.scala | 4 ++--
.../src/main/scala/org/apache/nlpcraft/NCModelClient.scala | 2 +-
.../internal/intent/matcher/NCIntentSolverManager.scala | 2 +-
.../nlpcraft/{test => validation}/NCCallbackData.scala | 2 +-
.../NCModelValidator.scala} | 13 +++++++------
.../apache/nlpcraft/internal/impl/NCModelClientSpec.scala | 4 ++--
.../apache/nlpcraft/internal/impl/NCModelClientSpec2.scala | 6 +++---
.../apache/nlpcraft/internal/impl/NCModelClientSpec3.scala | 4 ++--
11 files changed, 25 insertions(+), 24 deletions(-)
diff --git
a/nlpcraft-examples/lightswitch-fr/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
b/nlpcraft-examples/lightswitch-fr/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
index a58af3bc..b99b3d37 100644
---
a/nlpcraft-examples/lightswitch-fr/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
+++
b/nlpcraft-examples/lightswitch-fr/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
@@ -18,7 +18,7 @@
package org.apache.nlpcraft.examples.lightswitch
import org.apache.nlpcraft.*
-import org.apache.nlpcraft.test.NCModelTestClient
+import org.apache.nlpcraft.validation.NCModelValidator
import org.junit.jupiter.api.*
import scala.util.Using
@@ -28,4 +28,4 @@ import scala.util.Using
*/
class NCModelValidationSpec:
@Test
- def test(): Unit = Using.resource(new NCModelTestClient(new
LightSwitchFrModel)) { _.validateSamples() }
+ def test(): Unit = Using.resource(NCModelValidator(new
LightSwitchFrModel)) { _.validateSamples() }
diff --git
a/nlpcraft-examples/lightswitch-ru/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
b/nlpcraft-examples/lightswitch-ru/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
index ce5cd48d..f9ad2d28 100644
---
a/nlpcraft-examples/lightswitch-ru/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
+++
b/nlpcraft-examples/lightswitch-ru/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
@@ -18,7 +18,7 @@
package org.apache.nlpcraft.examples.lightswitch
import org.apache.nlpcraft.*
-import org.apache.nlpcraft.test.NCModelTestClient
+import org.apache.nlpcraft.validation.NCModelValidator
import org.junit.jupiter.api.*
import scala.util.Using
@@ -28,4 +28,4 @@ import scala.util.Using
*/
class NCModelValidationSpec:
@Test
- def test(): Unit = Using.resource(new NCModelTestClient(new
LightSwitchRuModel)) { _.validateSamples() }
+ def test(): Unit = Using.resource(NCModelValidator(new
LightSwitchRuModel)) { _.validateSamples() }
diff --git
a/nlpcraft-examples/lightswitch/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
b/nlpcraft-examples/lightswitch/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
index ef9102f0..ea852bc0 100644
---
a/nlpcraft-examples/lightswitch/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
+++
b/nlpcraft-examples/lightswitch/src/test/scala/org/apache/nlpcraft/examples/lightswitch/NCModelValidationSpec.scala
@@ -18,7 +18,7 @@
package org.apache.nlpcraft.examples.lightswitch
import org.apache.nlpcraft.*
-import org.apache.nlpcraft.test.NCModelTestClient
+import org.apache.nlpcraft.validation.NCModelValidator
import org.junit.jupiter.api.*
import scala.util.Using
@@ -27,7 +27,7 @@ import scala.util.Using
* JUnit models validation.
*/
class NCModelValidationSpec:
- private def test(mdl: NCModel): Unit = Using.resource(new
NCModelTestClient(mdl)) { _.validateSamples() }
+ private def test(mdl: NCModel): Unit =
Using.resource(NCModelValidator(mdl)) { _.validateSamples() }
@Test
def test(): Unit = test(new LightSwitchScalaModel())
diff --git
a/nlpcraft-examples/time/src/test/scala/org/apache/nlpcraft/examples/time/NCModelValidationSpec.scala
b/nlpcraft-examples/time/src/test/scala/org/apache/nlpcraft/examples/time/NCModelValidationSpec.scala
index ac0f6c24..4a8ae60a 100644
---
a/nlpcraft-examples/time/src/test/scala/org/apache/nlpcraft/examples/time/NCModelValidationSpec.scala
+++
b/nlpcraft-examples/time/src/test/scala/org/apache/nlpcraft/examples/time/NCModelValidationSpec.scala
@@ -18,7 +18,7 @@
package org.apache.nlpcraft.examples.time
import org.apache.nlpcraft.*
-import org.apache.nlpcraft.test.NCModelTestClient
+import org.apache.nlpcraft.validation.NCModelValidator
import org.junit.jupiter.api.*
import scala.util.Using
@@ -28,4 +28,4 @@ import scala.util.Using
*/
class NCModelValidationSpec:
@Test
- def test(): Unit = Using.resource(new NCModelTestClient(new TimeModel()))
{ _.validateSamples() }
+ def test(): Unit = Using.resource(NCModelValidator(new TimeModel())) {
_.validateSamples() }
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala
index 98b2e916..b3db6315 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala
@@ -26,7 +26,7 @@ import
org.apache.nlpcraft.internal.dialogflow.NCDialogFlowManager
import org.apache.nlpcraft.internal.impl.*
import org.apache.nlpcraft.internal.intent.matcher.*
import org.apache.nlpcraft.internal.util.*
-import org.apache.nlpcraft.test.NCCallbackData
+import org.apache.nlpcraft.validation.NCCallbackData
import java.util
import java.util.concurrent.*
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/matcher/NCIntentSolverManager.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/matcher/NCIntentSolverManager.scala
index d43d398f..6ef88437 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/matcher/NCIntentSolverManager.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/matcher/NCIntentSolverManager.scala
@@ -24,7 +24,7 @@ import
org.apache.nlpcraft.internal.conversation.NCConversationManager
import org.apache.nlpcraft.internal.dialogflow.NCDialogFlowManager
import org.apache.nlpcraft.internal.impl.NCCallbackInput
import org.apache.nlpcraft.internal.intent.*
-import org.apache.nlpcraft.test.NCCallbackData
+import org.apache.nlpcraft.validation.NCCallbackData
import java.util.function.Function
import scala.annotation.targetName
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/test/NCCallbackData.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/validation/NCCallbackData.scala
similarity index 88%
rename from
nlpcraft/src/main/scala/org/apache/nlpcraft/test/NCCallbackData.scala
rename to
nlpcraft/src/main/scala/org/apache/nlpcraft/validation/NCCallbackData.scala
index 3c2e1004..231e5110 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/test/NCCallbackData.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/validation/NCCallbackData.scala
@@ -1,4 +1,4 @@
-package org.apache.nlpcraft.test
+package org.apache.nlpcraft.validation
import org.apache.nlpcraft.*
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/test/NCModelTestClient.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/validation/NCModelValidator.scala
similarity index 73%
rename from
nlpcraft/src/main/scala/org/apache/nlpcraft/test/NCModelTestClient.scala
rename to
nlpcraft/src/main/scala/org/apache/nlpcraft/validation/NCModelValidator.scala
index 8e56eeb3..e70935fd 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/test/NCModelTestClient.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/validation/NCModelValidator.scala
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.nlpcraft.test
+package org.apache.nlpcraft.validation
import com.typesafe.scalalogging.LazyLogging
import org.apache.nlpcraft.*
@@ -25,11 +25,12 @@ import
org.apache.nlpcraft.internal.intent.matcher.NCIntentSolveType.*
import java.util.UUID
-class NCModelTestClient(mdl: NCModel) extends LazyLogging, AutoCloseable:
- private val client = new NCModelClient(mdl)
- /**
- * */
- def close(): Unit = client.close()
+object NCModelValidator:
+ def apply(client: NCModelClient): NCModelValidator = new
NCModelValidator(client, false)
+ def apply(mdl: NCModel): NCModelValidator = new NCModelValidator(new
NCModelClient(mdl), true)
+
+class NCModelValidator(private val client: NCModelClient, private val
shouldClose: Boolean) extends LazyLogging, AutoCloseable:
+ def close(): Unit = if shouldClose then client.close()
def debugAsk(txt: String, data: Map[String, AnyRef], usrId: String,
saveHist: Boolean): NCCallbackData =
client.debugAsk(txt, data, usrId, saveHist)
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec.scala
index 5bb0eaf5..28f0c9ca 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec.scala
@@ -22,7 +22,7 @@ import org.apache.nlpcraft.annotations.*
import org.apache.nlpcraft.nlp.entity.parser.*
import org.apache.nlpcraft.nlp.entity.parser.semantic.NCSemanticEntityParser
import org.apache.nlpcraft.nlp.util.*
-import org.apache.nlpcraft.test.NCModelTestClient
+import org.apache.nlpcraft.validation.NCModelValidator
import org.junit.jupiter.api.Test
import scala.jdk.CollectionConverters.*
@@ -53,7 +53,7 @@ class NCModelClientSpec:
println(s"Intent: ${res.getIntentId}")
println(s"Body: ${res.getBody}")
- Using.resource(new NCModelTestClient(mdl)) { _.validateSamples() }
+ Using.resource(NCModelValidator(mdl)) { _.validateSamples() }
val winner = client.debugAsk("Lights on at second floor kitchen",
"userId", true)
println(s"Winner intent: ${winner.getIntentId}")
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec2.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec2.scala
index 2987b57a..a3358c21 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec2.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec2.scala
@@ -20,9 +20,9 @@ package org.apache.nlpcraft.internal.impl
import org.apache.nlpcraft.*
import org.apache.nlpcraft.annotations.*
import org.apache.nlpcraft.nlp.entity.parser.*
-import org.apache.nlpcraft.nlp.entity.parser.semantic.{NCSemanticTestElement,
*}
+import org.apache.nlpcraft.nlp.entity.parser.semantic.*
import org.apache.nlpcraft.nlp.util.*
-import org.apache.nlpcraft.test.NCModelTestClient
+import org.apache.nlpcraft.validation.NCModelValidator
import org.junit.jupiter.api.Test
import java.util
@@ -50,7 +50,7 @@ class NCModelClientSpec2:
Using.resource(new NCModelClient(mdl)) { client =>
case class Result(txt: String):
- private val wi = Using.resource(new NCModelTestClient(mdl)) {
_.debugAsk(txt, "userId", true) }
+ private val wi = Using.resource(NCModelValidator(mdl)) {
_.debugAsk(txt, "userId", true) }
private val allArgs: List[List[NCEntity]] =
wi.getCallbackArguments
val intentId: String = wi.getIntentId
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec3.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec3.scala
index 232b94a0..bb265309 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec3.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientSpec3.scala
@@ -22,7 +22,7 @@ import org.apache.nlpcraft.annotations.*
import org.apache.nlpcraft.nlp.entity.parser.*
import org.apache.nlpcraft.nlp.entity.parser.semantic.*
import org.apache.nlpcraft.nlp.util.*
-import org.apache.nlpcraft.test.{NCCallbackData, NCModelTestClient}
+import org.apache.nlpcraft.validation.{NCCallbackData, NCModelValidator}
import org.junit.jupiter.api.Test
import java.util
@@ -48,7 +48,7 @@ class NCModelClientSpec3:
def onMatch(ctx: NCContext, im: NCIntentMatch, @NCIntentTerm("t1")
t1: NCEntity): NCResult = NCResult("Data", NCResultType.ASK_RESULT)
Using.resource(new NCModelClient(mdl)) { client =>
- def ask(): NCCallbackData = Using.resource(new
NCModelTestClient(mdl)) { _.debugAsk("e1", "userId", true) }
+ def ask(): NCCallbackData =
Using.resource(NCModelValidator(client)) { _.debugAsk("e1", "userId", true) }
def execCallback(cb: NCCallbackData): NCResult =
cb.getCallback.apply(cb.getCallbackArguments)
def execCallbackOk(cb: NCCallbackData): Unit = println(s"Result:
${execCallback(cb).getBody}")
def execCallbackFail(cb: NCCallbackData): Unit =