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/07/26 07:54:57 UTC

[incubator-nlpcraft] branch NLPCRAFT-369 updated: Intents IDL `options` tests added.

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

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


The following commit(s) were added to refs/heads/NLPCRAFT-369 by this push:
     new 68a3c3e  Intents IDL `options` tests added.
68a3c3e is described below

commit 68a3c3e337425bd238aab46a6ea5d93309206bad
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Mon Jul 26 10:54:45 2021 +0300

    Intents IDL `options` tests added.
---
 .../NCFreeWordsSpec.scala}                         | 37 +++++------
 .../NCOrderedSpec.scala}                           | 33 +++++-----
 .../NCStemOnlySpec.scala}                          | 77 ++++++++++++++++------
 .../NCSysTokensSpec.scala}                         | 37 +++++------
 .../NCUserTokensSpec.scala}                        | 37 +++++------
 5 files changed, 128 insertions(+), 93 deletions(-)

diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlIntentOptionsSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/options/NCFreeWordsSpec.scala
similarity index 70%
copy from nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlIntentOptionsSpec.scala
copy to nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/options/NCFreeWordsSpec.scala
index ad71333..0fd8c4c 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlIntentOptionsSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/options/NCFreeWordsSpec.scala
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.nlpcraft.model.intent.idl
+package org.apache.nlpcraft.model.intent.idl.options
 
 import org.apache.nlpcraft.model.`abstract`.NCAbstractTokensModel
 import org.apache.nlpcraft.model.meta.NCMetaSpecAdapter
@@ -25,26 +25,25 @@ import org.junit.jupiter.api.Test
 
 import java.util
 
-class NCIdlIntentOptionsModel extends NCAbstractTokensModel {
+class NCFreeWordsModel extends NCAbstractTokensModel {
     override def getElements: util.Set[NCElement] = Set(
-        NCTestElement("i1_a"),
-        NCTestElement("i1_b"),
-
-        NCTestElement("i2_a"),
-        NCTestElement("i2_b")
+        NCTestElement("a"),
+        NCTestElement("b"),
+        NCTestElement("c"),
+        NCTestElement("d")
     )
 
     @NCIntent(
         "intent=i1 " +
         "    options={" +
-        "        'ordered': true, " +
-        "        'unused_free_words': false, " +
+        "        'ordered': false, " +
+        "        'unused_free_words': true, " +
         "        'unused_sys_toks': false, " +
         "        'unused_usr_toks': false, " +
         "        'allow_stm_only': false" +
         "    }" +
-        "    term(a)={tok_id() == 'i1_a'}" +
-        "    term(b)={tok_id() == 'i1_b'}"
+        "    term(a)={tok_id() == 'a'}" +
+        "    term(b)={tok_id() == 'b'}"
     )
     def i1(): NCResult = NCResult.text("i1")
 
@@ -57,20 +56,20 @@ class NCIdlIntentOptionsModel extends NCAbstractTokensModel {
         "        'unused_usr_toks': false, " +
         "        'allow_stm_only': false" +
         "    }" +
-        "    term(a)={tok_id() == 'i2_a'}" +
-        "    term(b)={tok_id() == 'i2_b'}"
+        "    term(a)={tok_id() == 'c'}" +
+        "    term(b)={tok_id() == 'd'}"
     )
     def i2(): NCResult = NCResult.text("i2")
 }
 
-@NCTestEnvironment(model = classOf[NCIdlIntentOptionsModel], startClient = true)
-class NCIdlIntentOptionsSpec extends NCMetaSpecAdapter {
+@NCTestEnvironment(model = classOf[NCFreeWordsModel], startClient = true)
+class NCFreeWordsSpec extends NCMetaSpecAdapter {
     @Test
     def test(): Unit = {
-        checkResult("i1_a i1_b", "i1")
-        checkFail("i1_b i1_a")
+        checkResult("a b", "i1")
+        checkResult("a test b", "i1")
 
-        checkResult("i2_a i2_b", "i2")
-        checkResult("i2_b i2_a", "i2")
+        checkResult("c d", "i2")
+        checkFail("c test d")
     }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlIntentOptionsSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/options/NCOrderedSpec.scala
similarity index 73%
copy from nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlIntentOptionsSpec.scala
copy to nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/options/NCOrderedSpec.scala
index ad71333..0076a99 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlIntentOptionsSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/options/NCOrderedSpec.scala
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.nlpcraft.model.intent.idl
+package org.apache.nlpcraft.model.intent.idl.options
 
 import org.apache.nlpcraft.model.`abstract`.NCAbstractTokensModel
 import org.apache.nlpcraft.model.meta.NCMetaSpecAdapter
@@ -25,13 +25,12 @@ import org.junit.jupiter.api.Test
 
 import java.util
 
-class NCIdlIntentOptionsModel extends NCAbstractTokensModel {
+class NCOrderedModel extends NCAbstractTokensModel {
     override def getElements: util.Set[NCElement] = Set(
-        NCTestElement("i1_a"),
-        NCTestElement("i1_b"),
-
-        NCTestElement("i2_a"),
-        NCTestElement("i2_b")
+        NCTestElement("a"),
+        NCTestElement("b"),
+        NCTestElement("c"),
+        NCTestElement("d")
     )
 
     @NCIntent(
@@ -43,8 +42,8 @@ class NCIdlIntentOptionsModel extends NCAbstractTokensModel {
         "        'unused_usr_toks': false, " +
         "        'allow_stm_only': false" +
         "    }" +
-        "    term(a)={tok_id() == 'i1_a'}" +
-        "    term(b)={tok_id() == 'i1_b'}"
+        "    term(a)={tok_id() == 'a'}" +
+        "    term(b)={tok_id() == 'b'}"
     )
     def i1(): NCResult = NCResult.text("i1")
 
@@ -57,20 +56,20 @@ class NCIdlIntentOptionsModel extends NCAbstractTokensModel {
         "        'unused_usr_toks': false, " +
         "        'allow_stm_only': false" +
         "    }" +
-        "    term(a)={tok_id() == 'i2_a'}" +
-        "    term(b)={tok_id() == 'i2_b'}"
+        "    term(a)={tok_id() == 'c'}" +
+        "    term(b)={tok_id() == 'd'}"
     )
     def i2(): NCResult = NCResult.text("i2")
 }
 
-@NCTestEnvironment(model = classOf[NCIdlIntentOptionsModel], startClient = true)
-class NCIdlIntentOptionsSpec extends NCMetaSpecAdapter {
+@NCTestEnvironment(model = classOf[NCOrderedModel], startClient = true)
+class NCOrderedSpec extends NCMetaSpecAdapter {
     @Test
     def test(): Unit = {
-        checkResult("i1_a i1_b", "i1")
-        checkFail("i1_b i1_a")
+        checkResult("a b", "i1")
+        checkFail("b a")
 
-        checkResult("i2_a i2_b", "i2")
-        checkResult("i2_b i2_a", "i2")
+        checkResult("c d", "i2")
+        checkResult("d c", "i2")
     }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlIntentOptionsSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/options/NCStemOnlySpec.scala
similarity index 52%
copy from nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlIntentOptionsSpec.scala
copy to nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/options/NCStemOnlySpec.scala
index ad71333..604d4ca 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlIntentOptionsSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/options/NCStemOnlySpec.scala
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.nlpcraft.model.intent.idl
+package org.apache.nlpcraft.model.intent.idl.options
 
 import org.apache.nlpcraft.model.`abstract`.NCAbstractTokensModel
 import org.apache.nlpcraft.model.meta.NCMetaSpecAdapter
@@ -25,26 +25,41 @@ import org.junit.jupiter.api.Test
 
 import java.util
 
-class NCIdlIntentOptionsModel extends NCAbstractTokensModel {
+class NCStmOnlyModel extends NCAbstractTokensModel {
     override def getElements: util.Set[NCElement] = Set(
-        NCTestElement("i1_a"),
-        NCTestElement("i1_b"),
+        NCTestElement("a"),
+        NCTestElement("b"),
+        NCTestElement("c"),
+        NCTestElement("d")
+    )
 
-        NCTestElement("i2_a"),
-        NCTestElement("i2_b")
+    @NCIntent(
+        "intent=before " +
+            "    options={" +
+            "        'ordered': false, " +
+            "        'unused_free_words': false, " +
+            "        'unused_sys_toks': false, " +
+            "        'unused_usr_toks': false, " +
+            "        'allow_stm_only': false" +
+            "    }" +
+            "    term(a)={tok_id() == 'a'}" +
+            "    term(b)={tok_id() == 'b'} " +
+            "    term(c)={tok_id() == 'c'} " +
+            "    term(d)={tok_id() == 'd'}"
     )
+    def before(): NCResult = NCResult.text("before")
 
     @NCIntent(
         "intent=i1 " +
         "    options={" +
-        "        'ordered': true, " +
+        "        'ordered': false, " +
         "        'unused_free_words': false, " +
         "        'unused_sys_toks': false, " +
         "        'unused_usr_toks': false, " +
-        "        'allow_stm_only': false" +
+        "        'allow_stm_only': true" +
         "    }" +
-        "    term(a)={tok_id() == 'i1_a'}" +
-        "    term(b)={tok_id() == 'i1_b'}"
+        "    term(a)={tok_id() == 'a'}" +
+        "    term(b)={tok_id() == 'b'}"
     )
     def i1(): NCResult = NCResult.text("i1")
 
@@ -57,20 +72,44 @@ class NCIdlIntentOptionsModel extends NCAbstractTokensModel {
         "        'unused_usr_toks': false, " +
         "        'allow_stm_only': false" +
         "    }" +
-        "    term(a)={tok_id() == 'i2_a'}" +
-        "    term(b)={tok_id() == 'i2_b'}"
+        "    term(a)={tok_id() == 'c'}" +
+        "    term(b)={tok_id() == 'd'}"
     )
     def i2(): NCResult = NCResult.text("i2")
 }
 
-@NCTestEnvironment(model = classOf[NCIdlIntentOptionsModel], startClient = true)
-class NCIdlIntentOptionsSpec extends NCMetaSpecAdapter {
+@NCTestEnvironment(model = classOf[NCStmOnlyModel], startClient = true)
+class NCStmOnlySpec extends NCMetaSpecAdapter {
+    private def clear(): Unit = {
+        val client = getClient
+
+        client.clearConversation()
+        client.clearDialog()
+    }
+
     @Test
-    def test(): Unit = {
-        checkResult("i1_a i1_b", "i1")
-        checkFail("i1_b i1_a")
+    def test1(): Unit = {
+        clear()
+
+        checkResult("a b c d", "before")
+
+        checkResult("a b", "i1")
+
+        clear()
+
+        checkFail("a b", "i1")
+    }
+
+    @Test
+    def test2(): Unit = {
+        clear()
+
+        checkResult("a b c d", "before")
+
+        checkResult("c d", "i2")
+
+        clear()
 
-        checkResult("i2_a i2_b", "i2")
-        checkResult("i2_b i2_a", "i2")
+        checkResult("c d", "i2")
     }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlIntentOptionsSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/options/NCSysTokensSpec.scala
similarity index 70%
copy from nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlIntentOptionsSpec.scala
copy to nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/options/NCSysTokensSpec.scala
index ad71333..8c7e9ec 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlIntentOptionsSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/options/NCSysTokensSpec.scala
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.nlpcraft.model.intent.idl
+package org.apache.nlpcraft.model.intent.idl.options
 
 import org.apache.nlpcraft.model.`abstract`.NCAbstractTokensModel
 import org.apache.nlpcraft.model.meta.NCMetaSpecAdapter
@@ -25,26 +25,25 @@ import org.junit.jupiter.api.Test
 
 import java.util
 
-class NCIdlIntentOptionsModel extends NCAbstractTokensModel {
+class NCSysTokensModel extends NCAbstractTokensModel {
     override def getElements: util.Set[NCElement] = Set(
-        NCTestElement("i1_a"),
-        NCTestElement("i1_b"),
-
-        NCTestElement("i2_a"),
-        NCTestElement("i2_b")
+        NCTestElement("a"),
+        NCTestElement("b"),
+        NCTestElement("c"),
+        NCTestElement("d")
     )
 
     @NCIntent(
         "intent=i1 " +
         "    options={" +
-        "        'ordered': true, " +
+        "        'ordered': false, " +
         "        'unused_free_words': false, " +
-        "        'unused_sys_toks': false, " +
+        "        'unused_sys_toks': true, " +
         "        'unused_usr_toks': false, " +
         "        'allow_stm_only': false" +
         "    }" +
-        "    term(a)={tok_id() == 'i1_a'}" +
-        "    term(b)={tok_id() == 'i1_b'}"
+        "    term(a)={tok_id() == 'a'}" +
+        "    term(b)={tok_id() == 'b'}"
     )
     def i1(): NCResult = NCResult.text("i1")
 
@@ -57,20 +56,20 @@ class NCIdlIntentOptionsModel extends NCAbstractTokensModel {
         "        'unused_usr_toks': false, " +
         "        'allow_stm_only': false" +
         "    }" +
-        "    term(a)={tok_id() == 'i2_a'}" +
-        "    term(b)={tok_id() == 'i2_b'}"
+        "    term(a)={tok_id() == 'c'}" +
+        "    term(b)={tok_id() == 'd'}"
     )
     def i2(): NCResult = NCResult.text("i2")
 }
 
-@NCTestEnvironment(model = classOf[NCIdlIntentOptionsModel], startClient = true)
-class NCIdlIntentOptionsSpec extends NCMetaSpecAdapter {
+@NCTestEnvironment(model = classOf[NCSysTokensModel], startClient = true)
+class NCSysTokensSpec extends NCMetaSpecAdapter {
     @Test
     def test(): Unit = {
-        checkResult("i1_a i1_b", "i1")
-        checkFail("i1_b i1_a")
+        checkResult("a b", "i1")
+        checkResult("a today b", "i1")
 
-        checkResult("i2_a i2_b", "i2")
-        checkResult("i2_b i2_a", "i2")
+        checkResult("c d", "i2")
+        checkFail("c today d")
     }
 }
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlIntentOptionsSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/options/NCUserTokensSpec.scala
similarity index 70%
rename from nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlIntentOptionsSpec.scala
rename to nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/options/NCUserTokensSpec.scala
index ad71333..29b034e 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlIntentOptionsSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/options/NCUserTokensSpec.scala
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.nlpcraft.model.intent.idl
+package org.apache.nlpcraft.model.intent.idl.options
 
 import org.apache.nlpcraft.model.`abstract`.NCAbstractTokensModel
 import org.apache.nlpcraft.model.meta.NCMetaSpecAdapter
@@ -25,26 +25,25 @@ import org.junit.jupiter.api.Test
 
 import java.util
 
-class NCIdlIntentOptionsModel extends NCAbstractTokensModel {
+class NCUserTokensModel extends NCAbstractTokensModel {
     override def getElements: util.Set[NCElement] = Set(
-        NCTestElement("i1_a"),
-        NCTestElement("i1_b"),
-
-        NCTestElement("i2_a"),
-        NCTestElement("i2_b")
+        NCTestElement("a"),
+        NCTestElement("b"),
+        NCTestElement("c"),
+        NCTestElement("d")
     )
 
     @NCIntent(
         "intent=i1 " +
         "    options={" +
-        "        'ordered': true, " +
+        "        'ordered': false, " +
         "        'unused_free_words': false, " +
         "        'unused_sys_toks': false, " +
-        "        'unused_usr_toks': false, " +
+        "        'unused_usr_toks': true, " +
         "        'allow_stm_only': false" +
         "    }" +
-        "    term(a)={tok_id() == 'i1_a'}" +
-        "    term(b)={tok_id() == 'i1_b'}"
+        "    term(a)={tok_id() == 'a'}" +
+        "    term(b)={tok_id() == 'b'}"
     )
     def i1(): NCResult = NCResult.text("i1")
 
@@ -57,20 +56,20 @@ class NCIdlIntentOptionsModel extends NCAbstractTokensModel {
         "        'unused_usr_toks': false, " +
         "        'allow_stm_only': false" +
         "    }" +
-        "    term(a)={tok_id() == 'i2_a'}" +
-        "    term(b)={tok_id() == 'i2_b'}"
+        "    term(a)={tok_id() == 'c'}" +
+        "    term(b)={tok_id() == 'd'}"
     )
     def i2(): NCResult = NCResult.text("i2")
 }
 
-@NCTestEnvironment(model = classOf[NCIdlIntentOptionsModel], startClient = true)
-class NCIdlIntentOptionsSpec extends NCMetaSpecAdapter {
+@NCTestEnvironment(model = classOf[NCUserTokensModel], startClient = true)
+class NCUserTokensSpec extends NCMetaSpecAdapter {
     @Test
     def test(): Unit = {
-        checkResult("i1_a i1_b", "i1")
-        checkFail("i1_b i1_a")
+        checkResult("a b", "i1")
+        checkResult("a d b", "i1")
 
-        checkResult("i2_a i2_b", "i2")
-        checkResult("i2_b i2_a", "i2")
+        checkResult("c d", "i2")
+        checkFail("c a d")
     }
 }