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

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


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

commit a4efa58e01431144a2794a447cf5ea2cd223d21d
Author: Sergey Kamov <[email protected]>
AuthorDate: Fri Aug 27 14:30:25 2021 +0300

    WIP.
---
 .../probe/mgrs/sentence/NCSentenceManager.scala    |  3 +-
 .../model/NCEnricherNestedModelSpec6.scala         | 37 ++++++++++++++++------
 2 files changed, 29 insertions(+), 11 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/sentence/NCSentenceManager.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/sentence/NCSentenceManager.scala
index 17d4f6c..cd29f66 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/sentence/NCSentenceManager.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/sentence/NCSentenceManager.scala
@@ -736,7 +736,8 @@ object NCSentenceManager extends NCService {
         def notNlpNotes(s: NCNlpSentence): Seq[NCNlpSentenceNote] = 
s.flatten.filter(!_.isNlp)
 
         // Drops similar sentences (with same notes structure). Keeps with 
more found.
-        val notGreedyElems: Set[String] = mdl.getElements.asScala.flatMap(e => 
if (e.isGreedy.orElse(mdl.isGreedy)) Some(e.getId) else None).toSet
+        val notGreedyElems =
+            mdl.getElements.asScala.flatMap(e => if 
(!e.isGreedy.orElse(mdl.isGreedy)) Some(e.getId) else None).toSet
 
         sens = 
sens.groupBy(notNlpNotes(_).groupBy(_.noteType).keys.toSeq.sorted.distinct).
             flatMap { case (types, sensSeq) =>
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec6.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec6.scala
index 8670848..b93acdd 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec6.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec6.scala
@@ -30,13 +30,23 @@ class NCNestedTestModel6 extends 
NCModelAdapter("nlpcraft.nested5.test.mdl", "Te
 
     override def getElements: util.Set[NCElement] =
         Set(
-            NCTestElement("a"),
-            NCTestElement("b"),
-            { val e = NCTestElement("any", "{//[a-zA-Z0-9]+//}[1, 3]"); 
e.greedy = Optional.of(false); e },
-            NCTestElement("compose", "^^[aRef]{tok_id() == 'a'}^^ 
^^[anRef]{tok_id() == 'any'}^^ ^^[bRef]{tok_id() == 'b'}^^")
+            NCTestElement("a1"),
+            NCTestElement("b1"),
+            // We have to define any1 as 'not greedy'.
+            { val e = NCTestElement("any1", "{//[a-zA-Z0-9]+//}[1, 3]"); 
e.greedy = Optional.of(false); e },
+            NCTestElement("compose1", "^^[a1Ref]{tok_id() == 'a1'}^^ 
^^[any1Ref]{tok_id() == 'any1'}^^ ^^[b1Ref]{tok_id() == 'b1'}^^"),
+
+            NCTestElement("a2"),
+            NCTestElement("b2"),
+            // We don't have to do anything here with greedy flag.
+            NCTestElement("compose2", "^^[a2Ref]{tok_id() == 'a2'}^^ 
{//[a-zA-Z0-9]+//}[1, 3] ^^[b2Ref]{tok_id() == 'b2'}^^"),
+
         )
-    @NCIntent("intent=compose term(city)={tok_id() == 'compose'}")
-    private def onCompose(ctx: NCIntentMatch): NCResult = NCResult.text("OK")
+    @NCIntent("intent=compose1 term(city)={tok_id() == 'compose1'}")
+    private def onCompose1(ctx: NCIntentMatch): NCResult = NCResult.text("OK")
+
+    @NCIntent("intent=compose2 term(city)={tok_id() == 'compose2'}")
+    private def onCompose2(ctx: NCIntentMatch): NCResult = NCResult.text("OK")
 }
 /**
   *
@@ -44,9 +54,16 @@ class NCNestedTestModel6 extends 
NCModelAdapter("nlpcraft.nested5.test.mdl", "Te
 @NCTestEnvironment(model = classOf[NCNestedTestModel6], startClient = true)
 class NCEnricherNestedModelSpec6 extends NCTestContext {
     @Test
-    def test(): Unit = {
-        checkIntent("a t1 t2 t3 b", "compose")
-        checkIntent("a t1 t2 b", "compose")
-        checkIntent("a t1 b", "compose")
+    def testCompose1(): Unit = {
+        checkIntent("a1 t1 t2 t3 b1", "compose1")
+        checkIntent("a1 t1 t2 b1", "compose1")
+        checkIntent("a1 t1 b1", "compose1")
+    }
+
+    @Test
+    def testCompose2(): Unit = {
+        checkIntent("a2 t1 t2 t3 b2", "compose2")
+        checkIntent("a2 t1 t2 b2", "compose2")
+        checkIntent("a2 t1 b2", "compose2")
     }
 }

Reply via email to