This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch NLPCRAFT-390
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-390 by this push:
new a9703bc WIP on NLPCRAFT-390
a9703bc is described below
commit a9703bc6d4bfff5151fae5c948371b61d8169092
Author: Aaron Radzinzski <[email protected]>
AuthorDate: Sun Aug 1 23:29:01 2021 -0700
WIP on NLPCRAFT-390
---
.../model/intent/compiler/NCIdlCompilerBase.scala | 2 +-
.../compiler/functions/NCIdlFunctionsToken.scala | 42 ++++++++++++++++++++++
2 files changed, 43 insertions(+), 1 deletion(-)
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 @@ trait NCIdlCompilerBase {
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 @@ class NCIdlFunctionsToken extends NCIdlFunctions {
)
)
}
+
+ @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))
+ )
+ )
+ }
}