This is an automated email from the ASF dual-hosted git repository.
aradzinski 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 aa4b131 WIP.
aa4b131 is described below
commit aa4b13124e84367d109db8e277f2771bf7059cbd
Author: Aaron Radzinski <[email protected]>
AuthorDate: Tue Mar 23 15:03:10 2021 -0700
WIP.
---
.../intent/idl/compiler/functions/NCIdlFunctions.scala | 16 +++++++++++-----
.../compiler/functions/NCIdlFunctionsCollections.scala | 1 +
2 files changed, 12 insertions(+), 5 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 7b320e1..9290694 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
@@ -19,13 +19,14 @@ package
org.apache.nlpcraft.model.intent.idl.compiler.functions
import org.apache.nlpcraft.common.ScalaMeta
import org.apache.nlpcraft.model.intent.compiler.{NCIdlCompiler,
NCIdlCompilerGlobal}
-import org.apache.nlpcraft.model.intent.{NCIdlContext, NCIdlFunction}
+import org.apache.nlpcraft.model.intent.{NCIdlContext, NCIdlTerm}
import org.apache.nlpcraft.model.{NCCompany, NCModel, NCModelView, NCRequest,
NCToken, NCUser}
import org.junit.jupiter.api.BeforeEach
import java.util
import java.util.{Collections, Optional}
import scala.collection.JavaConverters._
+import scala.language.implicitConversions
/**
* Tests for IDL functions.
@@ -45,13 +46,13 @@ private[functions] trait NCIdlFunctions {
def before(): Unit = NCIdlCompilerGlobal.clearCache(MODEL_ID)
case class TestDesc(truth: String, token: Option[NCToken] = None, idlCtx:
NCIdlContext = ctx()) {
- val predicate: NCIdlFunction = {
+ val term: NCIdlTerm = {
val intents = NCIdlCompiler.compileIntents(s"intent=i
term(t)={$truth}", MODEL, MODEL_ID)
require(intents.size == 1)
require(intents.head.terms.size == 1)
- intents.head.terms.head.pred
+ intents.head.terms.head
}
override def toString: String =
@@ -147,8 +148,13 @@ private[functions] trait NCIdlFunctions {
protected def test(funcs: TestDesc*): Unit =
for (f ← funcs) {
val res =
- try
- f.predicate.apply(f.token.getOrElse(tkn()), f.idlCtx).value
+ try {
+ // Process declarations.
+ f.idlCtx.vars ++= f.term.decls
+
+ // Execute term's predicate.
+ f.term.pred.apply(f.token.getOrElse(tkn()), f.idlCtx).value
+ }
catch {
case e: Exception ⇒ throw new Exception(s"Execution error
processing: $f", e)
}
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCollections.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCollections.scala
index f0cea5f..d39bc56 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCollections.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCollections.scala
@@ -31,6 +31,7 @@ class NCIdlFunctionsCollections extends NCIdlFunctions {
"non_empty(list()) == false",
"non_empty(list(1)) == true",
"first(list(1, 2, 3)) == 1",
+ "@lst = list(1, 2, 3) first(reverse(@lst)) == last(@lst)",
"last(list(1, 2, 3)) == 3"
)
}