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

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


The following commit(s) were added to refs/heads/NLPCRAFT-385 by this push:
     new aa7556f  WIP on NLPCRAFT-385.
aa7556f is described below

commit aa7556f916e7a756f4ddcb9397844ad4fa75505b
Author: Aaron Radzinzski <[email protected]>
AuthorDate: Sun Aug 1 18:24:17 2021 -0700

    WIP on NLPCRAFT-385.
---
 .../idl/compiler/functions/NCIdlFunctions.scala    |  8 +++++---
 .../compiler/functions/NCIdlFunctionsCustom.scala  | 20 ++++++++++++------
 .../compiler/functions/NCIdlFunctionsToken.scala   | 24 +++++++++++++++++++---
 .../functions/NCIdlFunctionsTokensUsed.scala       | 18 +++++++++++-----
 .../{models => model}/stm/NCStmTestModel.scala     |  2 +-
 .../{models => model}/stm/NCStmTestModelSpec.scala |  2 +-
 .../stm/indexes/NCLimitSpec.scala                  |  4 ++--
 .../stm/indexes/NCRelationSpec.scala               |  4 ++--
 .../{models => model}/stm/indexes/NCSortSpec.scala |  4 ++--
 .../stm/indexes/NCSpecModelAdapter.scala           |  2 +-
 10 files changed, 62 insertions(+), 26 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 78a6899..f232a7c 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
@@ -80,11 +80,14 @@ private[functions] trait NCIdlFunctions {
     }
 
     object TestDesc {
+        def apply(truth: String): TestDesc =
+            new TestDesc(truth = truth, idlCtx = mkIdlContext())
+
         def apply(truth: String, token: NCToken, idlCtx: NCIdlContext): 
TestDesc =
-            TestDesc(truth = truth, token = Some(token), idlCtx = idlCtx)
+            new TestDesc(truth = truth, token = Some(token), idlCtx = idlCtx)
 
         def apply(truth: String, token: NCToken): TestDesc =
-            TestDesc(truth = truth, token = Some(token), idlCtx = 
mkIdlContext(toks = Seq(token)))
+            new TestDesc(truth = truth, token = Some(token), idlCtx = 
mkIdlContext(toks = Seq(token)))
     }
 
     private def t2s(t: NCToken): String = {
@@ -144,7 +147,6 @@ private[functions] trait NCIdlFunctions {
         map.putAll(meta.asJava)
 
         map.put("nlpcraft:nlp:origtext", txt)
-        map.put("nlpcraft:nlp:origtext", txt)
 
         new NCToken {
             override def getModel: NCModelView = MODEL
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCustom.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCustom.scala
index a8946d2..99892b3 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCustom.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCustom.scala
@@ -45,7 +45,7 @@ class NCIdlFunctionsCustom extends NCIdlFunctions {
     def testErrors(): Unit = {
         def test(truth: String*): Unit =
             for (t <- truth)
-                expectError(TestDesc(truth = t, isCustom = true))
+                expectError(TestDesc(truth = t, idlCtx = mkIdlContext(), 
isCustom = true))
 
         test(
             "invalid",
@@ -61,26 +61,34 @@ class NCIdlFunctionsCustom extends NCIdlFunctions {
     }
 
     @Test
-    def test(): Unit =
+    def test(): Unit = {
+        val tok123 = mkToken(txt = "123")
+        val tok456 = mkToken(txt = "456")
+        val tokAny = mkToken(txt = "any")
+
         test(
             TestDesc(
                 truth = s"$C#trueOn123",
                 isCustom = true,
-                token = Some(mkToken(txt = "123")),
+                token = Some(tok123),
+                idlCtx = mkIdlContext(toks = Seq(tok123)),
                 tokensUsed = Some(1)
             ),
             TestDesc(
                 truth = s"$C#trueOn123",
                 isCustom = true,
-                token = Some(mkToken(txt = "456")),
+                token = Some(tok456),
+                idlCtx = mkIdlContext(toks = Seq(tok456)),
                 expectedRes = false,
                 tokensUsed = Some(1)
             ),
             TestDesc(
-                // Method defined in model.
+                // Method defined in the model.
                 truth = s"#trueAlwaysCustomToken",
                 isCustom = true,
-                token = Some(mkToken(txt = "any"))
+                token = Some(tokAny),
+                idlCtx = mkIdlContext(toks = Seq(tokAny)),
             )
         )
+    }
 }
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 b0d5824..347f63a 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
@@ -106,8 +106,26 @@ class NCIdlFunctionsToken extends NCIdlFunctions {
                 truth = "tok_end_idx() == 123",
                 token = mkToken(end = 123)
             ),
-            TestDesc(truth = "tok_this() == tok_this()"),
-            TestDesc(truth = "tok_is_first() == true"),
-            TestDesc(truth = "tok_is_last() == true")
+            TestDesc(truth = "tok_this() == tok_this()", idlCtx = 
mkIdlContext())
         )
+
+    @Test
+    def testTokenOrder(): Unit = {
+        val tok = mkToken(id = "a")
+
+        tok.getMetadata.put("nlpcraft:nlp:index", 0)
+
+        test(
+            TestDesc(
+                truth = "tok_is_first() == true",
+                token = tok,
+                idlCtx = mkIdlContext(toks = Seq(tok))
+            ),
+            TestDesc(
+                truth = "tok_is_last() == true",
+                token = tok,
+                idlCtx = mkIdlContext(toks = Seq(tok))
+            )
+        )
+    }
 }
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsTokensUsed.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsTokensUsed.scala
index ea0c1cb..624c34b 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsTokensUsed.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsTokensUsed.scala
@@ -24,31 +24,39 @@ import org.junit.jupiter.api.Test
   */
 class NCIdlFunctionsTokensUsed extends NCIdlFunctions {
     @Test
-    def test(): Unit =
+    def test(): Unit = {
+        val tokIdA = mkToken(id = "a")
+        val tokAb = mkToken(id = "a", parentId = "b")
         test(
             TestDesc(
                 truth = "1 == 1",
+                idlCtx = mkIdlContext(),
                 tokensUsed = Some(0)
             ),
             TestDesc(
                 truth = "tok_id() == 'a'",
-                token = Some(mkToken(id = "a")),
+                token = Some(tokIdA),
+                idlCtx = mkIdlContext(Seq(tokIdA)),
                 tokensUsed = Some(1)
             ),
             TestDesc(
                 truth = "tok_id() == 'a' && tok_id() == 'a'",
-                token = Some(mkToken(id = "a")),
+                token = Some(tokIdA),
+                idlCtx = mkIdlContext(Seq(tokIdA)),
                 tokensUsed = Some(2)
             ),
             TestDesc(
                 truth = "tok_id() == 'a' && tok_parent() == 'b'",
-                token = Some(mkToken(id = "a", parentId = "b")),
+                token = Some(tokAb),
+                idlCtx = mkIdlContext(Seq(tokAb)),
                 tokensUsed = Some(2)
             ),
             TestDesc(
                 truth = "tok_id() == 'a' && tok_id() == 'a' && tok_parent() == 
'b'",
-                token = Some(mkToken(id = "a", parentId = "b")),
+                token = Some(tokAb),
+                idlCtx = mkIdlContext(Seq(tokAb)),
                 tokensUsed = Some(3)
             )
         )
+    }
 }
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/NCStmTestModel.scala 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/NCStmTestModel.scala
similarity index 98%
rename from 
nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/NCStmTestModel.scala
rename to 
nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/NCStmTestModel.scala
index d51ec12..7201388 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/NCStmTestModel.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/NCStmTestModel.scala
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.nlpcraft.models.stm
+package org.apache.nlpcraft.model.stm
 
 import org.apache.nlpcraft.model.{NCIntentMatch, _}
 
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/NCStmTestModelSpec.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/NCStmTestModelSpec.scala
similarity index 97%
rename from 
nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/NCStmTestModelSpec.scala
rename to 
nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/NCStmTestModelSpec.scala
index bdff1cf..de74383 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/NCStmTestModelSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/NCStmTestModelSpec.scala
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.nlpcraft.models.stm
+package org.apache.nlpcraft.model.stm
 
 import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
 import org.junit.jupiter.api.Test
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/indexes/NCLimitSpec.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/indexes/NCLimitSpec.scala
similarity index 97%
rename from 
nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/indexes/NCLimitSpec.scala
rename to 
nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/indexes/NCLimitSpec.scala
index 9e1cb8f..a10594a 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/indexes/NCLimitSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/indexes/NCLimitSpec.scala
@@ -15,10 +15,10 @@
  * limitations under the License.
  */
 
-package org.apache.nlpcraft.models.stm.indexes
+package org.apache.nlpcraft.model.stm.indexes
 
 import org.apache.nlpcraft.model.{NCIntent, NCIntentMatch, NCResult, _}
-import org.apache.nlpcraft.models.stm.indexes.NCSpecModelAdapter.mapper
+import NCSpecModelAdapter.mapper
 import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
 import org.junit.jupiter.api.Test
 
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/indexes/NCRelationSpec.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/indexes/NCRelationSpec.scala
similarity index 97%
rename from 
nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/indexes/NCRelationSpec.scala
rename to 
nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/indexes/NCRelationSpec.scala
index 4198c77..d4f5c37 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/indexes/NCRelationSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/indexes/NCRelationSpec.scala
@@ -15,10 +15,10 @@
  * limitations under the License.
  */
 
-package org.apache.nlpcraft.models.stm.indexes
+package org.apache.nlpcraft.model.stm.indexes
 
 import org.apache.nlpcraft.model.{NCIntent, NCIntentMatch, NCResult, _}
-import org.apache.nlpcraft.models.stm.indexes.NCSpecModelAdapter.mapper
+import NCSpecModelAdapter.mapper
 import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
 import org.junit.jupiter.api.Test
 
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/indexes/NCSortSpec.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/indexes/NCSortSpec.scala
similarity index 98%
rename from 
nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/indexes/NCSortSpec.scala
rename to 
nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/indexes/NCSortSpec.scala
index 4658df6..6b19bba 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/indexes/NCSortSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/indexes/NCSortSpec.scala
@@ -15,10 +15,10 @@
  * limitations under the License.
  */
 
-package org.apache.nlpcraft.models.stm.indexes
+package org.apache.nlpcraft.model.stm.indexes
 
 import org.apache.nlpcraft.model.{NCIntent, NCIntentMatch, NCResult, _}
-import org.apache.nlpcraft.models.stm.indexes.NCSpecModelAdapter.mapper
+import NCSpecModelAdapter.mapper
 import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
 import org.junit.jupiter.api.Test
 
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/indexes/NCSpecModelAdapter.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/indexes/NCSpecModelAdapter.scala
similarity index 97%
rename from 
nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/indexes/NCSpecModelAdapter.scala
rename to 
nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/indexes/NCSpecModelAdapter.scala
index 81e5563..c0a8ac4 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/indexes/NCSpecModelAdapter.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/stm/indexes/NCSpecModelAdapter.scala
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.nlpcraft.models.stm.indexes
+package org.apache.nlpcraft.model.stm.indexes
 
 import com.fasterxml.jackson.databind.ObjectMapper
 import com.fasterxml.jackson.module.scala.DefaultScalaModule

Reply via email to