You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by se...@apache.org on 2021/03/23 11:13:20 UTC

[incubator-nlpcraft] branch NLPCRAFT-278 created (now e9ec949)

This is an automated email from the ASF dual-hosted git repository.

sergeykamov pushed a change to branch NLPCRAFT-278
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git.


      at e9ec949  WIP.

This branch includes the following new commits:

     new dedcf82  WIP.
     new 27b900f  WIP.
     new d5eb9da  WIP.
     new e9ec949  WIP.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[incubator-nlpcraft] 04/04: WIP.

Posted by se...@apache.org.
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

commit e9ec949ed698745754d53ad2ebb7af0a6b09b389
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Tue Mar 23 14:13:10 2021 +0300

    WIP.
---
 .../idl/compiler/functions/NCIdlFunctions.scala    | 52 ++++++++++------------
 .../compiler/functions/NCIdlFunctionsColl.scala    |  8 ++--
 .../compiler/functions/NCIdlFunctionsCompany.scala |  2 +-
 .../compiler/functions/NCIdlFunctionsDate.scala    | 32 ++++++++++---
 .../compiler/functions/NCIdlFunctionsMath.scala    |  2 +-
 .../compiler/functions/NCIdlFunctionsRequest.scala |  2 +-
 .../compiler/functions/NCIdlFunctionsStat.scala    |  6 +--
 .../compiler/functions/NCIdlFunctionsStrings.scala |  2 +-
 .../compiler/functions/NCIdlFunctionsToken.scala   |  2 +-
 .../compiler/functions/NCIdlFunctionsUser.scala    |  2 +-
 10 files changed, 63 insertions(+), 47 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 b059f23..a4ef1a5 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,13 @@ private[functions] trait NCIdlFunctions {
     @BeforeEach
     def before(): Unit = NCIdlCompilerGlobal.clearCache(MODEL_ID)
 
-    import TrueFunc._
-
     case class TrueFunc(
         truth: String,
         token: NCToken = tkn(),
         idlCtx: NCIdlContext = ctx()
     ) {
-        val function: NCIdlFunction = mkFunc(truth)
-
-        override def toString: String =
-            s"Boolean function [" +
-                s"token=${t2s(token)}, " +
-                s"function=$truth" +
-                s"]"
-    }
-
-    object TrueFunc {
-        private def t2s(t: NCToken) = s"${t.getOriginalText} (${t.getId})"
-
-        private def mkFunc(function: String): NCIdlFunction = {
-            val intents = NCIdlCompiler.compileIntents(s"intent=i term(t)={$function}", MODEL, MODEL_ID)
+        val function: NCIdlFunction = {
+            val intents = NCIdlCompiler.compileIntents(s"intent=i term(t)={$truth}", MODEL, MODEL_ID)
 
             require(intents.size == 1)
 
@@ -76,6 +62,15 @@ private[functions] trait NCIdlFunctions {
                 override def toString(): String = s"Function, based on term: $function"
             }
         }
+
+        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")}]"
+
+        override def toString: String =
+            s"Function [" +
+            s"token=${t2s(token)}, " +
+            s"function=$truth" +
+            s"]"
     }
 
     protected def ctx(
@@ -143,32 +138,31 @@ private[functions] trait NCIdlFunctions {
     }
 
     protected def test(funcs: TrueFunc*): Unit =
-        for ((func, idx) ← funcs.zipWithIndex) {
+        for (f ← funcs) {
             val res =
                 try
-                    func.function.apply(func.token, func.idlCtx).value
+                    f.function.apply(f.token, f.idlCtx).value
                 catch {
-                    case e: Exception ⇒ throw new Exception(s"Execution error [index=$idx, testFunc=$func]", e)
+                    case e: Exception ⇒ throw new Exception(s"Execution error [func=$f]", e)
                 }
 
             res match {
                 case b: java.lang.Boolean ⇒
-                    require(b,
-                        s"Unexpected result [" +
-                            s"index=$idx, " +
-                            s"testFunc=$func, " +
-                            s"result=$res" +
+                    require(
+                        b,
+                        s"Unexpected FALSE result [" +
+                            s"testFunc=$f " +
                             s"]"
                     )
                 case _ ⇒
-                    require(requirement = false,
+                    require(
+                        requirement = false,
                         s"Unexpected result type [" +
-                            s"index=$idx, " +
-                            s"testFunc=$func, " +
-                            s"result=$res" +
+                            s"resType=${if (res == null) null else res.getClass.getName}, " +
+                            s"testFunc='$f', " +
+                            s"resValue=$res" +
                             s"]"
                     )
             }
-
         }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsColl.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsColl.scala
index ba253cd..f1e9562 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsColl.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsColl.scala
@@ -20,17 +20,17 @@ package org.apache.nlpcraft.model.intent.idl.compiler.functions
 import org.junit.jupiter.api.Test
 
 /**
-  * Tests for IDL functions.
+  * Tests for 'collections' functions.
   */
 class NCIdlFunctionsColl extends NCIdlFunctions {
     @Test
     def test(): Unit =
         test(
-            // BoolFunc(boolCondition = "first(list(1, 2, 3)) == 1"),
-            // BoolFunc(boolCondition = "last(list(1, 2, 3)) == 3")
             TrueFunc(truth = "is_empty(list()) == true"),
             TrueFunc(truth = "is_empty(list(1)) == false"),
             TrueFunc(truth = "non_empty(list()) == false"),
-            TrueFunc(truth = "non_empty(list(1)) == true")
+            TrueFunc(truth = "non_empty(list(1)) == true"),
+            TrueFunc(truth = "first(list(1, 2, 3)) == 1"),
+            TrueFunc(truth = "last(list(1, 2, 3)) == 3")
         )
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala
index 9554ad2..3ad354c 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala
@@ -25,7 +25,7 @@ import java.util
 import java.util.Optional
 
 /**
-  * Tests for IDL functions.
+  * Tests for 'company' functions.
   */
 class NCIdlFunctionsCompany extends NCRestSpec with NCIdlFunctions {
     private var company: NCCompany = _
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala
index cb8901e..31125a7 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala
@@ -19,16 +19,38 @@ package org.apache.nlpcraft.model.intent.idl.compiler.functions
 
 import org.junit.jupiter.api.Test
 
+import java.time.temporal.IsoFields
+import java.time.{LocalDate, LocalTime}
+import java.util.Calendar
+
 /**
-  * Tests for IDL functions.
+  * Tests for 'dates' functions.
   */
 class NCIdlFunctionsDate extends NCIdlFunctions {
     @Test
     def test(): Unit = {
-        val now = System.currentTimeMillis()
+        def test0(): Unit =
+            test(
+                TrueFunc(truth = s"year() - ${LocalDate.now.getYear} == 0"),
+                TrueFunc(truth = s"month() - ${LocalDate.now.getMonthValue} == 0"),
+                TrueFunc(truth = s"day_of_month() - ${LocalDate.now.getDayOfMonth} == 0"),
+                TrueFunc(truth = s"day_of_week() - ${LocalDate.now.getDayOfWeek.getValue} == 0"),
+                TrueFunc(truth = s"day_of_year() - ${LocalDate.now.getDayOfYear} == 0"),
+                TrueFunc(truth = s"hour() - ${LocalTime.now.getHour} == 0"),
+                TrueFunc(truth = s"minute() - ${LocalTime.now.getMinute} == 0"),
+                TrueFunc(truth = s"second() - ${LocalTime.now.getSecond} < 5"),
+                TrueFunc(truth = s"week_of_month() - ${Calendar.getInstance().get(Calendar.WEEK_OF_MONTH)} == 0"),
+                TrueFunc(truth = s"week_of_year() - ${Calendar.getInstance().get(Calendar.WEEK_OF_YEAR)} == 0"),
+                TrueFunc(truth = s"quarter() - ${LocalDate.now().get(IsoFields.QUARTER_OF_YEAR)} == 0"),
+                TrueFunc(truth = s"now() - ${System.currentTimeMillis()} < 5000")
+            )
 
-        test(
-            TrueFunc(truth = s"now() - $now < 1000")
-        )
+        try
+            test0()
+        catch {
+            case _: AssertionError ⇒
+                // Some field more than `second` can be changed. One more attempt.
+                test0()
+        }
     }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
index 1e9ffe0..aa16f41 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
@@ -20,7 +20,7 @@ package org.apache.nlpcraft.model.intent.idl.compiler.functions
 import org.junit.jupiter.api.Test
 
 /**
-  * Tests for IDL functions.
+  * Tests for 'math' functions.
   */
 class NCIdlFunctionsMath extends NCIdlFunctions {
     @Test
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
index aad7973..998b39b 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
@@ -20,7 +20,7 @@ package org.apache.nlpcraft.model.intent.idl.compiler.functions
 import org.junit.jupiter.api.Test
 
 /**
-  * Tests for IDL functions.
+  * Tests for 'requests' functions.
   */
 class NCIdlFunctionsRequest extends NCIdlFunctions {
     @Test
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStat.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStat.scala
index bed9c30..674085b 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStat.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStat.scala
@@ -20,13 +20,13 @@ package org.apache.nlpcraft.model.intent.idl.compiler.functions
 import org.junit.jupiter.api.Test
 
 /**
-  * Tests for IDL functions.
+  * Tests for 'stat' functions.
   */
 class NCIdlFunctionsStat extends NCIdlFunctions {
     @Test
     def test(): Unit =
         test(
-             TrueFunc(truth = "max(list(1, 2, 3)) == 3"),
-             TrueFunc(truth = "min(list(1, 2, 3)) == 1")
+            TrueFunc(truth = "max(list(1, 2, 3)) == 3"),
+            TrueFunc(truth = "min(list(1, 2, 3)) == 1")
         )
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
index c09dc3d..b370f9c 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
@@ -20,7 +20,7 @@ package org.apache.nlpcraft.model.intent.idl.compiler.functions
 import org.junit.jupiter.api.Test
 
 /**
-  * Tests for IDL functions.
+  * Tests for 'strings' functions.
   */
 class NCIdlFunctionsStrings extends NCIdlFunctions {
     @Test
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 272fac9..d2e8b63 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
@@ -20,7 +20,7 @@ package org.apache.nlpcraft.model.intent.idl.compiler.functions
 import org.junit.jupiter.api.Test
 
 /**
-  * Tests for IDL functions.
+  * Tests for 'tokens' functions.
   */
 class NCIdlFunctionsToken extends NCIdlFunctions {
     @Test
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala
index 6d874c7..2df88d9 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala
@@ -25,7 +25,7 @@ import java.util
 import java.util.Optional
 
 /**
-  * Tests for IDL functions.
+  * Tests for 'user' functions.
   */
 class NCIdlFunctionsUser extends NCRestSpec with NCIdlFunctions {
     private var usr: NCUser = _

[incubator-nlpcraft] 03/04: WIP.

Posted by se...@apache.org.
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

commit d5eb9da623a3c4cf568adb0f6f4f5ff5691f6209
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Tue Mar 23 13:20:53 2021 +0300

    WIP.
---
 .../idl/compiler/functions/NCIdlFunctions.scala    | 45 ++++++++--------------
 .../compiler/functions/NCIdlFunctionsColl.scala    |  8 ++--
 .../compiler/functions/NCIdlFunctionsCompany.scala |  7 +++-
 .../compiler/functions/NCIdlFunctionsDate.scala    |  2 +-
 .../compiler/functions/NCIdlFunctionsMath.scala    |  6 +--
 .../compiler/functions/NCIdlFunctionsRequest.scala |  7 +++-
 .../compiler/functions/NCIdlFunctionsStat.scala    |  4 +-
 .../compiler/functions/NCIdlFunctionsStrings.scala | 12 +++---
 .../compiler/functions/NCIdlFunctionsToken.scala   | 11 ++++--
 .../compiler/functions/NCIdlFunctionsUser.scala    |  7 +++-
 10 files changed, 55 insertions(+), 54 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 b65dc4c..b059f23 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,25 +43,27 @@ private[functions] trait NCIdlFunctions {
     @BeforeEach
     def before(): Unit = NCIdlCompilerGlobal.clearCache(MODEL_ID)
 
-    import BoolFunc._
+    import TrueFunc._
 
-    case class BoolFunc(
-        func: NCIdlFunction,
-        token: NCToken,
-        idlContext: NCIdlContext
+    case class TrueFunc(
+        truth: String,
+        token: NCToken = tkn(),
+        idlCtx: NCIdlContext = ctx()
     ) {
+        val function: NCIdlFunction = mkFunc(truth)
+
         override def toString: String =
             s"Boolean function [" +
                 s"token=${t2s(token)}, " +
-                s"function=$func" +
+                s"function=$truth" +
                 s"]"
     }
 
-    object BoolFunc {
+    object TrueFunc {
         private def t2s(t: NCToken) = s"${t.getOriginalText} (${t.getId})"
 
-        private def mkFunc(term: String): NCIdlFunction = {
-            val intents = NCIdlCompiler.compileIntents(s"intent=i term(t)={$term}", MODEL, MODEL_ID)
+        private def mkFunc(function: String): NCIdlFunction = {
+            val intents = NCIdlCompiler.compileIntents(s"intent=i term(t)={$function}", MODEL, MODEL_ID)
 
             require(intents.size == 1)
 
@@ -71,24 +73,12 @@ private[functions] trait NCIdlFunctions {
 
             new NCIdlFunction() {
                 override def apply(v1: NCToken, v2: NCIdlContext): NCIdlStackItem = intent.terms.head.pred.apply(v1, v2)
-                override def toString(): String = s"Function, based on term: $term"
+                override def toString(): String = s"Function, based on term: $function"
             }
         }
-
-        def apply(bool: String, tokenId: String): BoolFunc =
-            BoolFunc(func = mkFunc(bool), token = mkToken(tokenId), idlContext = mkIdlContext())
-
-        def apply(bool: String, token: NCToken): BoolFunc =
-            BoolFunc(func = mkFunc(bool), token, idlContext = mkIdlContext())
-
-        def apply(bool: String, idlContext: NCIdlContext): BoolFunc =
-            BoolFunc(func = mkFunc(bool), mkToken(), idlContext)
-
-        def apply(bool: String): BoolFunc =
-            BoolFunc(func = mkFunc(bool), mkToken(), idlContext = mkIdlContext())
     }
 
-    protected def mkIdlContext(
+    protected def ctx(
         usr: NCUser = null,
         comp: NCCompany = null,
         srvReqId: String = null,
@@ -97,7 +87,7 @@ private[functions] trait NCIdlFunctions {
         remAddress: String = null,
         clientAgent: String = null,
         reqData: Map[String, AnyRef] = Map.empty[String, AnyRef]
-    ): NCIdlContext = {
+    ): NCIdlContext =
         NCIdlContext(
             req =
                 new NCRequest() {
@@ -111,9 +101,8 @@ private[functions] trait NCIdlFunctions {
                     override def getRequestData: util.Map[String, AnyRef] = reqData.asJava
                 }
         )
-    }
 
-    protected def mkToken(
+    protected def tkn(
         id: String = null,
         srvReqId: String = null,
         parentId: String = null,
@@ -153,11 +142,11 @@ private[functions] trait NCIdlFunctions {
         }
     }
 
-    protected def test(funcs: BoolFunc*): Unit =
+    protected def test(funcs: TrueFunc*): Unit =
         for ((func, idx) ← funcs.zipWithIndex) {
             val res =
                 try
-                    func.func.apply(func.token, func.idlContext).value
+                    func.function.apply(func.token, func.idlCtx).value
                 catch {
                     case e: Exception ⇒ throw new Exception(s"Execution error [index=$idx, testFunc=$func]", e)
                 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsColl.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsColl.scala
index 0fe5523..ba253cd 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsColl.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsColl.scala
@@ -28,9 +28,9 @@ class NCIdlFunctionsColl extends NCIdlFunctions {
         test(
             // BoolFunc(boolCondition = "first(list(1, 2, 3)) == 1"),
             // BoolFunc(boolCondition = "last(list(1, 2, 3)) == 3")
-            BoolFunc(bool = "is_empty(list()) == true"),
-            BoolFunc(bool = "is_empty(list(1)) == false"),
-            BoolFunc(bool = "non_empty(list()) == false"),
-            BoolFunc(bool = "non_empty(list(1)) == true")
+            TrueFunc(truth = "is_empty(list()) == true"),
+            TrueFunc(truth = "is_empty(list(1)) == false"),
+            TrueFunc(truth = "non_empty(list()) == false"),
+            TrueFunc(truth = "non_empty(list(1)) == true")
         )
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala
index 35976ab..9554ad2 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala
@@ -67,10 +67,13 @@ class NCIdlFunctionsCompany extends NCRestSpec with NCIdlFunctions {
 
     @Test
     def test(): Unit = {
-        val ctx = mkIdlContext(comp = company)
+        val idlCtx = ctx(comp = company)
 
         test(
-            BoolFunc(s"comp_name() == '${company.getName}'", ctx)
+            TrueFunc(
+                truth = s"comp_name() == '${company.getName}'",
+                idlCtx = idlCtx
+            )
         )
     }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala
index 34cbe19..cb8901e 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala
@@ -28,7 +28,7 @@ class NCIdlFunctionsDate extends NCIdlFunctions {
         val now = System.currentTimeMillis()
 
         test(
-            BoolFunc(bool = s"now() - $now < 1000")
+            TrueFunc(truth = s"now() - $now < 1000")
         )
     }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
index cb7da1b..1e9ffe0 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
@@ -26,8 +26,8 @@ class NCIdlFunctionsMath extends NCIdlFunctions {
     @Test
     def test(): Unit =
         test(
-            BoolFunc(bool = "sin(90.0) == 0"),
-            BoolFunc(bool = "sin(90) == 0"),
-            BoolFunc(bool = "rand() < 1")
+            TrueFunc(truth = "sin(90.0) == 0"),
+            TrueFunc(truth = "sin(90) == 0"),
+            TrueFunc(truth = "rand() < 1")
         )
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
index d60c2ca..aad7973 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
@@ -25,10 +25,13 @@ import org.junit.jupiter.api.Test
 class NCIdlFunctionsRequest extends NCIdlFunctions {
     @Test
     def test(): Unit = {
-        val ctx = mkIdlContext(srvReqId = "req.id")
+        val idlCtx = ctx(srvReqId = "req.id")
 
         test(
-            BoolFunc(s"req_id() == '${ctx.req.getServerRequestId}'", ctx)
+            TrueFunc(
+                truth = s"req_id() == '${idlCtx.req.getServerRequestId}'",
+                idlCtx = idlCtx
+            )
         )
     }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStat.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStat.scala
index d6aeabc..bed9c30 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStat.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStat.scala
@@ -26,7 +26,7 @@ class NCIdlFunctionsStat extends NCIdlFunctions {
     @Test
     def test(): Unit =
         test(
-             BoolFunc(bool = "max(list(1, 2, 3)) == 3"),
-             BoolFunc(bool = "min(list(1, 2, 3)) == 1")
+             TrueFunc(truth = "max(list(1, 2, 3)) == 3"),
+             TrueFunc(truth = "min(list(1, 2, 3)) == 1")
         )
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
index c2fd3b7..c09dc3d 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
@@ -26,11 +26,11 @@ class NCIdlFunctionsStrings extends NCIdlFunctions {
     @Test
     def test(): Unit =
         test(
-            BoolFunc(bool = "trim(' a b  ') == 'a b'"),
-            BoolFunc(bool = "strip(' a b  ') == 'a b'"),
-            BoolFunc(bool = "uppercase('aB') == 'AB'"),
-            BoolFunc(bool = "lowercase('aB') == 'ab'"),
-            BoolFunc(bool = "is_num('a') == false"),
-            BoolFunc(bool = "is_num('1') == true")
+            TrueFunc(truth = "trim(' a b  ') == 'a b'"),
+            TrueFunc(truth = "strip(' a b  ') == 'a b'"),
+            TrueFunc(truth = "uppercase('aB') == 'AB'"),
+            TrueFunc(truth = "lowercase('aB') == 'ab'"),
+            TrueFunc(truth = "is_num('a') == false"),
+            TrueFunc(truth = "is_num('1') == true")
         )
 }
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 1f5a823..272fac9 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
@@ -26,10 +26,13 @@ class NCIdlFunctionsToken extends NCIdlFunctions {
     @Test
     def test(): Unit =
         test(
-            BoolFunc(bool = "id() == 'a'", "a"),
-            BoolFunc(
-                bool = "parent() == 'a'",
-                mkToken(parentId = "a")
+            TrueFunc(
+                truth = "id() == 'a'",
+                tkn(id = "a")
+            ),
+            TrueFunc(
+                truth = "parent() == 'a'",
+                tkn(parentId = "a")
             )
         )
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala
index 3c4560b..6d874c7 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala
@@ -63,10 +63,13 @@ class NCIdlFunctionsUser extends NCRestSpec with NCIdlFunctions {
 
     @Test
     def test(): Unit =  {
-        val ctx = mkIdlContext(usr = usr)
+        val idlCtx = ctx(usr = usr)
 
         test(
-            BoolFunc(s"user_email() == '${usr.getEmail.get()}'", ctx)
+            TrueFunc(
+                truth = s"user_email() == '${usr.getEmail.get()}'",
+                idlCtx = idlCtx
+            )
         )
     }
 }

[incubator-nlpcraft] 01/04: WIP.

Posted by se...@apache.org.
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

commit dedcf823693a82936c10866c795b16ae7ee1a913
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Tue Mar 23 11:52:57 2021 +0300

    WIP.
---
 .../idl/compiler/NCIdlCompilerSpecFunctions.scala  | 192 +++++++++++++++++++++
 1 file changed, 192 insertions(+)

diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpecFunctions.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpecFunctions.scala
new file mode 100644
index 0000000..5f3c687
--- /dev/null
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpecFunctions.scala
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.model.intent.idl.compiler
+
+import org.apache.nlpcraft.model.intent.compiler.{NCIdlCompiler, NCIdlCompilerGlobal}
+import org.apache.nlpcraft.model.intent.{NCIdlContext, NCIdlFunction, NCIdlStackItem}
+import org.apache.nlpcraft.model.{NCModel, NCModelView, NCToken}
+import org.junit.jupiter.api.{BeforeEach, Test}
+
+import java.util
+import java.util.{Collections, UUID}
+import scala.collection.JavaConverters._
+
+/**
+  * Tests for IDL functions.
+  */
+class NCIdlCompilerSpecFunctions {
+    private final val MODEL_ID = "test.mdl.id"
+
+    private final val MODEL: NCModel = new NCModel {
+        override val getId: String = MODEL_ID
+        override val getName: String = MODEL_ID
+        override val getVersion: String = "1.0.0"
+
+        override def getOrigin: String = "test"
+    }
+
+    private final val DUMMY_CTX: NCIdlContext = NCIdlContext(req = null)
+
+    @BeforeEach
+    def before(): Unit = NCIdlCompilerGlobal.clearCache(MODEL_ID)
+
+    import BoolFunc._
+
+    case class BoolFunc(func: NCIdlFunction, token: NCToken, result: Boolean) {
+        override def toString: String =
+            s"Boolean function [" +
+                s"token=${t2s(token)}, " +
+                s"function=$func, " +
+                s"expected=$result" +
+                s"]"
+    }
+
+    object BoolFunc {
+        private def t2s(t: NCToken) = s"${t.getOriginalText} (${t.getId})"
+
+        private def mkToken(
+            id: String = null,
+            value: String = null,
+            txt: String = null,
+            start: Int = 0,
+            end: Int = 0,
+            meta: Map[String, AnyRef] = Map.empty[String, AnyRef]
+        ): NCToken = {
+            val map = new util.HashMap[String, AnyRef]
+
+            map.putAll(meta.asJava)
+
+            def nvl(v: String): String = if (v != null) v else "(not set)"
+
+            map.put("nlpcraft:nlp:origtext", nvl(txt))
+
+            new NCToken {
+                override def getModel: NCModelView = MODEL
+                override def getServerRequestId: String = UUID.randomUUID().toString
+                override def getId: String = nvl(id)
+                override def getParentId: String = null
+                override def getAncestors: util.List[String] = Collections.emptyList()
+                override def getPartTokens: util.List[NCToken] = Collections.emptyList()
+                override def getAliases: util.Set[String] = Collections.emptySet()
+                override def getValue: String = value
+                override def getGroups: util.List[String] = Collections.singletonList(id)
+                override def getStartCharIndex: Int = start
+                override def getEndCharIndex: Int = end
+                override def isAbstract: Boolean = false
+                override def getMetadata: util.Map[String, AnyRef] = map
+            }
+        }
+
+        private def mkFunc(term: String): NCIdlFunction = {
+            val intents = NCIdlCompiler.compileIntents(s"intent=i term(t)={$term}", MODEL, MODEL_ID)
+
+            require(intents.size == 1)
+
+            val intent = intents.head
+
+            require(intent.terms.size == 1)
+
+            new NCIdlFunction() {
+                override def apply(v1: NCToken, v2: NCIdlContext): NCIdlStackItem = intent.terms.head.pred.apply(v1, v2)
+                override def toString(): String = s"Function, based on term: $term"
+            }
+        }
+
+        def apply(boolCondition: String, token: String, result: Boolean): BoolFunc =
+            BoolFunc(func = mkFunc(boolCondition), token = mkToken(token), result = result)
+
+        def apply(boolCondition: String, tokenId: String): BoolFunc =
+            BoolFunc(func = mkFunc(boolCondition), token = mkToken(tokenId), result = true)
+
+        def apply(boolCondition: String, token: NCToken, result: Boolean): BoolFunc =
+            BoolFunc(func = mkFunc(boolCondition), token, result = result)
+
+        def apply(bool: String): BoolFunc =
+            BoolFunc(func = mkFunc(bool), mkToken(), result = true)
+    }
+
+    private def test(funcs: BoolFunc*): Unit =
+        for ((func, idx) ← funcs.zipWithIndex) {
+            val res =
+                try
+                    func.func.apply(func.token, DUMMY_CTX).value
+                catch {
+                    case e: Exception ⇒ throw new Exception(s"Execution error [index=$idx, testFunc=$func]", e)
+                }
+
+                res match {
+                    case b: java.lang.Boolean ⇒
+                        require(b == func.result,
+                            s"Unexpected result [" +
+                                s"index=$idx, " +
+                                s"testFunc=$func, " +
+                                s"expected=${func.result}, " +
+                                s"result=$res" +
+                                s"]"
+                        )
+                    case _ ⇒
+                        require(requirement = false,
+                            s"Unexpected result type [" +
+                                s"index=$idx, " +
+                                s"testFunc=$func, " +
+                                s"expected=${func.result}, " +
+                                s"result=$res" +
+                                s"]"
+                        )
+                }
+
+        }
+
+    @Test
+    def test(): Unit = {
+        val now = System.currentTimeMillis()
+
+        test(
+            BoolFunc(boolCondition = "id() == 'a'", tokenId = "a"),
+
+            // Math.
+            // BoolFunc(boolCondition = "sin(90.0) == 0")
+            // BoolFunc(boolCondition = "rand() < 1")
+
+            // String.
+            BoolFunc(bool = "trim(' a b  ') == 'a b'"),
+            BoolFunc(bool = "strip(' a b  ') == 'a b'"),
+            BoolFunc(bool = "uppercase('aB') == 'AB'"),
+            BoolFunc(bool = "lowercase('aB') == 'ab'"),
+            BoolFunc(bool = "is_num('a') == false"),
+            BoolFunc(bool = "is_num('1') == true"),
+
+            // Statistical.
+            // BoolFunc(boolCondition = "max(list(1, 2, 3)) == 3"),
+            // BoolFunc(boolCondition = "min(list(1, 2, 3)) == 1")
+
+            // Collection.
+            // BoolFunc(boolCondition = "first(list(1, 2, 3)) == 1"),
+            // BoolFunc(boolCondition = "last(list(1, 2, 3)) == 3")
+            BoolFunc(bool = "is_empty(list()) == true"),
+            BoolFunc(bool = "is_empty(list(1)) == false"),
+            BoolFunc(bool = "non_empty(list()) == false"),
+            BoolFunc(bool = "non_empty(list(1)) == true"),
+
+            // Date-time functions.
+
+
+            BoolFunc(bool = s"now() - $now < 1000")
+        )
+    }
+}

[incubator-nlpcraft] 02/04: WIP.

Posted by se...@apache.org.
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

commit 27b900f200cca2470eaaa9ea23150628eace6dbb
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Tue Mar 23 13:03:25 2021 +0300

    WIP.
---
 .../idl/compiler/NCIdlCompilerSpecFunctions.scala  | 192 ---------------------
 .../idl/compiler/functions/NCIdlFunctions.scala    | 185 ++++++++++++++++++++
 .../compiler/functions/NCIdlFunctionsColl.scala    |  36 ++++
 .../compiler/functions/NCIdlFunctionsCompany.scala |  76 ++++++++
 .../compiler/functions/NCIdlFunctionsDate.scala    |  34 ++++
 .../compiler/functions/NCIdlFunctionsMath.scala    |  33 ++++
 .../compiler/functions/NCIdlFunctionsRequest.scala |  34 ++++
 .../compiler/functions/NCIdlFunctionsStat.scala    |  32 ++++
 .../compiler/functions/NCIdlFunctionsStrings.scala |  36 ++++
 .../compiler/functions/NCIdlFunctionsToken.scala   |  35 ++++
 .../compiler/functions/NCIdlFunctionsUser.scala    |  72 ++++++++
 11 files changed, 573 insertions(+), 192 deletions(-)

diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpecFunctions.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpecFunctions.scala
deleted file mode 100644
index 5f3c687..0000000
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpecFunctions.scala
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.nlpcraft.model.intent.idl.compiler
-
-import org.apache.nlpcraft.model.intent.compiler.{NCIdlCompiler, NCIdlCompilerGlobal}
-import org.apache.nlpcraft.model.intent.{NCIdlContext, NCIdlFunction, NCIdlStackItem}
-import org.apache.nlpcraft.model.{NCModel, NCModelView, NCToken}
-import org.junit.jupiter.api.{BeforeEach, Test}
-
-import java.util
-import java.util.{Collections, UUID}
-import scala.collection.JavaConverters._
-
-/**
-  * Tests for IDL functions.
-  */
-class NCIdlCompilerSpecFunctions {
-    private final val MODEL_ID = "test.mdl.id"
-
-    private final val MODEL: NCModel = new NCModel {
-        override val getId: String = MODEL_ID
-        override val getName: String = MODEL_ID
-        override val getVersion: String = "1.0.0"
-
-        override def getOrigin: String = "test"
-    }
-
-    private final val DUMMY_CTX: NCIdlContext = NCIdlContext(req = null)
-
-    @BeforeEach
-    def before(): Unit = NCIdlCompilerGlobal.clearCache(MODEL_ID)
-
-    import BoolFunc._
-
-    case class BoolFunc(func: NCIdlFunction, token: NCToken, result: Boolean) {
-        override def toString: String =
-            s"Boolean function [" +
-                s"token=${t2s(token)}, " +
-                s"function=$func, " +
-                s"expected=$result" +
-                s"]"
-    }
-
-    object BoolFunc {
-        private def t2s(t: NCToken) = s"${t.getOriginalText} (${t.getId})"
-
-        private def mkToken(
-            id: String = null,
-            value: String = null,
-            txt: String = null,
-            start: Int = 0,
-            end: Int = 0,
-            meta: Map[String, AnyRef] = Map.empty[String, AnyRef]
-        ): NCToken = {
-            val map = new util.HashMap[String, AnyRef]
-
-            map.putAll(meta.asJava)
-
-            def nvl(v: String): String = if (v != null) v else "(not set)"
-
-            map.put("nlpcraft:nlp:origtext", nvl(txt))
-
-            new NCToken {
-                override def getModel: NCModelView = MODEL
-                override def getServerRequestId: String = UUID.randomUUID().toString
-                override def getId: String = nvl(id)
-                override def getParentId: String = null
-                override def getAncestors: util.List[String] = Collections.emptyList()
-                override def getPartTokens: util.List[NCToken] = Collections.emptyList()
-                override def getAliases: util.Set[String] = Collections.emptySet()
-                override def getValue: String = value
-                override def getGroups: util.List[String] = Collections.singletonList(id)
-                override def getStartCharIndex: Int = start
-                override def getEndCharIndex: Int = end
-                override def isAbstract: Boolean = false
-                override def getMetadata: util.Map[String, AnyRef] = map
-            }
-        }
-
-        private def mkFunc(term: String): NCIdlFunction = {
-            val intents = NCIdlCompiler.compileIntents(s"intent=i term(t)={$term}", MODEL, MODEL_ID)
-
-            require(intents.size == 1)
-
-            val intent = intents.head
-
-            require(intent.terms.size == 1)
-
-            new NCIdlFunction() {
-                override def apply(v1: NCToken, v2: NCIdlContext): NCIdlStackItem = intent.terms.head.pred.apply(v1, v2)
-                override def toString(): String = s"Function, based on term: $term"
-            }
-        }
-
-        def apply(boolCondition: String, token: String, result: Boolean): BoolFunc =
-            BoolFunc(func = mkFunc(boolCondition), token = mkToken(token), result = result)
-
-        def apply(boolCondition: String, tokenId: String): BoolFunc =
-            BoolFunc(func = mkFunc(boolCondition), token = mkToken(tokenId), result = true)
-
-        def apply(boolCondition: String, token: NCToken, result: Boolean): BoolFunc =
-            BoolFunc(func = mkFunc(boolCondition), token, result = result)
-
-        def apply(bool: String): BoolFunc =
-            BoolFunc(func = mkFunc(bool), mkToken(), result = true)
-    }
-
-    private def test(funcs: BoolFunc*): Unit =
-        for ((func, idx) ← funcs.zipWithIndex) {
-            val res =
-                try
-                    func.func.apply(func.token, DUMMY_CTX).value
-                catch {
-                    case e: Exception ⇒ throw new Exception(s"Execution error [index=$idx, testFunc=$func]", e)
-                }
-
-                res match {
-                    case b: java.lang.Boolean ⇒
-                        require(b == func.result,
-                            s"Unexpected result [" +
-                                s"index=$idx, " +
-                                s"testFunc=$func, " +
-                                s"expected=${func.result}, " +
-                                s"result=$res" +
-                                s"]"
-                        )
-                    case _ ⇒
-                        require(requirement = false,
-                            s"Unexpected result type [" +
-                                s"index=$idx, " +
-                                s"testFunc=$func, " +
-                                s"expected=${func.result}, " +
-                                s"result=$res" +
-                                s"]"
-                        )
-                }
-
-        }
-
-    @Test
-    def test(): Unit = {
-        val now = System.currentTimeMillis()
-
-        test(
-            BoolFunc(boolCondition = "id() == 'a'", tokenId = "a"),
-
-            // Math.
-            // BoolFunc(boolCondition = "sin(90.0) == 0")
-            // BoolFunc(boolCondition = "rand() < 1")
-
-            // String.
-            BoolFunc(bool = "trim(' a b  ') == 'a b'"),
-            BoolFunc(bool = "strip(' a b  ') == 'a b'"),
-            BoolFunc(bool = "uppercase('aB') == 'AB'"),
-            BoolFunc(bool = "lowercase('aB') == 'ab'"),
-            BoolFunc(bool = "is_num('a') == false"),
-            BoolFunc(bool = "is_num('1') == true"),
-
-            // Statistical.
-            // BoolFunc(boolCondition = "max(list(1, 2, 3)) == 3"),
-            // BoolFunc(boolCondition = "min(list(1, 2, 3)) == 1")
-
-            // Collection.
-            // BoolFunc(boolCondition = "first(list(1, 2, 3)) == 1"),
-            // BoolFunc(boolCondition = "last(list(1, 2, 3)) == 3")
-            BoolFunc(bool = "is_empty(list()) == true"),
-            BoolFunc(bool = "is_empty(list(1)) == false"),
-            BoolFunc(bool = "non_empty(list()) == false"),
-            BoolFunc(bool = "non_empty(list(1)) == true"),
-
-            // Date-time functions.
-
-
-            BoolFunc(bool = s"now() - $now < 1000")
-        )
-    }
-}
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
new file mode 100644
index 0000000..b65dc4c
--- /dev/null
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.model.intent.idl.compiler.functions
+
+import org.apache.nlpcraft.model.intent.compiler.{NCIdlCompiler, NCIdlCompilerGlobal}
+import org.apache.nlpcraft.model.intent.{NCIdlContext, NCIdlFunction, NCIdlStackItem}
+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._
+
+/**
+  * Tests for IDL functions.
+  */
+private[functions] trait NCIdlFunctions {
+    private final val MODEL_ID = "test.mdl.id"
+
+    private final val MODEL: NCModel = new NCModel {
+        override val getId: String = MODEL_ID
+        override val getName: String = MODEL_ID
+        override val getVersion: String = "1.0.0"
+
+        override def getOrigin: String = "test"
+    }
+
+    @BeforeEach
+    def before(): Unit = NCIdlCompilerGlobal.clearCache(MODEL_ID)
+
+    import BoolFunc._
+
+    case class BoolFunc(
+        func: NCIdlFunction,
+        token: NCToken,
+        idlContext: NCIdlContext
+    ) {
+        override def toString: String =
+            s"Boolean function [" +
+                s"token=${t2s(token)}, " +
+                s"function=$func" +
+                s"]"
+    }
+
+    object BoolFunc {
+        private def t2s(t: NCToken) = s"${t.getOriginalText} (${t.getId})"
+
+        private def mkFunc(term: String): NCIdlFunction = {
+            val intents = NCIdlCompiler.compileIntents(s"intent=i term(t)={$term}", MODEL, MODEL_ID)
+
+            require(intents.size == 1)
+
+            val intent = intents.head
+
+            require(intent.terms.size == 1)
+
+            new NCIdlFunction() {
+                override def apply(v1: NCToken, v2: NCIdlContext): NCIdlStackItem = intent.terms.head.pred.apply(v1, v2)
+                override def toString(): String = s"Function, based on term: $term"
+            }
+        }
+
+        def apply(bool: String, tokenId: String): BoolFunc =
+            BoolFunc(func = mkFunc(bool), token = mkToken(tokenId), idlContext = mkIdlContext())
+
+        def apply(bool: String, token: NCToken): BoolFunc =
+            BoolFunc(func = mkFunc(bool), token, idlContext = mkIdlContext())
+
+        def apply(bool: String, idlContext: NCIdlContext): BoolFunc =
+            BoolFunc(func = mkFunc(bool), mkToken(), idlContext)
+
+        def apply(bool: String): BoolFunc =
+            BoolFunc(func = mkFunc(bool), mkToken(), idlContext = mkIdlContext())
+    }
+
+    protected def mkIdlContext(
+        usr: NCUser = null,
+        comp: NCCompany = null,
+        srvReqId: String = null,
+        normTxt: String = null,
+        recTimestamp: Long = 0,
+        remAddress: String = null,
+        clientAgent: String = null,
+        reqData: Map[String, AnyRef] = Map.empty[String, AnyRef]
+    ): NCIdlContext = {
+        NCIdlContext(
+            req =
+                new NCRequest() {
+                    override def getUser: NCUser = usr
+                    override def getCompany: NCCompany = comp
+                    override def getServerRequestId: String = srvReqId
+                    override def getNormalizedText: String = normTxt
+                    override def getReceiveTimestamp: Long = recTimestamp
+                    override def getRemoteAddress: Optional[String] = Optional.ofNullable(remAddress)
+                    override def getClientAgent: Optional[String] = Optional.ofNullable(clientAgent)
+                    override def getRequestData: util.Map[String, AnyRef] = reqData.asJava
+                }
+        )
+    }
+
+    protected def mkToken(
+        id: String = null,
+        srvReqId: String = null,
+        parentId: String = null,
+        value: String = null,
+        txt: String = null,
+        start: Int = 0,
+        end: Int = 0,
+        groups: Seq[String] = Seq.empty,
+        ancestors: Seq[String] = Seq.empty,
+        aliases: Set[String] = Set.empty,
+        partTokens: Seq[NCToken] = Seq.empty,
+        meta: Map[String, AnyRef] = Map.empty[String, AnyRef]
+    ): NCToken = {
+        val map = new util.HashMap[String, AnyRef]
+
+        map.putAll(meta.asJava)
+
+        map.put("nlpcraft:nlp:origtext", txt)
+        map.put("nlpcraft:nlp:origtext", txt)
+
+        new NCToken {
+            override def getModel: NCModelView = MODEL
+
+            override def getServerRequestId: String = srvReqId
+            override def getId: String = id
+            override def getParentId: String = parentId
+            override def getAncestors: util.List[String] = ancestors.asJava
+            override def getPartTokens: util.List[NCToken] = partTokens.asJava
+            override def getAliases: util.Set[String] = aliases.asJava
+            override def getValue: String = value
+            override def getGroups: util.List[String] =
+                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 getMetadata: util.Map[String, AnyRef] = map
+        }
+    }
+
+    protected def test(funcs: BoolFunc*): Unit =
+        for ((func, idx) ← funcs.zipWithIndex) {
+            val res =
+                try
+                    func.func.apply(func.token, func.idlContext).value
+                catch {
+                    case e: Exception ⇒ throw new Exception(s"Execution error [index=$idx, testFunc=$func]", e)
+                }
+
+            res match {
+                case b: java.lang.Boolean ⇒
+                    require(b,
+                        s"Unexpected result [" +
+                            s"index=$idx, " +
+                            s"testFunc=$func, " +
+                            s"result=$res" +
+                            s"]"
+                    )
+                case _ ⇒
+                    require(requirement = false,
+                        s"Unexpected result type [" +
+                            s"index=$idx, " +
+                            s"testFunc=$func, " +
+                            s"result=$res" +
+                            s"]"
+                    )
+            }
+
+        }
+}
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsColl.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsColl.scala
new file mode 100644
index 0000000..0fe5523
--- /dev/null
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsColl.scala
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.model.intent.idl.compiler.functions
+
+import org.junit.jupiter.api.Test
+
+/**
+  * Tests for IDL functions.
+  */
+class NCIdlFunctionsColl extends NCIdlFunctions {
+    @Test
+    def test(): Unit =
+        test(
+            // BoolFunc(boolCondition = "first(list(1, 2, 3)) == 1"),
+            // BoolFunc(boolCondition = "last(list(1, 2, 3)) == 3")
+            BoolFunc(bool = "is_empty(list()) == true"),
+            BoolFunc(bool = "is_empty(list(1)) == false"),
+            BoolFunc(bool = "non_empty(list()) == false"),
+            BoolFunc(bool = "non_empty(list(1)) == true")
+        )
+}
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala
new file mode 100644
index 0000000..35976ab
--- /dev/null
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.model.intent.idl.compiler.functions
+
+import org.apache.nlpcraft.model.NCCompany
+import org.apache.nlpcraft.server.rest.NCRestSpec
+import org.junit.jupiter.api.{BeforeEach, Test}
+
+import java.util
+import java.util.Optional
+
+/**
+  * Tests for IDL functions.
+  */
+class NCIdlFunctionsCompany extends NCRestSpec with NCIdlFunctions {
+    private var company: NCCompany = _
+
+    @BeforeEach
+    def setCompany(): Unit = {
+        var compName: String = null
+        var compWebsite: String = null
+        var compCountry: String = null
+        var compRegion: String = null
+        var compCity: String = null
+        var compAddress: String = null
+        var compPostalCode: String = null
+        var props: java.util.Map[String, AnyRef] = null
+
+        post("company/get")(
+            ("$.name", (v: String) ⇒ compName = v),
+            ("$.website", (v: String) ⇒ compWebsite = v),
+            ("$.country", (v: String) ⇒ compCountry = v),
+            ("$.region", (v: String) ⇒ compRegion = v),
+            ("$.city", (v: String) ⇒ compCity = v),
+            ("$.address", (v: String) ⇒ compAddress = v),
+            ("$.postalCode", (v: String) ⇒ compPostalCode = v),
+            ("$.properties", (v: java.util.Map[String, AnyRef]) ⇒ props = v)
+        )
+
+        company = new NCCompany() {
+            override def getId: Long = -1  // TODO: No REST API data
+            override def getName: String = compName
+            override def getWebsite: Optional[String] = Optional.ofNullable(compWebsite)
+            override def getCountry: Optional[String] = Optional.ofNullable(compCountry)
+            override def getRegion: Optional[String] = Optional.ofNullable(compRegion)
+            override def getCity: Optional[String] = Optional.ofNullable(compCity)
+            override def getAddress: Optional[String] = Optional.ofNullable(compAddress)
+            override def getPostalCode: Optional[String] = Optional.ofNullable(compPostalCode)
+            override def getMetadata: util.Map[String, AnyRef] = props
+        }
+    }
+
+    @Test
+    def test(): Unit = {
+        val ctx = mkIdlContext(comp = company)
+
+        test(
+            BoolFunc(s"comp_name() == '${company.getName}'", ctx)
+        )
+    }
+}
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala
new file mode 100644
index 0000000..34cbe19
--- /dev/null
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsDate.scala
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.model.intent.idl.compiler.functions
+
+import org.junit.jupiter.api.Test
+
+/**
+  * Tests for IDL functions.
+  */
+class NCIdlFunctionsDate extends NCIdlFunctions {
+    @Test
+    def test(): Unit = {
+        val now = System.currentTimeMillis()
+
+        test(
+            BoolFunc(bool = s"now() - $now < 1000")
+        )
+    }
+}
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
new file mode 100644
index 0000000..cb7da1b
--- /dev/null
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.model.intent.idl.compiler.functions
+
+import org.junit.jupiter.api.Test
+
+/**
+  * Tests for IDL functions.
+  */
+class NCIdlFunctionsMath extends NCIdlFunctions {
+    @Test
+    def test(): Unit =
+        test(
+            BoolFunc(bool = "sin(90.0) == 0"),
+            BoolFunc(bool = "sin(90) == 0"),
+            BoolFunc(bool = "rand() < 1")
+        )
+}
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
new file mode 100644
index 0000000..d60c2ca
--- /dev/null
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.model.intent.idl.compiler.functions
+
+import org.junit.jupiter.api.Test
+
+/**
+  * Tests for IDL functions.
+  */
+class NCIdlFunctionsRequest extends NCIdlFunctions {
+    @Test
+    def test(): Unit = {
+        val ctx = mkIdlContext(srvReqId = "req.id")
+
+        test(
+            BoolFunc(s"req_id() == '${ctx.req.getServerRequestId}'", ctx)
+        )
+    }
+}
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStat.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStat.scala
new file mode 100644
index 0000000..d6aeabc
--- /dev/null
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStat.scala
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.model.intent.idl.compiler.functions
+
+import org.junit.jupiter.api.Test
+
+/**
+  * Tests for IDL functions.
+  */
+class NCIdlFunctionsStat extends NCIdlFunctions {
+    @Test
+    def test(): Unit =
+        test(
+             BoolFunc(bool = "max(list(1, 2, 3)) == 3"),
+             BoolFunc(bool = "min(list(1, 2, 3)) == 1")
+        )
+}
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
new file mode 100644
index 0000000..c2fd3b7
--- /dev/null
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.model.intent.idl.compiler.functions
+
+import org.junit.jupiter.api.Test
+
+/**
+  * Tests for IDL functions.
+  */
+class NCIdlFunctionsStrings extends NCIdlFunctions {
+    @Test
+    def test(): Unit =
+        test(
+            BoolFunc(bool = "trim(' a b  ') == 'a b'"),
+            BoolFunc(bool = "strip(' a b  ') == 'a b'"),
+            BoolFunc(bool = "uppercase('aB') == 'AB'"),
+            BoolFunc(bool = "lowercase('aB') == 'ab'"),
+            BoolFunc(bool = "is_num('a') == false"),
+            BoolFunc(bool = "is_num('1') == true")
+        )
+}
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
new file mode 100644
index 0000000..1f5a823
--- /dev/null
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.model.intent.idl.compiler.functions
+
+import org.junit.jupiter.api.Test
+
+/**
+  * Tests for IDL functions.
+  */
+class NCIdlFunctionsToken extends NCIdlFunctions {
+    @Test
+    def test(): Unit =
+        test(
+            BoolFunc(bool = "id() == 'a'", "a"),
+            BoolFunc(
+                bool = "parent() == 'a'",
+                mkToken(parentId = "a")
+            )
+        )
+}
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala
new file mode 100644
index 0000000..3c4560b
--- /dev/null
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.model.intent.idl.compiler.functions
+
+import org.apache.nlpcraft.model.NCUser
+import org.apache.nlpcraft.server.rest.NCRestSpec
+import org.junit.jupiter.api.{BeforeEach, Test}
+
+import java.util
+import java.util.Optional
+
+/**
+  * Tests for IDL functions.
+  */
+class NCIdlFunctionsUser extends NCRestSpec with NCIdlFunctions {
+    private var usr: NCUser = _
+
+    @BeforeEach
+    def setCompany(): Unit = {
+        var firstName: String = null
+        var lastName: String = null
+        var avatarUrl: String = null
+        var email: String = null
+        var adm: Boolean = false
+        var props: java.util.Map[String, AnyRef] = null
+
+        // Checks updated.
+        post("user/get")(
+            ("$.firstName", (v: String) ⇒ firstName = v),
+            ("$.lastName", (v: String) ⇒ lastName = v),
+            ("$.email", (v: String) ⇒ email = v),
+            ("$.avatarUrl", (v: String) ⇒ avatarUrl = v),
+            ("$.isAdmin", (v: Boolean) ⇒ adm = v),
+            ("$.properties", (v: java.util.Map[String, AnyRef]) ⇒ props = v)
+        )
+
+        usr = new NCUser {
+            override def getId: Long = -1  // TODO: No REST API data
+            override def getFirstName: Optional[String] = Optional.ofNullable(firstName)
+            override def getLastName: Optional[String] = Optional.ofNullable(lastName)
+            override def getEmail: Optional[String] = Optional.ofNullable(email)
+            override def getAvatarUrl: Optional[String] = Optional.ofNullable(avatarUrl)
+            override def isAdmin: Boolean = adm
+            override def getSignupTimestamp: Long = -1 // TODO: No REST API data
+            override def getMetadata: util.Map[String, AnyRef] = props
+        }
+    }
+
+    @Test
+    def test(): Unit =  {
+        val ctx = mkIdlContext(usr = usr)
+
+        test(
+            BoolFunc(s"user_email() == '${usr.getEmail.get()}'", ctx)
+        )
+    }
+}