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 53621c5b Validation fixes.
53621c5b is described below
commit 53621c5b6dcbabdd24ef65c89db056b138662f1e
Author: Sergey Kamov <[email protected]>
AuthorDate: Mon Aug 8 10:52:36 2022 +0300
Validation fixes.
---
.../src/main/scala/org/apache/nlpcraft/NCModelClient.scala | 6 +++---
.../internal/intent/matcher/NCIntentSolverManager.scala | 6 +++---
.../validation/{NCCallbackData.scala => NCFiredIntent.scala} | 2 +-
.../org/apache/nlpcraft/validation/NCModelValidator.scala | 7 ++++---
.../org/apache/nlpcraft/internal/impl/NCModelClientSpec3.scala | 10 +++++-----
5 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala
index 89abfa27..e73ba8cc 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.validation.NCCallbackData
+import org.apache.nlpcraft.validation.NCFiredIntent
import java.util
import java.util.concurrent.*
@@ -79,7 +79,7 @@ class NCModelClient(mdl: NCModel) extends LazyLogging,
AutoCloseable:
* @param typ
* @return
*/
- private def ask0(txt: String, data: Map[String, Any], usrId: String, typ:
NCIntentSolveType): Either[NCResult, NCCallbackData] =
+ private def ask0(txt: String, data: Map[String, Any], usrId: String, typ:
NCIntentSolveType): Either[NCResult, NCFiredIntent] =
val plData = plMgr.prepare(txt, data, usrId)
val userId = plData.request.getUserId
@@ -221,7 +221,7 @@ class NCModelClient(mdl: NCModel) extends LazyLogging,
AutoCloseable:
* @param saveHist
* @return
*/
- private[nlpcraft] def debugAsk(txt: String, usrId: String, saveHist:
Boolean, data: Map[String, AnyRef]): NCCallbackData =
+ private[nlpcraft] def debugAsk(txt: String, usrId: String, saveHist:
Boolean, data: Map[String, AnyRef]): NCFiredIntent =
require(txt != null, "Input text cannot be null.")
require(data != null, "Data cannot be null.")
require(usrId != null, "User id cannot be null.")
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 6ef88437..8776bad3 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.validation.NCCallbackData
+import org.apache.nlpcraft.validation.NCFiredIntent
import java.util.function.Function
import scala.annotation.targetName
@@ -90,7 +90,7 @@ object NCIntentSolverManager:
getIntentId: String,
getCallbackArguments: List[List[NCEntity]],
getCallback: List[List[NCEntity]] => NCResult
- ) extends NCCallbackData
+ ) extends NCFiredIntent
/**
*
@@ -184,7 +184,7 @@ object NCIntentSolverManager:
*/
private case class IntentEntity(var used: Boolean, var conv: Boolean,
entity: NCEntity)
- type ResultData = Either[NCResult, NCCallbackData]
+ type ResultData = Either[NCResult, NCFiredIntent]
/**
*
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/validation/NCCallbackData.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/validation/NCFiredIntent.scala
similarity index 93%
rename from
nlpcraft/src/main/scala/org/apache/nlpcraft/validation/NCCallbackData.scala
rename to
nlpcraft/src/main/scala/org/apache/nlpcraft/validation/NCFiredIntent.scala
index 231e5110..7879a92a 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/validation/NCCallbackData.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/validation/NCFiredIntent.scala
@@ -4,7 +4,7 @@ import org.apache.nlpcraft.*
/**
* */
-trait NCCallbackData:
+trait NCFiredIntent:
/**
*
* @return */
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/validation/NCModelValidator.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/validation/NCModelValidator.scala
index 746683b3..160f7345 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/validation/NCModelValidator.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/validation/NCModelValidator.scala
@@ -29,7 +29,8 @@ object NCModelValidator:
def apply(client: NCModelClient): NCModelValidator = new
NCModelValidator(client)
def apply(mdl: NCModel): NCModelValidator = new NCModelValidator(new
NCModelClient(mdl), true)
-class NCModelValidator(private val client: NCModelClient, private val
autoClose: Boolean = false) extends LazyLogging, AutoCloseable:
- override def close(): Unit = if autoClose then client.close()
- def validateAsk(txt: String, usrId: String, saveHist: Boolean = false,
data: Map[String, AnyRef] = Map.empty): NCCallbackData = client.debugAsk(txt,
usrId, saveHist, data)
+class NCModelValidator(client: NCModelClient, clientClose: Boolean = false)
extends LazyLogging, AutoCloseable:
+ override def close(): Unit = if clientClose then client.close()
+
+ def validateAsk(txt: String, usrId: String, saveHist: Boolean = false,
data: Map[String, AnyRef] = Map.empty): NCFiredIntent = client.debugAsk(txt,
usrId, saveHist, data)
def validateSamples(): Unit = client.validateSamples()
\ No newline at end of file
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 9cb901c3..cc8709b9 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.validation.{NCCallbackData, NCModelValidator}
+import org.apache.nlpcraft.validation.{NCFiredIntent, NCModelValidator}
import org.junit.jupiter.api.Test
import java.util
@@ -48,10 +48,10 @@ 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(NCModelValidator(client)) { _.validateAsk("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 =
+ def ask(): NCFiredIntent =
Using.resource(NCModelValidator(client)) { _.validateAsk("e1", "userId", true) }
+ def execCallback(cb: NCFiredIntent): NCResult =
cb.getCallback.apply(cb.getCallbackArguments)
+ def execCallbackOk(cb: NCFiredIntent): Unit = println(s"Result:
${execCallback(cb).getBody}")
+ def execCallbackFail(cb: NCFiredIntent): Unit =
try execCallback(cb)
catch case e: NCException => println(s"Expected error:
${e.getMessage}")