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/04/14 07:01:40 UTC

[incubator-nlpcraft] 06/08: WIP.

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

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

commit ae02e4926227be05efb165f040ad6fe14b830f56
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Tue Apr 13 22:40:55 2021 +0300

    WIP.
---
 .../nlpcraft/probe/mgrs/NCProbeSynonym.scala       |  1 -
 .../mgrs/nlp/enrichers/model/NCModelEnricher.scala | 35 ++++++++++++----------
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeSynonym.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeSynonym.scala
index 7a7d794..0a4bda6 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeSynonym.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeSynonym.scala
@@ -202,7 +202,6 @@ class NCProbeSynonym(
       */
     def isMatch(tows: Seq[NCDslContent], req: NCRequest): Boolean = {
         require(tows != null)
-        require(!sparse)
 
         if (tows.length == length && tows.count(_.isLeft) >= dslChunks)
             tows.zip(this).sortBy(p ⇒ getSort(p._2.kind)).forall { case (tow, chunk) ⇒ isMatch(tow, chunk, req) }
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCModelEnricher.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCModelEnricher.scala
index d1ec4e5..8d5c9f2 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCModelEnricher.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCModelEnricher.scala
@@ -186,6 +186,7 @@ object NCModelEnricher extends NCProbeEnricher with DecorateAsScala {
 
         // Internal usage.
         params += "allToksIndexes" → allToksIdxs.asJava
+        params += "toksIndexes" → toks.map(_.index).asJava
         params += "continuous" → continuous
 
         syn match {
@@ -345,20 +346,22 @@ object NCModelEnricher extends NCProbeEnricher with DecorateAsScala {
       * @param toks
       * @param elemId
       */
-    private def alreadyMarked(toks: Seq[NlpToken], allToksIndexes: Seq[Int], continuous: Boolean, elemId: String): Boolean =
-         toks.flatten.exists(n ⇒
-             n.noteType == elemId &&
-             {
-                 if (n.data("continuous").asInstanceOf[Boolean])
-                     false
-                 else {
-                     if (continuous)
-                         false
-                     else
-                         n.data("allToksIndexes").asInstanceOf[JList[Int]].asScala.containsSlice(allToksIndexes)
-                 }
-             }
-         )
+    private def alreadyMarked(toks: Seq[NlpToken], allToksIndexes: Seq[Int], continuous: Boolean, elemId: String): Boolean = {
+        toks.forall(t ⇒ t.isTypeOf(elemId)) &&
+        toks.head.filter(_.noteType == elemId).exists(n ⇒ n.tokenIndexes.toSet == toks.map(_.index).toSet)
+        toks.flatten.exists(n ⇒
+            n.noteType == elemId && {
+                if (n.data("continuous").asInstanceOf[Boolean])
+                    false
+                else {
+                    if (continuous)
+                        false
+                    else
+                        n.data("allToksIndexes").asInstanceOf[JList[Int]].asScala.containsSlice(allToksIndexes)
+                }
+            }
+        )
+    }
 
     /**
       *
@@ -591,11 +594,11 @@ object NCModelEnricher extends NCProbeEnricher with DecorateAsScala {
                             }
 
                     // 2. DSL.
-                    if (state != SIMPLE && mdl.dslSynonyms.nonEmpty) {
+                    if (state != SIMPLE && mdl.hasDslSynonyms) {
                         found = false
 
                         // 2.1 Sparse.
-                        if (mdl.hasSparseSynonyms)
+                        if (mdl.hasDslSynonyms)
                             for (s ← get(mdl.dslSynonyms, elemId); comb ← dslCombs if !found)
                                 s.trySparseMatch(comb.map(_.data), req) match {
                                     case Some(res) ⇒