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/25 08:54:47 UTC

[incubator-nlpcraft] branch NLPCRAFT-283 created (now 62c9183)

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

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


      at 62c9183  WIP.

This branch includes the following new commits:

     new 16191ce  WIP.
     new e4c43f3  Merge branch 'NLPCRAFT-278' into NLPCRAFT-283
     new 62c9183  WIP.

The 3 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] 02/03: Merge branch 'NLPCRAFT-278' into NLPCRAFT-283

Posted by se...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e4c43f360a901d5e9bfbda64f8e5b001c0ff474e
Merge: 16191ce 1001938
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Thu Mar 25 11:46:30 2021 +0300

    Merge branch 'NLPCRAFT-278' into NLPCRAFT-283

 .../nlpcraft/model/NCTokenPredicateContext.java    |   3 +-
 .../nlpcraft/model/NCTokenPredicateResult.java     |  10 +-
 .../model/intent/compiler/NCIdlCompilerBase.scala  |   2 +-
 .../nlpcraft/model/intent/compiler/antlr4/NCIdl.g4 |  13 +-
 .../model/intent/compiler/antlr4/NCIdl.interp      |   3 +-
 .../intent/compiler/antlr4/NCIdlBaseListener.java  |  12 +
 .../intent/compiler/antlr4/NCIdlListener.java      |  10 +
 .../model/intent/compiler/antlr4/NCIdlParser.java  | 834 ++++++++++++---------
 8 files changed, 517 insertions(+), 370 deletions(-)

[incubator-nlpcraft] 01/03: 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-283
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git

commit 16191ce07d28127a798bceb4a8fe5cbeccc99a8e
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Thu Mar 25 11:46:12 2021 +0300

    WIP.
---
 .../model/dialog/NCIdlFunctionsCustom.scala        | 63 ++++++++++++++++++++++
 .../idl/compiler/functions/NCIdlFunctions.scala    | 46 ++++++++++++----
 2 files changed, 98 insertions(+), 11 deletions(-)

diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCIdlFunctionsCustom.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCIdlFunctionsCustom.scala
new file mode 100644
index 0000000..8f00078
--- /dev/null
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCIdlFunctionsCustom.scala
@@ -0,0 +1,63 @@
+/*
+ * 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.dialog
+
+import org.apache.nlpcraft.model.{NCTokenPredicateContext, NCTokenPredicateResult}
+import org.apache.nlpcraft.model.intent.idl.compiler.functions.NCIdlFunctions
+import org.junit.jupiter.api.Test
+
+class NCIdlFunctionsCustomImpl {
+    def trueOn123(ctx: NCTokenPredicateContext): NCTokenPredicateResult =
+        new NCTokenPredicateResult(ctx.getToken.getOriginalText == "123", 1)
+}
+
+/**
+  * Tests for 'custom' functions.
+  */
+class NCIdlFunctionsCustom extends NCIdlFunctions {
+    @Test
+    def testErrors(): Unit = {
+        expectError(
+            TestDesc(
+                truth = "org.apache.nlpcraft.model.dialog.NCIdlFunctionsCustomImpl#missed",
+                isCustom = true,
+                token = Some(tkn(txt = "123")),
+                expectedTokensUsed = Some(1)
+            ),
+        )
+    }
+
+
+    @Test
+    def test(): Unit =
+        test(
+            TestDesc(
+                truth = "org.apache.nlpcraft.model.dialog.NCIdlFunctionsCustomImpl#trueOn123",
+                isCustom = true,
+                token = Some(tkn(txt = "123")),
+                expectedTokensUsed = Some(1)
+            ),
+            TestDesc(
+                truth = "org.apache.nlpcraft.model.dialog.NCIdlFunctionsCustomImpl#trueOn123",
+                isCustom = true,
+                token = Some(tkn(txt = "456")),
+                expectedRes = false,
+                expectedTokensUsed = Some(1)
+            )
+        )
+}
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 4c8840d..aa88297 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
@@ -31,7 +31,7 @@ import scala.language.implicitConversions
 /**
   * Tests for IDL functions.
   */
-private[functions] trait NCIdlFunctions {
+trait NCIdlFunctions {
     private final val MODEL_ID = "test.mdl.id"
 
     final val MODEL: NCModel = new NCModel {
@@ -45,9 +45,19 @@ private[functions] trait NCIdlFunctions {
     @BeforeEach
     def before(): Unit = NCIdlCompilerGlobal.clearCache(MODEL_ID)
 
-    case class TestDesc(truth: String, token: Option[NCToken] = None, idlCtx: NCIdlContext = ctx()) {
-        val term: NCIdlTerm = {
-            val intents = NCIdlCompiler.compileIntents(s"intent=i term(t)={$truth}", MODEL, MODEL_ID)
+    case class TestDesc(
+        truth: String,
+        token: Option[NCToken] = None,
+        idlCtx: NCIdlContext = ctx(),
+        isCustom: Boolean = false,
+        expectedRes: Boolean = true,
+        expectedTokensUsed: Option[Int] = None
+    ) {
+        // It should be lazy for errors verification methods.
+        lazy val term: NCIdlTerm = {
+            val (s1, s2) = if (isCustom) ('/', '/') else ('{', '}')
+
+            val intents = NCIdlCompiler.compileIntents(s"intent=i term(t)=$s1$truth$s2", MODEL, MODEL_ID)
 
             require(intents.size == 1)
             require(intents.head.terms.size == 1)
@@ -148,34 +158,48 @@ private[functions] trait NCIdlFunctions {
 
     protected def test(funcs: TestDesc*): Unit =
         for (f ← funcs) {
-            val res =
+            val item =
                 try {
                     // Process declarations.
                     f.idlCtx.vars ++= f.term.decls
 
                     // Execute term's predicate.
-                    f.term.pred.apply(f.token.getOrElse(tkn()), f.idlCtx).value
+                    f.term.pred.apply(f.token.getOrElse(tkn()), f.idlCtx)
                 }
                 catch {
                     case e: NCE ⇒ throw new NCE(s"Execution error processing: $f", e)
                     case e: Exception ⇒ throw new Exception(s"Execution error processing: $f", e)
                 }
 
-            res match {
-                case b: java.lang.Boolean ⇒ require(b, s"Unexpected FALSE result for: $f")
+            item.value match {
+                case b: java.lang.Boolean ⇒ require(if (f.expectedRes) b else !b, s"Unexpected '$b' result for: $f")
                 case _ ⇒
                     require(
                         requirement = false,
                         s"Unexpected result type [" +
-                            s"resType=${if (res == null) "null" else res.getClass.getName}, " +
-                            s"resValue=$res, " +
+                            s"resType=${if (item.value == null) "null" else item.value.getClass.getName}, " +
+                            s"resValue=${item.value}, " +
                             s"function=$f" +
                             s"]"
                     )
             }
+
+            f.expectedTokensUsed match {
+                case Some(exp) ⇒
+                    require(
+                        exp == item.tokUse,
+                        s"Unexpected tokens used [" +
+                        s"expectedTokensUsed=$exp, " +
+                        s"resultTokensUsed=${item.tokUse}, " +
+                        s"function=$f" +
+                        s"]"
+                    )
+
+                case None ⇒ // No-op.
+            }
         }
 
-    protected def expectError(f: String): Unit =
+    protected def expectError(f: TestDesc): Unit =
         try {
             test(f)
 

[incubator-nlpcraft] 03/03: 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-283
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git

commit 62c91839ffbac2cdeec88293d307041703427a19
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Thu Mar 25 11:54:34 2021 +0300

    WIP.
---
 .../model/intent/idl/compiler/functions/NCIdlFunctions.scala   |  9 +++++++--
 .../idl/compiler/functions}/NCIdlFunctionsCustom.scala         | 10 ++++------
 2 files changed, 11 insertions(+), 8 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 aa88297..2674401 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
@@ -31,7 +31,7 @@ import scala.language.implicitConversions
 /**
   * Tests for IDL functions.
   */
-trait NCIdlFunctions {
+private[functions] trait NCIdlFunctions {
     private final val MODEL_ID = "test.mdl.id"
 
     final val MODEL: NCModel = new NCModel {
@@ -206,7 +206,12 @@ trait NCIdlFunctions {
             require(false)
         }
         catch {
-            case e: Exception ⇒ println(s"Expected error: ${e.getLocalizedMessage}")
+            case e: Exception ⇒
+                e.getCause match {
+                    case cause: NCE ⇒ println(s"Expected error: ${cause.getLocalizedMessage}")
+                    case _ ⇒ println(s"Expected error: ${e.getLocalizedMessage}")
+                }
+
         }
 
     protected implicit def convert(pred: String): TestDesc = TestDesc(truth = pred)
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCIdlFunctionsCustom.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCustom.scala
similarity index 81%
rename from nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCIdlFunctionsCustom.scala
rename to nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCustom.scala
index 8f00078..cc2e543 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCIdlFunctionsCustom.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCustom.scala
@@ -15,10 +15,9 @@
  * limitations under the License.
  */
 
-package org.apache.nlpcraft.model.dialog
+package org.apache.nlpcraft.model.intent.idl.compiler.functions
 
 import org.apache.nlpcraft.model.{NCTokenPredicateContext, NCTokenPredicateResult}
-import org.apache.nlpcraft.model.intent.idl.compiler.functions.NCIdlFunctions
 import org.junit.jupiter.api.Test
 
 class NCIdlFunctionsCustomImpl {
@@ -34,7 +33,7 @@ class NCIdlFunctionsCustom extends NCIdlFunctions {
     def testErrors(): Unit = {
         expectError(
             TestDesc(
-                truth = "org.apache.nlpcraft.model.dialog.NCIdlFunctionsCustomImpl#missed",
+                truth = "org.apache.nlpcraft.model.intent.idl.compiler.functions.NCIdlFunctionsCustomImpl#missed",
                 isCustom = true,
                 token = Some(tkn(txt = "123")),
                 expectedTokensUsed = Some(1)
@@ -42,18 +41,17 @@ class NCIdlFunctionsCustom extends NCIdlFunctions {
         )
     }
 
-
     @Test
     def test(): Unit =
         test(
             TestDesc(
-                truth = "org.apache.nlpcraft.model.dialog.NCIdlFunctionsCustomImpl#trueOn123",
+                truth = "org.apache.nlpcraft.model.intent.idl.compiler.functions.NCIdlFunctionsCustomImpl#trueOn123",
                 isCustom = true,
                 token = Some(tkn(txt = "123")),
                 expectedTokensUsed = Some(1)
             ),
             TestDesc(
-                truth = "org.apache.nlpcraft.model.dialog.NCIdlFunctionsCustomImpl#trueOn123",
+                truth = "org.apache.nlpcraft.model.intent.idl.compiler.functions.NCIdlFunctionsCustomImpl#trueOn123",
                 isCustom = true,
                 token = Some(tkn(txt = "456")),
                 expectedRes = false,