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/29 11:31:48 UTC

[incubator-nlpcraft] 01/03: WIP.

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

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

commit 004a3dc373c8450c5fc55927cba5e9599ef03f62
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Wed Jul 28 16:16:49 2021 +0300

    WIP.
---
 .../nlpcraft/models/stm/indexes/NCSortSpec.scala   | 30 ++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/indexes/NCSortSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/indexes/NCSortSpec.scala
index a33f0cb..ed47ade 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/indexes/NCSortSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/models/stm/indexes/NCSortSpec.scala
@@ -26,6 +26,19 @@ import java.util.{List => JList}
 import scala.jdk.CollectionConverters.ListHasAsScala
 import scala.language.implicitConversions
 
+object NCSortSpecModelData {
+    private def nvl[T](list: JList[T]): Seq[T] = if (list == null) Seq.empty else list.asScala.toSeq
+
+    def apply(subjnotes: JList[String], subjindexes: JList[Int], bynotes: JList[String], byindexes: JList[Int]):
+        NCSortSpecModelData = new
+            NCSortSpecModelData(
+                subjnotes = nvl(subjnotes),
+                subjindexes = nvl(subjindexes),
+                bynotes = nvl(bynotes),
+                byindexes = nvl(byindexes)
+            )
+}
+
 case class NCSortSpecModelData(
     subjnotes: Seq[String] = Seq.empty,
     subjindexes: Seq[Int] = Seq.empty,
@@ -39,8 +52,10 @@ class NCSortSpecModel extends NCSpecModelAdapter {
         NCResult.json(
             mapper.writeValueAsString(
                 NCSortSpecModelData(
-                    bynotes = sort.meta[JList[String]]("nlpcraft:sort:bynotes").asScala.toSeq,
-                    byindexes = sort.meta[JList[Int]]("nlpcraft:sort:byindexes").asScala.toSeq
+                    subjnotes = sort.meta[JList[String]]("nlpcraft:sort:subjnotes"),
+                    subjindexes = sort.meta[JList[Int]]("nlpcraft:sort:subjindexes"),
+                    bynotes = sort.meta[JList[String]]("nlpcraft:sort:bynotes"),
+                    byindexes = sort.meta[JList[Int]]("nlpcraft:sort:byindexes")
                 )
             )
         )
@@ -62,5 +77,16 @@ class NCSortSpec extends NCTestContext {
             extract,
             NCSortSpecModelData(bynotes = Seq("B"), byindexes = Seq(1))
         )
+        checkResult(
+            "test test sort a a by a a",
+            extract,
+            NCSortSpecModelData(subjnotes = Seq("A"), subjindexes = Seq(3), bynotes = Seq("A"), byindexes = Seq(5))
+        )
+
+//        checkResult(
+//            "test test sort a a, a a by a a, a a",
+//            extract,
+//            NCSortSpecModelData(subjnotes = Seq("A"), subjindexes = Seq(2, 3), bynotes = Seq("A"), byindexes = Seq(5, 6))
+//        )
     }
 }
\ No newline at end of file