WIP on NLPCRAFT-390
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala
index 0cd93a8..ec78ffc 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala
@@ -1100,7 +1100,7 @@
stack.push(() => {
val Z(arg, n) = x()
- Z(idlCtx.toks.filter(f(_, toStr(arg))), n)
+ Z(idlCtx.toks.filter(f(_, toStr(arg))).asJava, n)
})
}
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 4e768f9..58363a4 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
@@ -162,4 +162,46 @@
)
)
}
+
+ @Test
+ def testTokenCount(): Unit = {
+ val tok1 = mkToken(id = "1")
+ val tok2 = mkToken(id = "2")
+
+ test(
+ TestDesc(
+ truth = "tok_count() == 2",
+ token = tok2,
+ idlCtx = mkIdlContext(Seq(tok1, tok2))
+ )
+ )
+ }
+
+ @Test
+ def testTokenForAll(): Unit = {
+ val tok1 = mkToken(id = "1", parentId = "x")
+ val tok2 = mkToken(id = "2", groups = Seq("g", "z", "w"))
+ val tok3 = mkToken(id = "2")
+
+ test(
+ TestDesc(
+ truth = "size(tok_all_for_id('1')) == 1",
+ token = tok2,
+ idlCtx = mkIdlContext(Seq(tok1, tok2, tok3))
+ ),
+ TestDesc(
+ truth = "size(tok_all_for_parent('x')) == 1",
+ token = tok2,
+ idlCtx = mkIdlContext(Seq(tok1, tok2, tok3))
+ ),
+ TestDesc(
+ truth =
+ "size(tok_all_for_group('g')) == 1 && " +
+ "tok_id(first(tok_all_for_group('w'))) == '2' && " +
+ "is_empty(tok_all_for_group('unknown'))",
+ token = tok2,
+ idlCtx = mkIdlContext(Seq(tok1, tok2, tok3))
+ )
+ )
+ }
}