This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-283
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-283 by this push:
new 3fcce6a WIP.
3fcce6a is described below
commit 3fcce6a8e1c67d13ff12712ddd3093fd79c94d7a
Author: Sergey Kamov <[email protected]>
AuthorDate: Fri Mar 26 14:26:48 2021 +0300
WIP.
---
.../model/intent/solver/NCIntentSolverEngine.scala | 17 ++++++-----------
.../apache/nlpcraft/model/dialog/NCDialogSpec.scala | 21 +++++++++++++++++++--
.../idl/compiler/functions/NCIdlFunctions.scala | 5 ++++-
.../compiler/functions/NCIdlFunctionsCustom.scala | 6 ++++++
4 files changed, 35 insertions(+), 14 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/solver/NCIntentSolverEngine.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/solver/NCIntentSolverEngine.scala
index 23fbb84..2c6d3dc 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/solver/NCIntentSolverEngine.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/solver/NCIntentSolverEngine.scala
@@ -449,22 +449,17 @@ object NCIntentSolverEngine extends LazyLogging with
NCOpenCensusTrace {
x("matched")
}
else if (intent.flowMtdName.isDefined) {
- require(intent.flowClsName.isDefined)
-
- val clsName = intent.flowClsName.get
+ val clsName = intent.flowClsName.orNull
val mtdName = intent.flowMtdName.get
-
- val fqn = s"$clsName.$mtdName(java.util.List[NCDialogFlowItem])"
+
+ val fqn =
+ s"${if (clsName == null) ctx.getModel.getClass.getName else
clsName}." +
+ s"$mtdName(java.util.List[NCDialogFlowItem])"
val res =
try
U.callMethod[java.util.List[NCDialogFlowItem],
java.lang.Boolean](
- () ⇒ {
- // Type must be defined.
- val any: Any = U.mkObject(clsName)
-
- any
- },
+ () ⇒ if (clsName == null) ctx.getModel else
U.mkObject(clsName),
mtdName,
flow.toList.asJava
)
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCDialogSpec.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCDialogSpec.scala
index 9dd34ca..efb52d1 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCDialogSpec.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCDialogSpec.scala
@@ -43,8 +43,7 @@ class NCDialogSpecModel extends NCModel {
override def getName: String = this.getClass.getSimpleName
override def getVersion: String = "1.0.0"
- override def getElements: util.Set[NCElement] =
- Set((for (ch ← 'a' to 'y'; i ← 1 to 9) yield
NCTestElement(s"$ch$i")):_*)
+ override def getElements: util.Set[NCElement] = Set((for (i ← 1 to 100)
yield NCTestElement(s"a$i")):_*)
@NCIntent("intent=onA1 term~{tok_id() == 'a1'}")
def onA1(): NCResult = NCResult.text("ok")
@@ -72,6 +71,16 @@ class NCDialogSpecModel extends NCModel {
@NCIntent("intent=onA9
flow=/org.apache.nlpcraft.model.dialog.NCDialogSpecModelFlow#trueAfterOnA7AndA8/
term~{tok_id() == 'a9'}")
def onA9(): NCResult = NCResult.text("ok")
+
+ def trueAlwaysInternal(flow: java.util.List[NCDialogFlowItem]): Boolean =
true
+
+ @NCIntent("intent=onA10 flow=/trueAlwaysInternal/ term~{tok_id() ==
'a10'}")
+ def onA10(): NCResult = NCResult.text("ok")
+
+ def falseAlwaysInternal(flow: java.util.List[NCDialogFlowItem]): Boolean =
true
+
+ @NCIntent("intent=onA11 flow=/falseAlwaysInternal/ term~{tok_id() ==
'a11'}")
+ def onA11(): NCResult = NCResult.text("ok")
}
/**
@@ -164,4 +173,12 @@ class NCDialogSpec extends NCTestContext {
"a8" → "onA8",
"a9" → "onA9"
)
+
+ @Test
+ private[dialog] def test6(): Unit = {
+ // Always 'true'.
+ require(getClient.ask("10").isOk)
+ // Always 'false'.
+ require(getClient.ask("11").isFailed)
+ }
}
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
index 15d0180..204a9cd 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
@@ -20,7 +20,7 @@ package
org.apache.nlpcraft.model.intent.idl.compiler.functions
import org.apache.nlpcraft.common.{NCE, ScalaMeta}
import org.apache.nlpcraft.model.intent.compiler.{NCIdlCompiler,
NCIdlCompilerGlobal}
import org.apache.nlpcraft.model.intent.{NCIdlContext, NCIdlTerm}
-import org.apache.nlpcraft.model.{NCCompany, NCModel, NCModelView, NCRequest,
NCToken, NCUser}
+import org.apache.nlpcraft.model.{NCCompany, NCModel, NCModelView, NCRequest,
NCToken, NCTokenPredicateContext, NCTokenPredicateResult, NCUser}
import org.junit.jupiter.api.BeforeEach
import java.util
@@ -40,6 +40,9 @@ private[functions] trait NCIdlFunctions {
override val getVersion: String = "1.0.0"
override def getOrigin: String = "test"
+
+ def trueAlwaysCustomToken(ctx: NCTokenPredicateContext):
NCTokenPredicateResult =
+ new NCTokenPredicateResult(true, 1)
}
@BeforeEach
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCustom.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCustom.scala
index ec98903..a12de38 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCustom.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCustom.scala
@@ -71,6 +71,12 @@ class NCIdlFunctionsCustom extends NCIdlFunctions {
token = Some(tkn(txt = "456")),
expectedRes = false,
tokensUsed = Some(1)
+ ),
+ TestDesc(
+ // Method defined in model.
+ truth = s"trueAlwaysCustomToken",
+ isCustom = true,
+ token = Some(tkn(txt = "any"))
)
)
}