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 2020/03/19 14:53:19 UTC

[incubator-nlpcraft] branch NLPCRAFT-15 created (now 9078b74)

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

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


      at 9078b74  WIP.

This branch includes the following new commits:

     new d7d9c2d  WIP.
     new f927285  WIP.
     new 9078b74  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] 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-15
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git

commit d7d9c2d04fc48bd24f70a0c5ec449fc0d4fd3ecb
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Wed Mar 18 14:37:53 2020 +0300

    WIP.
---
 .../mgrs/nlp/enrichers/limit/NCLimitEnricher.scala | 24 +++++++++-------------
 .../mgrs/nlp/enrichers/NCEnricherBaseSpec.scala    |  2 +-
 .../mgrs/nlp/enrichers/NCEnrichersTestBeans.scala  | 19 +++++++++++++++--
 .../nlp/enrichers/limit/NCEnricherLimitSpec.scala  | 15 ++++++++++----
 4 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala b/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala
index a5e00e4..b8b61a2 100644
--- a/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala
+++ b/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala
@@ -201,20 +201,16 @@ object NCLimitEnricher extends NCProbeEnricher {
                 tryToMatch(numsMap, groupsMap, toks) match {
                     case Some(m) ⇒
                         for (refNote ← m.refNotes if !hasReference(TOK_ID, "note", refNote, m.matched)) {
-                            val note = NCNlpSentenceNote(
-                                m.matched.map(_.index),
-                                TOK_ID,
-                                Seq(
-                                    "limit" → m.limit,
-                                    "asc" →
-                                        (m.asc match {
-                                            case Some(a) ⇒ a
-                                            case None ⇒ null
-                                        }),
-                                    "indexes" → m.refIndexes,
-                                    "note" → refNote
-                                ).filter(_._2 != null): _*
-                            )
+                            val params = mutable.ArrayBuffer.empty[(String, Any)]
+
+                            params += "limit" → m.limit
+                            params += "indexes" → m.refIndexes
+                            params += "note" → refNote
+
+                            if (m.asc.isDefined)
+                                params += "asc" → m.asc.get
+
+                            val note = NCNlpSentenceNote(m.matched.map(_.index), TOK_ID, params: _*)
 
                             m.matched.foreach(_.add(note))
 
diff --git a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
index c59174f..8566a57 100644
--- a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
+++ b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
@@ -32,7 +32,7 @@ class NCEnricherBaseSpec {
 
     @BeforeEach
     private[enrichers] def setUp(): Unit = {
-        NCEmbeddedProbe.start(classOf[NCEnricherTestModel])
+        //NCEmbeddedProbe.start(classOf[NCEnricherTestModel])
 
         client = new NCTestClientBuilder().newBuilder.setResponseLog(false).build
 
diff --git a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnrichersTestBeans.scala b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnrichersTestBeans.scala
index f97bc40..211048d 100644
--- a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnrichersTestBeans.scala
+++ b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnrichersTestBeans.scala
@@ -239,7 +239,7 @@ case class NCTestLimitToken(
     limit: Double,
     indexes: Seq[Int],
     note: String,
-    asc: Option[Boolean] = None
+    asc: Option[Boolean]
 ) extends NCTestToken {
     require(text != null)
     require(indexes != null)
@@ -263,9 +263,24 @@ case class NCTestLimitToken(
     }
 }
 
+object NCTestLimitToken {
+    def apply(text: String, limit: Double, indexes: Seq[Int], note: String, asc: Boolean): NCTestLimitToken =
+        new NCTestLimitToken(text, limit, indexes, note, Some(asc))
+
+    def apply(text: String, limit: Double, indexes: Seq[Int], note: String): NCTestLimitToken =
+        new NCTestLimitToken(text, limit, indexes, note, None)
+
+    def apply(text: String, limit: Double, index: Int, note: String, asc: Boolean): NCTestLimitToken =
+        new NCTestLimitToken(text, limit, Seq(index), note, Some(asc))
+
+    def apply(text: String, limit: Double, index: Int, note: String): NCTestLimitToken =
+        new NCTestLimitToken(text, limit, Seq(index), note, None)
+}
+
 case class NCTestUserToken(text: String, id: String) extends NCTestToken {
     require(text != null)
     require(id != null)
+
     override def toString: String = s"$text(user)<id=$id>"}
 
 // Token and sentence beans and utilities.
@@ -332,7 +347,7 @@ object NCTestToken {
 
             case "nlpcraft:limit" ⇒
                 val indexes: java.util.List[Int] = t.meta("nlpcraft:limit:indexes")
-                val asc: Optional[Boolean] = t.metaOpt("nlpcraft:sort:asc")
+                val asc: Optional[Boolean] = t.metaOpt("nlpcraft:limit:asc")
 
                 NCTestLimitToken(
                     txt,
diff --git a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala
index 7795bbc..18db234 100644
--- a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala
+++ b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala
@@ -30,10 +30,17 @@ class NCEnricherLimitSpec extends NCEnricherBaseSpec {
       */
     @Test
     def test(): Unit = {
-        checkExists(
-            "top 5 A",
-            lim(text = "top 5", limit = 5, indexes = Seq(1), note = "A", asc = Some(true)),
-            usr(text = "A", id = "A")
+        runBatch(
+            _ ⇒ checkExists(
+                "top A",
+                lim(text = "top", limit = 10, index = 1, note = "A", asc = false),
+                usr(text = "A", id = "A")
+            ),
+            _ ⇒ checkExists(
+                "few A B",
+                lim(text = "few", limit = 3, index = 1, note = "AB", asc = false),
+                usr(text = "A B", id = "AB")
+            )
         )
     }
 }


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

commit 9078b746d3dda896c508175212e6155578aafcec
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Thu Mar 19 17:53:12 2020 +0300

    WIP.
---
 .../mgrs/nlp/enrichers/NCEnricherBaseSpec.scala    | 16 +++++++-
 .../mgrs/nlp/enrichers/NCEnricherTestModel.scala   | 18 +++++++--
 .../mgrs/nlp/enrichers/NCEnrichersTestBeans.scala  |  5 +++
 .../aggregation/NCEnricherAggregationSpec.scala    | 41 +++++++++++++++++++++
 .../relation/NCEnricherRelationSpec.scala          | 43 ++++++++++++++++++++++
 5 files changed, 118 insertions(+), 5 deletions(-)

diff --git a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
index 8566a57..a283327 100644
--- a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
+++ b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
@@ -17,9 +17,9 @@
 
 package org.apache.nlpcraft.probe.mgrs.nlp.enrichers
 
+import org.apache.nlpcraft.model.NCModel
 import org.apache.nlpcraft.model.tools.test.{NCTestClient, NCTestClientBuilder}
 import org.apache.nlpcraft.probe.embedded.NCEmbeddedProbe
-
 import org.junit.jupiter.api.Assertions.{assertTrue, fail}
 import org.junit.jupiter.api.{AfterEach, BeforeEach}
 import org.scalatest.Assertions
@@ -30,9 +30,21 @@ import org.scalatest.Assertions
 class NCEnricherBaseSpec {
     private var client: NCTestClient = _
 
+    // TODO:
+    def getModelClass[T <: NCModel]: Option[Class[NCModel]] = Some(classOf[NCEnricherTestModel].asInstanceOf[Class[NCModel]])
+
     @BeforeEach
     private[enrichers] def setUp(): Unit = {
-        //NCEmbeddedProbe.start(classOf[NCEnricherTestModel])
+        getModelClass match {
+            case Some(claxx) ⇒
+                println(s"Embedded probe is going to start with model: $claxx")
+
+                NCEmbeddedProbe.start(claxx)
+            case None ⇒
+                println("Embedded probe will not be started")
+
+                None
+        }
 
         client = new NCTestClientBuilder().newBuilder.setResponseLog(false).build
 
diff --git a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherTestModel.scala b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherTestModel.scala
index 8023bdc..701372d 100644
--- a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherTestModel.scala
+++ b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherTestModel.scala
@@ -20,11 +20,10 @@ package org.apache.nlpcraft.probe.mgrs.nlp.enrichers
 import java.util
 import java.util.Collections
 
-import org.apache.nlpcraft.model.{NCContext, NCElement, NCModelAdapter, NCResult}
+import org.apache.nlpcraft.model.{NCContext, NCElement, NCModelAdapter, NCResult, NCValue}
 
 import scala.collection.JavaConverters._
 import scala.language.implicitConversions
-
 import NCEnricherTestModel._
 
 /**
@@ -42,7 +41,8 @@ class NCEnricherTestModel extends NCModelAdapter(ID, "Model enrichers test", "1.
             mkElement("BC", "B C"),
             mkElement("ABC", "A B C"),
             mkElement("D1", "D"),
-            mkElement("D2", "D")
+            mkElement("D2", "D"),
+            mkValueElement("V", "V1", "V2")
         ).asJava
 
     private def mkElement(id: String, syns: String*): NCElement =
@@ -52,6 +52,18 @@ class NCEnricherTestModel extends NCModelAdapter(ID, "Model enrichers test", "1.
             override def getGroups: util.List[String] = Collections.singletonList(GROUP)
         }
 
+    private def mkValueElement(id: String, vals: String*): NCElement =
+        new NCElement {
+            override def getId: String = id
+            override def getSynonyms: util.List[String] = Collections.singletonList(id)
+            override def getGroups: util.List[String] = Collections.singletonList(GROUP)
+            override def getValues: util.List[NCValue] = vals.map(v ⇒ new NCValue {
+                override def getName: String = v
+                override def getSynonyms: util.List[String] = Collections.singletonList(v)
+            }).asJava
+        }
+
+
     override def onContext(ctx: NCContext): NCResult =
         NCResult.text(
             NCTestSentence.serialize(ctx.getVariants.asScala.map(v ⇒ NCTestSentence(v.asScala.map(NCTestToken(_)))))
diff --git a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnrichersTestBeans.scala b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnrichersTestBeans.scala
index 211048d..ef3fe41 100644
--- a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnrichersTestBeans.scala
+++ b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnrichersTestBeans.scala
@@ -234,6 +234,11 @@ case class NCTestAggregationToken(text: String, `type`: String, indexes: Seq[Int
             s", note=$note>"
 }
 
+object NCTestAggregationToken {
+    def apply(text: String, `type`: String, index: Int, note: String): NCTestAggregationToken =
+        new NCTestAggregationToken(text, `type`, Seq(index), note)
+}
+
 case class NCTestLimitToken(
     text: String,
     limit: Double,
diff --git a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/aggregation/NCEnricherAggregationSpec.scala b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/aggregation/NCEnricherAggregationSpec.scala
new file mode 100644
index 0000000..f96a567
--- /dev/null
+++ b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/aggregation/NCEnricherAggregationSpec.scala
@@ -0,0 +1,41 @@
+/*
+ * 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.probe.mgrs.nlp.enrichers.aggregation
+
+import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{NCEnricherBaseSpec, NCTestAggregationToken ⇒ agg, NCTestUserToken ⇒ usr}
+import org.junit.jupiter.api.Test
+
+/**
+  * Aggregation enricher test.
+  */
+class NCEnricherAggregationSpec extends NCEnricherBaseSpec {
+    /**
+      *
+      * @throws Exception
+      */
+    @Test
+    def test(): Unit = {
+        runBatch(
+            _ ⇒ checkExists(
+                "max A",
+                agg(text = "max", `type` = "max", index = 1, note = "A"),
+                usr(text = "A", id = "A")
+            )
+        )
+    }
+}
diff --git a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/relation/NCEnricherRelationSpec.scala b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/relation/NCEnricherRelationSpec.scala
new file mode 100644
index 0000000..8253217
--- /dev/null
+++ b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/relation/NCEnricherRelationSpec.scala
@@ -0,0 +1,43 @@
+/*
+ * 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.probe.mgrs.nlp.enrichers.relation
+
+import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{NCEnricherBaseSpec, NCTestRelationToken ⇒ rel, NCTestUserToken ⇒ usr, NCTestNlpToken ⇒ nlp}
+import org.junit.jupiter.api.Test
+
+/**
+  * Relation enricher test.
+  */
+class NCEnricherRelationSpec extends NCEnricherBaseSpec {
+    /**
+      *
+      * @throws Exception
+      */
+    @Test
+    def test(): Unit = {
+        runBatch(
+            _ ⇒ checkExists(
+                "compare V1 and V2",
+                rel(text = "compare", `type` = "compare", indexes = Seq(1, 3), note = "V"),
+                usr(text = "V1", id = "V"),
+                nlp(text = "and", isStop = true),
+                usr(text = "V2", id = "V")
+            )
+        )
+    }
+}


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

commit f927285fc6fa1d95fc5c28bd6a4056a0967cbb08
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Wed Mar 18 15:48:50 2020 +0300

    WIP.
---
 .../probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala         | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala
index 18db234..2ba3638 100644
--- a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala
+++ b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala
@@ -40,6 +40,11 @@ class NCEnricherLimitSpec extends NCEnricherBaseSpec {
                 "few A B",
                 lim(text = "few", limit = 3, index = 1, note = "AB", asc = false),
                 usr(text = "A B", id = "AB")
+            ),
+            _ ⇒ checkExists(
+                "top 10 D1",
+                lim(text = "top 10", limit = 10, index = 1, note = "D1", asc = false),
+                usr(text = "D1", id = "D1")
             )
         )
     }