This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-278
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-278 by this push:
new 61edff9 WIP.
61edff9 is described below
commit 61edff93eee630c1b464cb14a6528132ed8f64af
Author: Sergey Kamov <[email protected]>
AuthorDate: Tue Mar 23 16:12:43 2021 +0300
WIP.
---
.../idl/compiler/functions/NCIdlFunctions.scala | 38 +++++++++++++---------
.../compiler/functions/NCIdlFunctionsToken.scala | 4 +--
2 files changed, 25 insertions(+), 17 deletions(-)
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 5420365..0b519ae 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
@@ -43,27 +43,35 @@ private[functions] trait NCIdlFunctions {
@BeforeEach
def before(): Unit = NCIdlCompilerGlobal.clearCache(MODEL_ID)
- case class TestData(truth: String, token: NCToken = tkn(), idlCtx:
NCIdlContext = ctx()) {
- val function: NCIdlFunction = {
+ case class TestData(truth: String, token: Option[NCToken] = None, idlCtx:
NCIdlContext = ctx()) {
+ val predicate: NCIdlFunction = {
val intents = NCIdlCompiler.compileIntents(s"intent=i
term(t)={$truth}", MODEL, MODEL_ID)
require(intents.size == 1)
+ require(intents.head.terms.size == 1)
- val intent = intents.head
+ intents.head.terms.head.pred
+ }
+
+ override def toString: String =
+ token match {
+ case Some(t) ⇒ s"Function [definition=$truth, token=${t2s(t)}]"
+ case None ⇒ s"Function [definition=$truth]"
+ }
+ }
- require(intent.terms.size == 1)
+ object TestData {
+ def apply(truth: String, token: NCToken, idlCtx: NCIdlContext):
TestData =
+ TestData(truth = truth, token = Some(token), idlCtx = idlCtx)
- intent.terms.head.pred
- }
+ def apply(truth: String, token: NCToken): TestData =
+ TestData(truth = truth, token = Some(token))
+ }
- private def nvl(s: String, name: String): String = if (s != null) s
else s"$name (not set)"
- private def t2s(t: NCToken) = s"text=${nvl(t.getOriginalText, "text")}
[${nvl(t.getId, "id")}]"
+ private def t2s(t: NCToken) = {
+ def nvl(s: String, name: String): String = if (s != null) s else
s"$name (not set)"
- override def toString: String =
- s"Function [" +
- s"token=${t2s(token)}, " +
- s"function=$truth" +
- s"]"
+ s"text=${nvl(t.getOriginalText, "text")} [${nvl(t.getId, "id")}]"
}
protected def ctx(
@@ -133,7 +141,7 @@ private[functions] trait NCIdlFunctions {
for (f ← funcs) {
val res =
try
- f.function.apply(f.token, f.idlCtx).value
+ f.predicate.apply(f.token.getOrElse(tkn()), f.idlCtx).value
catch {
case e: Exception ⇒ throw new Exception(s"Execution error
[func=$f]", e)
}
@@ -144,7 +152,7 @@ private[functions] trait NCIdlFunctions {
require(
requirement = false,
s"Unexpected result type [" +
- s"resType=${if (res == null) null else
res.getClass.getName}, " +
+ s"resType=${if (res == null) "null" else
res.getClass.getName}, " +
s"resValue=$res, " +
s"testFunc='$f'" +
s"]"
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
index 23b7e64..fb9721d 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
@@ -28,11 +28,11 @@ class NCIdlFunctionsToken extends NCIdlFunctions {
test(
TestData(
truth = "id() == 'a'",
- tkn(id = "a")
+ token = tkn(id = "a")
),
TestData(
truth = "parent() == 'a'",
- tkn(parentId = "a")
+ token = tkn(parentId = "a")
)
)
}