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 d4f5e75  WIP.
d4f5e75 is described below

commit d4f5e751430602de5939327089614c1319245373
Author: Sergey Kamov <[email protected]>
AuthorDate: Wed Mar 24 12:15:52 2021 +0300

    WIP.
---
 .../idl/compiler/functions/NCIdlFunctions.scala    |  3 +-
 .../compiler/functions/NCIdlFunctionsToken.scala   | 94 +++++++++++++++++++++-
 2 files changed, 93 insertions(+), 4 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 05ecc35..c47f569 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
@@ -118,6 +118,7 @@ private[functions] trait NCIdlFunctions {
         ancestors: Seq[String] = Seq.empty,
         aliases: Set[String] = Set.empty,
         partTokens: Seq[NCToken] = Seq.empty,
+        isAbstr: Boolean = false,
         meta: Map[String, AnyRef] = Map.empty[String, AnyRef]
     ): NCToken = {
         val map = new util.HashMap[String, AnyRef]
@@ -140,7 +141,7 @@ private[functions] trait NCIdlFunctions {
                 if (groups.isEmpty && id != null) 
Collections.singletonList(id) else groups.asJava
             override def getStartCharIndex: Int = start
             override def getEndCharIndex: Int = end
-            override def isAbstract: Boolean = false
+            override def isAbstract: Boolean = isAbstr
             override def getMetadata: util.Map[String, AnyRef] = map
         }
     }
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 1d3919c..8725886 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
@@ -23,6 +23,27 @@ import org.junit.jupiter.api.Test
   * Tests for 'tokens' functions.
   */
 class NCIdlFunctionsToken extends NCIdlFunctions {
+    private final val meta: Map[String, AnyRef] = Map(
+        "nlpcraft:nlp:stopword" → java.lang.Boolean.TRUE,
+        "nlpcraft:nlp:freeword" → java.lang.Boolean.TRUE,
+        "nlpcraft:nlp:origtext" → "orig text",
+        "nlpcraft:nlp:index" → java.lang.Integer.valueOf(11),
+        "nlpcraft:nlp:normtext" → "norm text",
+        "nlpcraft:nlp:direct" → java.lang.Boolean.TRUE,
+        "nlpcraft:nlp:english" → java.lang.Boolean.TRUE,
+        "nlpcraft:nlp:swear" → java.lang.Boolean.TRUE,
+        "nlpcraft:nlp:quoted" → java.lang.Boolean.TRUE,
+        "nlpcraft:nlp:bracketed" → java.lang.Boolean.TRUE,
+        "nlpcraft:nlp:dict" → java.lang.Boolean.TRUE,
+        "nlpcraft:nlp:lemma" → "lemma",
+        "nlpcraft:nlp:stem" → "stem",
+        "nlpcraft:nlp:sparsity" → java.lang.Integer.valueOf(112),
+        "nlpcraft:nlp:pos" → "pos",
+        "nlpcraft:nlp:unid" → "21421"
+    )
+
+    private def mkMeta(truth: String):TestDesc = TestDesc(truth = truth, token 
= tkn(meta = meta))
+
     @Test
     def test(): Unit =
         test(
@@ -30,9 +51,76 @@ class NCIdlFunctionsToken extends NCIdlFunctions {
                 truth = "tok_id() == 'a'",
                 token = tkn(id = "a")
             ),
+            mkMeta(truth = s"tok_lemma() == '${meta("nlpcraft:nlp:lemma")}'"),
+            mkMeta(truth = s"tok_stem() == '${meta("nlpcraft:nlp:stem")}'"),
+            mkMeta(truth = s"tok_pos() == '${meta("nlpcraft:nlp:pos")}'"),
+            mkMeta(truth = s"tok_sparsity() == 
${meta("nlpcraft:nlp:sparsity")}"),
+            mkMeta(truth = s"tok_unid() == '${meta("nlpcraft:nlp:unid")}'"),
+            TestDesc(
+                truth = s"tok_is_abstract() == true",
+                token = tkn(isAbstr = true)
+            ),
+            mkMeta(truth = s"tok_is_abstract() == false"),
+            mkMeta(truth = s"tok_is_bracketed() == 
${meta("nlpcraft:nlp:bracketed")}"),
+            mkMeta(truth = s"tok_is_direct() == 
${meta("nlpcraft:nlp:direct")}"),
+            mkMeta(truth = s"tok_is_english() == 
${meta("nlpcraft:nlp:english")}"),
+            mkMeta(truth = s"tok_is_freeWord() == 
${meta("nlpcraft:nlp:freeword")}"),
+            mkMeta(truth = s"tok_is_quoted() == 
${meta("nlpcraft:nlp:quoted")}"),
+            mkMeta(truth = s"tok_is_stopword() == 
${meta("nlpcraft:nlp:stopword")}"),
+            mkMeta(truth = s"tok_is_swear() == ${meta("nlpcraft:nlp:swear")}"),
+            TestDesc(
+                truth = s"tok_is_user() == true",
+                token = tkn(id = "aa")
+            ),
+            TestDesc(
+                truth = s"tok_is_user() == false",
+                token = tkn(id = "nlpcraft:nlp")
+            ),
+            mkMeta(truth = s"tok_is_wordnet() == 
${meta("nlpcraft:nlp:dict")}"),
+            TestDesc(
+                truth = s"tok_ancestors() == list('1', '2')",
+                token = tkn(ancestors = Seq("1", "2"))
+            ),
+            TestDesc(
+                truth = s"tok_parent() == 'parentId'",
+                token = tkn(parentId = "parentId")
+            ),
+            TestDesc(
+                truth = "tok_groups() == list('1', '2')",
+                token = tkn(groups = Seq("1", "2"))
+            ),
             TestDesc(
-                truth = "tok_parent() == 'a'",
-                token = tkn(parentId = "a")
-            )
+                truth = "tok_value() == 'value'",
+                token = tkn(value = "value")
+            ),
+            TestDesc(
+                truth = "tok_value() == null",
+                token = tkn()
+            ),
+            TestDesc(
+                truth = "tok_start_idx() == 123",
+                token = tkn(start = 123)
+            ),
+            TestDesc(
+                truth = "tok_end_idx() == 123",
+                token = tkn(end = 123)
+            ),
+            // TODO: fix following.
+//            TestDesc(
+//                truth = "tok_aliases() == list('1')",
+//                token = tkn(aliases = Set("1"))
+//            ),
+//            TestDesc(
+//                truth = "tok_this() == tok_this()"
+//            ),
+//            TestDesc(
+//                truth = "tok_find_part() != null",
+//                token = tkn(partTokens = Seq(tkn("part1"), tkn("part2")))
+//            ),
+//            TestDesc(
+//                truth = "tok_find_parts() != null",
+//                token = tkn(partTokens = Seq(tkn("part1"), tkn("part2")))
+//            ),
+
         )
 }

Reply via email to