Result trait refactoring.
diff --git a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
index f0f80a7..8d5c372 100644
--- a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
+++ b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
@@ -87,10 +87,10 @@
val resp = client.ask(txt, "userId")
testMsgs += s">> Request: $txt"
- testMsgs += s">> Response: '${resp.resultType}': ${resp.body}"
+ testMsgs += s">> Response: '${resp.getType}': ${resp.getBody}"
- if expType != resp.resultType then
- errs += testNum -> new Exception(s"Unexpected result type [num=$testNum, txt=$txt, expected=$expType, type=${resp.resultType}]")
+ if expType != resp.getType then
+ errs += testNum -> new Exception(s"Unexpected result type [num=$testNum, txt=$txt, expected=$expType, type=${resp.getType}]")
// Check execution result on last request.
if idx == reqs.size - 1 then
diff --git a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelServer.scala b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelServer.scala
index 056d071..aa8fd12 100644
--- a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelServer.scala
+++ b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelServer.scala
@@ -64,8 +64,8 @@
if req == null || req.isEmpty then Exception(s"Empty request.")
val resp = nlpClient.ask(req, null, "userId")
- val prompt = if resp.resultType == ASK_DIALOG then "(Your should answer on the model's question below)\n" else ""
- doResponse(s"$prompt${resp.body}")
+ val prompt = if resp.getType == ASK_DIALOG then "(Your should answer on the model's question below)\n" else ""
+ doResponse(s"$prompt${resp.getBody}")
catch
case e: NCRejection => doResponse(s"Request rejected: ${e.getMessage}")
case e: Throwable =>
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala
index 07c626d..4b5553e 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelClient.scala
@@ -174,7 +174,7 @@
try
val r = ask(sample, Map.empty, userId)
- Option.when(r.intentId.isEmpty || r.intentId.get!= i.intent.id)(s"Unexpected intent ID: '${r.intentId.getOrElse("(not set)")}'")
+ Option.when(r.getIntentId.isEmpty || r.getIntentId.get != i.intent.id)(s"Unexpected intent ID: '${r.getIntentId.getOrElse("(not set)")}'")
catch case e: Throwable =>
logger.warn("Unexpected error.", e)
Option(e.getLocalizedMessage)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCResult.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCResult.scala
deleted file mode 100644
index 63c5cd6..0000000
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCResult.scala
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.nlpcraft
-
-import org.apache.nlpcraft.NCResultType.*
-
-/**
- *
- */
-object NCResult:
- def apply(body: Any, resultType: NCResultType, intentId: String): NCResult = new NCResult(body = body, resultType = resultType, Option(intentId))
- def apply(body: Any, resultType: NCResultType): NCResult = apply(body, resultType, intentId = None)
-
-/**
- *
- * @param body
- * @param resultType
- * @param intentId
- */
-case class NCResult(body: Any, resultType: NCResultType, intentId: Option[String] = None)
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 4ce8794..1f04f9f 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
@@ -711,7 +711,7 @@
def executeCallback(in: NCCallbackInput): NCResult =
var cbRes = intentRes.fn(in)
// Store winning intent match in the input.
- if cbRes.intentId.isEmpty then cbRes = NCResult(cbRes.body, cbRes.resultType, intentRes.intentId)
+ if cbRes.getIntentId.isEmpty then cbRes = NCResult(cbRes.getBody, cbRes.getType, intentRes.intentId)
cbRes
def finishSearch(): Unit =
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationTimeoutSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationTimeoutSpec.scala
index ee8537c..62e5119 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationTimeoutSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationTimeoutSpec.scala
@@ -64,7 +64,7 @@
Using.resource(new NCModelClient(mdl)) { cli =>
def check(hasValue: Boolean): Unit =
- require(cli.ask("test", "userId").body.toString == (if hasValue then VALUE else EMPTY))
+ require(cli.ask("test", "userId").getBody.toString == (if hasValue then VALUE else EMPTY))
check(false)
check(true)
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelCallbacksSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelCallbacksSpec.scala
index 02f07d6..706c064 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelCallbacksSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelCallbacksSpec.scala
@@ -100,7 +100,7 @@
*/
private def testOk(client: NCModelClient, exp: NCResult, states: State*): Unit =
set(states*)
- require(client.ask("x", "userId").body == exp.body)
+ require(client.ask("x", "userId").getBody == exp.getBody)
/**
*
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 a9f7c5b..4452a1c 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
@@ -49,8 +49,8 @@
Using.resource(new NCModelClient(mdl)) { client =>
val res = client.ask("Lights on at second floor kitchen", "userId")
- println(s"Intent: ${res.intentId}")
- println(s"Body: ${res.body}")
+ println(s"Intent: ${res.getIntentId}")
+ println(s"Body: ${res.getBody}")
client.validateSamples()
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 f98408b..332822e 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
@@ -49,7 +49,7 @@
Using.resource(new NCModelClient(mdl)) { client =>
def ask(): NCCallbackData = 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).body}")
+ def execCallbackOk(cb: NCCallbackData): Unit = println(s"Result: ${execCallback(cb).getBody}")
def execCallbackFail(cb: NCCallbackData): Unit =
try execCallback(cb)
catch case e: NCException => println(s"Expected error: ${e.getMessage}")
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelPingPongSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelPingPongSpec.scala
index 49168b2..8f47d0c 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelPingPongSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelPingPongSpec.scala
@@ -34,14 +34,18 @@
class NCModelPingPongSpec:
private var client: NCModelClient = _
- private class R(resType: NCResultType, txt: String) extends NCResult(txt, resType):
- override def toString: String = s"$resType ($txt)"
+ def mkResult(resType: NCResultType, txt: String): NCResult =
+ new NCResult ():
+ override def getBody: Any = txt
+ override def getType: NCResultType = resType
+ override def getIntentId: Option[String] = None
+ override def toString: String = s"$resType ($txt)"
private val MDL: NCTestModelAdapter =
new NCTestModelAdapter():
@NCIntent("intent=command term(command)={# == 'command'}")
def onCommand(ctx: NCContext, im: NCIntentMatch, @NCIntentTerm("command") command: NCEntity): NCResult =
- R(ASK_DIALOG, s"Confirm your request 'command'")
+ mkResult(ASK_DIALOG, s"Confirm your request 'command'")
@NCIntent("intent=confirmCommand term(confirm)={# == 'confirm'}")
def onConfirmCommand(ctx: NCContext, im: NCIntentMatch, @NCIntentTerm("confirm") confirm: NCEntity): NCResult =
@@ -56,11 +60,11 @@
println("'Command' confirmed and can be be executed here.")
- R(ASK_RESULT, s"'dialog' confirmed.")
+ mkResult(ASK_RESULT, s"'dialog' confirmed.")
@NCIntent("intent=other term(other)={# == 'other'}")
def onOther(ctx: NCContext, im: NCIntentMatch, @NCIntentTerm("other") other: NCEntity): NCResult =
- R(ASK_RESULT, s"Some request by: ${other.mkText}")
+ mkResult(ASK_RESULT, s"Some request by: ${other.mkText}")
MDL.pipeline.entParsers += NCTestUtils.mkEnSemanticParser(List(STE("command"), STE("confirm"), STE("other")))
@@ -73,7 +77,7 @@
private def ask(txt: String, typ: NCResultType): Unit =
val res = client.ask(txt, "userId")
println(s"Request [text=$txt, result=$res]")
- require(res.resultType == typ)
+ require(res.getType == typ)
private def askForDialog(txt: String): Unit = ask(txt, ASK_DIALOG)
private def askForResult(txt: String): Unit = ask(txt, ASK_RESULT)
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityMapperSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityMapperSpec.scala
index 0d07e05..277a621 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityMapperSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/NCEntityMapperSpec.scala
@@ -72,5 +72,5 @@
@Test
def test(): Unit = Using.resource(new NCModelClient(mdl)) { client =>
- require(client.ask("a b c d", "userId").intentId.orNull == "abcd")
+ require(client.ask("a b c d", "userId").getIntentId.orNull == "abcd")
}
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestResult.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestResult.scala
index 77b7490..14b8662 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestResult.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestResult.scala
@@ -23,10 +23,10 @@
*
*/
object NCTestResult {
- def apply(): NCTestResult = new NCTestResult()
+ def apply(): NCResult = TEST_RESULT
}
/**
*
*/
-class NCTestResult extends NCResult("test", NCResultType.ASK_RESULT)
+val TEST_RESULT = NCResult("test", NCResultType.ASK_RESULT)
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestUtils.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestUtils.scala
index 7e4da7e..d64924c 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestUtils.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestUtils.scala
@@ -113,7 +113,7 @@
def ask(): NCResult = client.ask("test", "userId")
if expectedOk then
- println(ask().body)
+ println(ask().getBody)
else
try
ask()