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 15d4fff2 Validation fixes.
15d4fff2 is described below
commit 15d4fff2809f79a933d583d35ffff5a3ee7370d4
Author: Sergey Kamov <[email protected]>
AuthorDate: Sat Aug 6 21:38:17 2022 +0300
Validation fixes.
---
.../nlpcraft/internal/impl/NCModelClientSpec.scala | 11 ++--
.../internal/impl/NCModelClientSpec2.scala | 71 +++++++++++-----------
2 files changed, 43 insertions(+), 39 deletions(-)
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 28f0c9ca..4399a1db 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
@@ -53,11 +53,14 @@ class NCModelClientSpec:
println(s"Intent: ${res.getIntentId}")
println(s"Body: ${res.getBody}")
- Using.resource(NCModelValidator(mdl)) { _.validateSamples() }
+ Using.resource(NCModelValidator(mdl)) { validator =>
+ validator.validateSamples()
- val winner = client.debugAsk("Lights on at second floor kitchen",
"userId", true)
- println(s"Winner intent: ${winner.getIntentId}")
- println("Entities: \n" + winner.getCallbackArguments.map(p =>
p.map(s).mkString(", ")).mkString("\n"))
+ val winner = validator.validateAsk("Lights on at second floor
kitchen", "userId", true)
+
+ println(s"Winner intent: ${winner.getIntentId}")
+ println("Entities: \n" + winner.getCallbackArguments.map(p =>
p.map(s).mkString(", ")).mkString("\n"))
+ }
}
/**
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 55989707..c438547c 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
@@ -38,7 +38,7 @@ class NCModelClientSpec2:
def test(): Unit =
val mdl = new NCTestModelAdapter:
import NCSemanticTestElement as TE
- override val getPipeline =
+ override val getPipeline: NCTestPipeline =
val pl = mkEnPipeline
pl.entParsers += NCTestUtils.mkEnSemanticParser(TE("e1"),
TE("e2"))
pl.tokEnrichers += EN_TOK_LEMMA_POS_ENRICHER
@@ -49,53 +49,54 @@ class NCModelClientSpec2:
E("Shouldn't be called.")
Using.resource(new NCModelClient(mdl)) { client =>
- case class Result(txt: String):
- private val wi = Using.resource(NCModelValidator(mdl)) {
_.validateAsk(txt, "userId", true) }
- private val allArgs: List[List[NCEntity]] =
wi.getCallbackArguments
+ Using.resource(NCModelValidator(client)) { validator =>
+ case class Result(txt: String):
+ private val wi = validator.validateAsk(txt, "userId", true)
+ private val allArgs: List[List[NCEntity]] =
wi.getCallbackArguments
- val intentId: String = wi.getIntentId
- val size: Int = allArgs.size
+ val intentId: String = wi.getIntentId
+ val size: Int = allArgs.size
- lazy val first: Seq[NCEntity] = allArgs.head
- lazy val second: Seq[NCEntity] = allArgs.last
+ lazy val first: Seq[NCEntity] = allArgs.head
+ lazy val second: Seq[NCEntity] = allArgs.last
// 1. One argument.
- var res = Result("e1")
+ var res = Result("e1")
- require(res.intentId == "i1")
- require(res.size == 2)
+ require(res.intentId == "i1")
+ require(res.size == 2)
- def check(e: NCEntity, txt: String): Unit =
- require(e.mkText == txt)
- // All data aren't lost.
- require(e.getTokens.head.keysSet.contains("lemma"))
+ def check(e: NCEntity, txt: String): Unit =
+ require(e.mkText == txt)
+ // All data aren't lost.
+ require(e.getTokens.head.keysSet.contains("lemma"))
- require(res.first.size == 1)
- check(res.first.head, "e1")
+ require(res.first.size == 1)
+ check(res.first.head, "e1")
- require(res.second.isEmpty)
+ require(res.second.isEmpty)
- // 2. One argument.
- res = Result("e1 e2 e2")
+ // 2. One argument.
+ res = Result("e1 e2 e2")
- require(res.intentId == "i1")
- require(res.size == 2)
+ require(res.intentId == "i1")
+ require(res.size == 2)
- require(res.first.size == 1)
- check(res.first.head, "e1")
+ require(res.first.size == 1)
+ check(res.first.head, "e1")
- require(res.second.size == 2)
- check(res.second.head, "e2")
- check(res.second.last, "e2")
+ require(res.second.size == 2)
+ check(res.second.head, "e2")
+ check(res.second.last, "e2")
- // 3. No winners.
- try
- client.debugAsk("x", "userId", false)
-
- require(false)
- catch
- case e: NCRejection => println(s"Expected rejection:
${e.getMessage}")
- case e: Throwable => throw e
+ // 3. No winners.
+ try
+ validator.validateAsk("x", "userId", false)
+ require(false)
+ catch
+ case e: NCRejection => println(s"Expected rejection:
${e.getMessage}")
+ case e: Throwable => throw e
+ }
}