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 101e2153bfe4ba02de4f42facc1471894271e4e4
Author: Sergey Kamov <[email protected]>
AuthorDate: Wed Apr 14 12:08:58 2021 +0300

    WIP.
---
 .../apache/nlpcraft/probe/mgrs/NCProbeModel.scala  |  9 +-
 .../nlpcraft/probe/mgrs/NCProbeSynonym.scala       | 95 +++++++++++-----------
 .../probe/mgrs/deploy/NCDeployManager.scala        | 34 ++++----
 .../nlpcraft/probe/mgrs/model/NCModelManager.scala | 39 +++++----
 .../mgrs/nlp/enrichers/model/NCModelEnricher.scala | 49 +++++------
 .../org/apache/nlpcraft/model/NCIdlSpec.scala      |  2 +-
 .../org/apache/nlpcraft/model/NCIdlSpec2.scala     |  2 +-
 .../nlpcraft/model/intent/idl/NCIdlTestSpec.scala  |  2 +-
 .../intent/idl/compiler/NCIdlCompilerSpec.scala    |  8 +-
 .../nlpcraft/model/intent/idl/idl_test_model.yaml  |  2 +-
 10 files changed, 118 insertions(+), 124 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeModel.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeModel.scala
index 1c21cb9..a4e55a6 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeModel.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeModel.scala
@@ -30,7 +30,7 @@ import scala.collection.{Map, Seq}
   * @param intents
   * @param continuousSynonyms
   * @param sparseSynonyms
-  * @param dslSynonyms
+  * @param idlSynonyms
   * @param exclStopWordsStems
   * @param suspWordsStems
   * @param elements
@@ -41,14 +41,13 @@ case class NCProbeModel(
     intents: Seq[NCIdlIntent],
     continuousSynonyms: Map[String /*Element ID*/ , Map[Int /*Synonym length*/ 
, NCProbeSynonymsWrapper]], // Fast access map.
     sparseSynonyms: Map[String /*Element ID*/, Seq[NCProbeSynonym]],
-    dslSynonyms: Map[String /*Element ID*/ , Seq[NCProbeSynonym]], // Fast 
access map.
+    idlSynonyms: Map[String /*Element ID*/ , Seq[NCProbeSynonym]], // Fast 
access map.
     addStopWordsStems: Set[String],
     exclStopWordsStems: Set[String],
     suspWordsStems: Set[String],
     elements: Map[String /*Element ID*/ , NCElement],
     samples: Set[(String, Seq[Seq[String]])]
 ) {
-    def hasDslSynonyms(elemId: String): Boolean = dslSynonyms.contains(elemId)
-    def hasDslSynonyms: Boolean = dslSynonyms.nonEmpty
-    def hasSparseSynonyms: Boolean = sparseSynonyms.nonEmpty
+    def hasIdlSynonyms(elemId: String): Boolean = idlSynonyms.contains(elemId)
+    def hasIdlSynonyms: Boolean = idlSynonyms.nonEmpty
 }
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 dc9a1f5..207bc02 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
@@ -17,10 +17,11 @@
 
 package org.apache.nlpcraft.probe.mgrs
 
+import org.apache.nlpcraft.common.U
 import org.apache.nlpcraft.common.nlp.{NCNlpSentenceToken, 
NCNlpSentenceTokenBuffer}
 import org.apache.nlpcraft.model._
 import org.apache.nlpcraft.model.intent.NCIdlContext
-import org.apache.nlpcraft.probe.mgrs.NCProbeSynonym.NCDslContent
+import org.apache.nlpcraft.probe.mgrs.NCProbeSynonym.NCIdlContent
 import org.apache.nlpcraft.probe.mgrs.NCProbeSynonymChunkKind._
 
 import scala.collection.mutable
@@ -49,7 +50,8 @@ class NCProbeSynonym(
 
     lazy val isTextOnly: Boolean = forall(_.kind == TEXT)
     lazy val regexChunks: Int = count(_.kind == REGEX)
-    lazy val dslChunks: Int = count(_.kind == IDL)
+    lazy val idlChunks: Int = count(_.kind == IDL)
+    lazy val hasIdl: Boolean = idlChunks != 0
     lazy val isValueSynonym: Boolean = value != null
     lazy val stems: String = map(_.wordStem).mkString(" ")
     lazy val stemsHash: Int = stems.hashCode
@@ -86,11 +88,18 @@ class NCProbeSynonym(
     /**
       *
       * @param toks
+      * @param isMatch
+      * @param getIndex
+      * @param shouldBeNeighbors
+      * @tparam T
+      * @return
       */
-    private def trySparseMatch0[T](toks: Seq[T], isMatch: (T, 
NCProbeSynonymChunk) ⇒ Boolean, getIndex: T ⇒ Int): Option[Seq[T]] = {
-        require(toks != null)
-        require(toks.nonEmpty)
-
+    private def sparseMatch0[T](
+        toks: Seq[T],
+        isMatch: (T, NCProbeSynonymChunk) ⇒ Boolean,
+        getIndex: T ⇒ Int,
+        shouldBeNeighbors: Boolean
+    ): Option[Seq[T]] =
         if (toks.size >= this.size) {
             lazy val res = mutable.ArrayBuffer.empty[T]
             lazy val all = mutable.HashSet.empty[T]
@@ -125,14 +134,21 @@ class NCProbeSynonym(
                     state = -1
             }
 
-            if (state != -1 && all.size == res.size)
+            if (
+                state != -1 &&
+                all.size == res.size
+                    &&
+                (
+                    !shouldBeNeighbors ||
+                    U.isIncreased(res.map(getIndex).sorted)
+                )
+            )
                 Some(res)
             else
                 None
         }
         else
             None
-    }
 
     /**
       *
@@ -140,7 +156,7 @@ class NCProbeSynonym(
       * @param chunk
       * @param req
       */
-    private def isMatch(tow: NCDslContent, chunk: NCProbeSynonymChunk, req: 
NCRequest): Boolean = {
+    private def isMatch(tow: NCIdlContent, chunk: NCProbeSynonymChunk, req: 
NCRequest): Boolean = {
         def get0[T](fromToken: NCToken ⇒ T, fromWord: NCNlpSentenceToken ⇒ T): 
T =
             if (tow.isLeft) fromToken(tow.left.get) else 
fromWord(tow.right.get)
 
@@ -164,7 +180,7 @@ class NCProbeSynonym(
       */
     def isMatch(toks: NCNlpSentenceTokenBuffer): Boolean = {
         require(toks != null)
-        require(!sparse)
+        require(!sparse && !hasIdl)
 
         if (toks.length == length) {
             if (isTextOnly)
@@ -180,29 +196,11 @@ class NCProbeSynonym(
       *
       * @param toks
       */
-    def trySparseMatch(toks: NCNlpSentenceTokenBuffer): 
Option[Seq[NCNlpSentenceToken]] = {
+    def sparseMatch(toks: NCNlpSentenceTokenBuffer): 
Option[Seq[NCNlpSentenceToken]] = {
         require(toks != null)
-        require(sparse, s"Unexpected call on: $this")
-
-        trySparseMatch0(
-            toks,
-            isMatch,
-            (t: NCNlpSentenceToken) ⇒ t.startCharIndex
-        )
-    }
-
-    /**
-      *
-      * @param tows
-      * @param req
-      */
-    def isMatch(tows: Seq[NCDslContent], req: NCRequest): Boolean = {
-        require(tows != null)
+        require(sparse && !hasIdl)
 
-        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) }
-        else
-            false
+        sparseMatch0(toks, isMatch, (t: NCNlpSentenceToken) ⇒ 
t.startCharIndex, shouldBeNeighbors = false)
     }
 
     /**
@@ -210,15 +208,16 @@ class NCProbeSynonym(
       * @param tows
       * @param req
       */
-    def trySparseMatch(tows: Seq[NCDslContent], req: NCRequest): 
Option[Seq[NCDslContent]] = {
+    def idlMatch(tows: Seq[NCIdlContent], req: NCRequest): 
Option[Seq[NCIdlContent]] = {
         require(tows != null)
         require(req != null)
-        require(sparse, s"Unexpected call on: $this")
+        require(hasIdl)
 
-        trySparseMatch0(
+        sparseMatch0(
             tows,
-            (t: NCDslContent, chunk: NCProbeSynonymChunk) ⇒ isMatch(t, chunk, 
req),
-            (t: NCDslContent) ⇒ if (t.isLeft) t.left.get.getStartCharIndex 
else t.right.get.startCharIndex
+            (t: NCIdlContent, chunk: NCProbeSynonymChunk) ⇒ isMatch(t, chunk, 
req),
+            (t: NCIdlContent) ⇒ if (t.isLeft) t.left.get.getStartCharIndex 
else t.right.get.startCharIndex,
+            shouldBeNeighbors = !sparse
         )
     }
 
@@ -226,7 +225,7 @@ class NCProbeSynonym(
 
     // Orders synonyms from least to most significant.
     override def compare(that: NCProbeSynonym): Int = {
-        require(sparse == that.sparse, s"Invalid comparing [this=$this, 
that=$that]")
+        require(hasIdl || sparse == that.sparse, s"Invalid comparing 
[this=$this, that=$that]")
 
         def compareIsValueSynonym(): Int =
             isValueSynonym match {
@@ -235,7 +234,7 @@ class NCProbeSynonym(
 
                 case _ ⇒ 0
             }
-        
+
         if (that == null)
             1
         else
@@ -264,9 +263,9 @@ class NCProbeSynonym(
                                 case false if that.isTextOnly ⇒ -1
                                 case true if that.isTextOnly ⇒ 
compareIsValueSynonym()
                                 case _ ⇒
-                                    val thisDynCnt = regexChunks + dslChunks
-                                    val thatDynCnt = that.regexChunks + 
that.dslChunks
-                                    
+                                    val thisDynCnt = regexChunks + idlChunks
+                                    val thatDynCnt = that.regexChunks + 
that.idlChunks
+
                                     // Less PoS/regex/IDL chunks means less 
uncertainty, i.e. larger weight.
                                     if (thisDynCnt < thatDynCnt)
                                         1
@@ -278,41 +277,41 @@ class NCProbeSynonym(
                     }
             }
     }
-    
+
     override def canEqual(other: Any): Boolean = 
other.isInstanceOf[NCProbeSynonym]
-    
+
     override def equals(other: Any): Boolean = other match {
         case that: NCProbeSynonym ⇒
             super.equals(that) &&
                 (that canEqual this) &&
                 isTextOnly == that.isTextOnly &&
                 regexChunks == that.regexChunks &&
-                dslChunks == that.dslChunks &&
+                idlChunks == that.idlChunks &&
                 isValueSynonym == that.isValueSynonym &&
                 isElementId == that.isElementId &&
                 isValueName == that.isValueName &&
                 value == that.value
         case _ ⇒ false
     }
-    
+
     override def hashCode(): Int = {
         val state = Seq(
             super.hashCode(),
             isTextOnly,
             regexChunks,
-            dslChunks,
+            idlChunks,
             isValueSynonym,
             isElementId,
             isValueName,
             value
         )
-        
+
         state.map(p ⇒ if (p == null) 0 else p.hashCode()).foldLeft(0)((a, b) ⇒ 
31 * a + b)
     }
 }
 
 object NCProbeSynonym {
-    type NCDslContent = Either[NCToken, NCNlpSentenceToken]
+    type NCIdlContent = Either[NCToken, NCNlpSentenceToken]
 
     /**
       *
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
index aeda6c7..b7db8dc 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
@@ -195,10 +195,8 @@ object NCDeployManager extends NCService with 
DecorateAsScala {
         val syns = mutable.HashSet.empty[SynonymHolder]
 
         def ok(b: Boolean, exp: Boolean): Boolean = if (exp) b else !b
-        def filterDsl(syns: Set[SynonymHolder], dsl: Boolean): 
Set[SynonymHolder] =
-            syns.filter(s ⇒ ok(s.syn.exists(_.kind == IDL), dsl))
-        def filterSparse(syns: Set[SynonymHolder], sparse: Boolean): 
Set[SynonymHolder] =
-            syns.filter(s ⇒ ok(s.syn.sparse, sparse))
+        def idl(syns: Set[SynonymHolder], idl: Boolean): Set[SynonymHolder] = 
syns.filter(s ⇒ ok(s.syn.hasIdl, idl))
+        def sparse(syns: Set[SynonymHolder], sp: Boolean): Set[SynonymHolder] 
= syns.filter(s ⇒ ok(s.syn.sparse, sp))
 
         var cnt = 0
         val maxCnt = mdl.getMaxTotalSynonyms
@@ -219,8 +217,8 @@ object NCDeployManager extends NCService with 
DecorateAsScala {
                     s"]"
                 )
 
-            val sparseFlag = elm.isSparse.orElse(mdl.isSparse)
-            val permuteFlag = 
elm.isPermutateSynonyms.orElse(mdl.isPermutateSynonyms)
+            val sparseElem = elm.isSparse.orElse(mdl.isSparse)
+            val permuteElem = 
elm.isPermutateSynonyms.orElse(mdl.isPermutateSynonyms)
 
             def addSynonym(
                 isElementId: Boolean,
@@ -264,19 +262,19 @@ object NCDeployManager extends NCService with 
DecorateAsScala {
                         )
                 }
 
-                def hasDsl(chunks: Seq[NCProbeSynonymChunk]) = 
chunks.exists(_.kind == IDL)
+                val sp = sparseElem && chunks.size > 1
 
                 if (
-                    permuteFlag &&
-                    !sparseFlag &&
+                    permuteElem &&
+                    !sparseElem &&
                     !isElementId &&
                     chunks.forall(_.wordStem != null)
                 )
                     simplePermute(chunks).map(p ⇒ p.map(_.wordStem) → 
p).toMap.values.foreach(seq ⇒
-                        add(seq, isDirect = seq == chunks, perm = true, sparse 
= hasDsl(seq))
+                        add(seq, isDirect = seq == chunks, perm = true, sparse 
= sp)
                     )
                 else
-                    add(chunks, isDirect = true, perm = permuteFlag, sparse = 
hasDsl(chunks) || (sparseFlag && chunks.size > 1))
+                    add(chunks, isDirect = true, perm = permuteElem, sparse = 
sp)
             }
 
             /**
@@ -483,7 +481,7 @@ object NCDeployManager extends NCService with 
DecorateAsScala {
 
         // Scan for intent annotations in the model class.
         val intents = scanIntents(mdl)
-        
+
         var solver: NCIntentSolver = null
 
         if (intents.nonEmpty) {
@@ -508,15 +506,15 @@ object NCDeployManager extends NCService with 
DecorateAsScala {
         def toMap(set: Set[SynonymHolder]): Map[String, Seq[NCProbeSynonym]] =
             set.groupBy(_.elmId).map(p ⇒ p._1 → 
p._2.map(_.syn).toSeq.sorted.reverse)
 
-        val notDsl = filterDsl(syns.toSet, dsl = false)
+        val simple = idl(syns.toSet, idl = false)
 
         NCProbeModel(
             model = mdl,
             solver = solver,
             intents = intents.map(_._1).toSeq,
-            continuousSynonyms = mkFastAccessMap(filterSparse(notDsl, sparse = 
false), NCProbeSynonymsWrapper(_)),
-            sparseSynonyms = toMap(filterSparse(notDsl, sparse = true)),
-            dslSynonyms = toMap(filterDsl(syns.toSet, dsl = true)),
+            continuousSynonyms = mkFastAccessMap(sparse(simple, sp = false), 
NCProbeSynonymsWrapper(_)),
+            sparseSynonyms = toMap(sparse(simple, sp = true)),
+            idlSynonyms = toMap(idl(syns.toSet, idl = true)),
             addStopWordsStems = addStopWords,
             exclStopWordsStems = exclStopWords,
             suspWordsStems = suspWords,
@@ -1004,8 +1002,8 @@ object NCDeployManager extends NCService with 
DecorateAsScala {
         }
         // IDL-based synonym.
         else if (startsAndEnds(IDL_FIX, chunk)) {
-            val dsl = stripSuffix(IDL_FIX, chunk)
-            val compUnit = NCIdlCompiler.compileSynonym(dsl, mdl, 
mdl.getOrigin)
+            val idl = stripSuffix(IDL_FIX, chunk)
+            val compUnit = NCIdlCompiler.compileSynonym(idl, mdl, 
mdl.getOrigin)
 
             val x = NCProbeSynonymChunk(alias = compUnit.alias.orNull, kind = 
IDL, origText = chunk, idlPred = compUnit.pred)
 
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelManager.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelManager.scala
index 18009f8..2b8313c 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelManager.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelManager.scala
@@ -59,30 +59,33 @@ object NCModelManager extends NCService with 
DecorateAsScala {
                 val mdl = w.model
 
                 // TODO:
-                
println("w.directSynonyms="+w.continuousSynonyms.getOrElse("col:orders_order_date",
 Map.empty).mkString("\n"))
-                
println("w.sparseSynonyms="+w.sparseSynonyms.getOrElse("col:orders_order_date", 
Seq.empty).mkString("\n"))
-                
println("w.synonymsDsl="+w.dslSynonyms.getOrElse("col:orders_order_date", 
Seq.empty).mkString("\n"))
+                val elemId = "col:orders_order_date"
+
+                
println("w.directSynonyms="+w.continuousSynonyms.getOrElse(elemId, 
Map.empty).mkString("\n"))
+                println("w.sparseSynonyms="+w.sparseSynonyms.getOrElse(elemId, 
Seq.empty).mkString("\n"))
+                println("w.idlSynonyms="+w.idlSynonyms.getOrElse(elemId, 
Seq.empty).mkString("\n"))
                 println
 
-                val synContCnt = 
w.continuousSynonyms.flatMap(_._2.map(_._2.count)).sum
-                val synSparseCnt = w.sparseSynonyms.map(_._2.size).sum
-                val synDslCnt = w.dslSynonyms.map(_._2.size).sum
-                val elmCnt = w.elements.keySet.size
-                val intentCnt = w.intents.size
+                val contCnt = 
w.continuousSynonyms.flatMap(_._2.map(_._2.count)).sum
+                val sparseCnt = w.sparseSynonyms.map(_._2.size).sum
+                val allIdlSyns = w.idlSynonyms.values.flatten
+                val sparseIdlCnt = allIdlSyns.count(_.sparse)
+                val contIdlCnt = allIdlSyns.size - sparseIdlCnt
 
                 def withWarn(i: Int): String = if (i == 0) s"0 ${r("(!)")}" 
else i.toString
 
                 tbl += Seq(
-                    s"Name:           ${bo(c(mdl.getName))}",
-                    s"ID:             ${bo(mdl.getId)}",
-                    s"Version:        ${mdl.getVersion}",
-                    s"Origin:         ${mdl.getOrigin}",
-                    s"Elements:       ${withWarn(elmCnt)}",
-                    s"Synonyms:       ${withWarn(elmCnt)}",
-                    s" - Continuous:  $synContCnt",
-                    s" - Sparse:      $synSparseCnt",
-                    s" - DSL(Sparse): $synDslCnt",
-                    s"Intents:        ${withWarn(intentCnt)}"
+                    s"Name:                  ${bo(c(mdl.getName))}",
+                    s"ID:                    ${bo(mdl.getId)}",
+                    s"Version:               ${mdl.getVersion}",
+                    s"Origin:                ${mdl.getOrigin}",
+                    s"Elements:              
${withWarn(w.elements.keySet.size)}",
+                    s"Synonyms:",
+                    s" - Simple, continuous: $contCnt",
+                    s" - Simple, sparse:     $sparseCnt",
+                    s" - IDL, continuous:    $contIdlCnt",
+                    s" - IDL, Sparse:        $sparseIdlCnt",
+                    s"Intents:               ${withWarn(w.intents.size)}"
                 )
             })
         }
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 713132c..29ec156 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
@@ -21,7 +21,7 @@ import io.opencensus.trace.Span
 import org.apache.nlpcraft.common._
 import org.apache.nlpcraft.common.nlp.{NCNlpSentenceToken ⇒ NlpToken, _}
 import org.apache.nlpcraft.model._
-import org.apache.nlpcraft.probe.mgrs.NCProbeSynonym.NCDslContent
+import org.apache.nlpcraft.probe.mgrs.NCProbeSynonym.NCIdlContent
 import 
org.apache.nlpcraft.probe.mgrs.NCProbeSynonymChunkKind.{NCSynonymChunkKind, _}
 import org.apache.nlpcraft.probe.mgrs.nlp.NCProbeEnricher
 import org.apache.nlpcraft.probe.mgrs.nlp.impl.NCRequestImpl
@@ -73,7 +73,7 @@ object NCModelEnricher extends NCProbeEnricher with 
DecorateAsScala {
     }
 
     case class Complex(
-        data: NCDslContent,
+        data: NCIdlContent,
         isToken: Boolean,
         isWord: Boolean,
         token: NCToken,
@@ -132,7 +132,7 @@ object NCModelEnricher extends NCProbeEnricher with 
DecorateAsScala {
     object State extends Enumeration {
         type State = Value
 
-        val SIMPLE, DSL_FIRST, DSL_NEXT = Value
+        val SIMPLE, IDL_FIRST, IDL_NEXT = Value
     }
 
     import State._
@@ -378,7 +378,7 @@ object NCModelEnricher extends NCProbeEnricher with 
DecorateAsScala {
       * @param seq
       * @param s
       */
-    private def toParts(seq: Seq[NCDslContent], s: Synonym): Seq[TokType] =
+    private def toParts(seq: Seq[NCIdlContent], s: Synonym): Seq[TokType] =
         seq.zip(s.map(_.kind)).flatMap {
             case (complex, kind) ⇒ if (complex.isLeft) Some(complex.left.get → 
kind) else None
         }
@@ -388,7 +388,7 @@ object NCModelEnricher extends NCProbeEnricher with 
DecorateAsScala {
       * @param tows
       * @param ns
       */
-    private def toTokens(tows: Seq[NCDslContent], ns: NCNlpSentence): 
Seq[NlpToken] =
+    private def toTokens(tows: Seq[NCIdlContent], ns: NCNlpSentence): 
Seq[NlpToken] =
         (
             tows.filter(_.isRight).map(_.right.get) ++
                 tows.filter(_.isLeft).map(_.left.get).
@@ -499,7 +499,7 @@ object NCModelEnricher extends NCProbeEnricher with 
DecorateAsScala {
             val contCache =
                 mutable.HashMap.empty[String, mutable.ArrayBuffer[Seq[Int]]] ++
                     mdl.elements.keys.map(k ⇒ k → 
mutable.ArrayBuffer.empty[Seq[Int]])
-            lazy val dslCache = mutable.HashSet.empty[Seq[Complex]]
+            lazy val idlCache = mutable.HashSet.empty[Seq[Complex]]
 
             var found = false
 
@@ -536,7 +536,7 @@ object NCModelEnricher extends NCProbeEnricher with 
DecorateAsScala {
 
             for (toks ← combosToks) {
                 val tokIdxs = toks.map(_.index)
-                lazy val dslCombs: Seq[Seq[Complex]] = 
mkComplexCombinations(h, toks, dslCache.toSet)
+                lazy val idlCombs: Seq[Seq[Complex]] = 
mkComplexCombinations(h, toks, idlCache.toSet)
                 lazy val tokStems = toks.map(_.stem).mkString(" ")
 
                 // Attempt to match each element.
@@ -550,8 +550,8 @@ object NCModelEnricher extends NCProbeEnricher with 
DecorateAsScala {
                     // 1. SIMPLE.
                     val simpleEnabled =
                         state match {
-                            case SIMPLE ⇒ !mdl.hasDslSynonyms(elemId)
-                            case DSL_FIRST ⇒ mdl.hasDslSynonyms(elemId)
+                            case SIMPLE ⇒ !mdl.hasIdlSynonyms(elemId)
+                            case IDL_FIRST ⇒ mdl.hasIdlSynonyms(elemId)
                             case _ ⇒ false
                         }
 
@@ -587,32 +587,27 @@ object NCModelEnricher extends NCProbeEnricher with 
DecorateAsScala {
                     // 1.2 Sparse.
                     if (simpleEnabled && !found)
                         for (s ← get(mdl.sparseSynonyms, elemId) if !found)
-                            s.trySparseMatch(toks) match {
+                            s.sparseMatch(toks) match {
                                 case Some(res) ⇒ add("simple sparse", elm, 
res, tokIdxs, s)
                                 case None ⇒ // No-op.
                             }
 
-                    // 2. DSL.
-                    if (state != SIMPLE && mdl.hasDslSynonyms) {
+                    // 2. IDL.
+                    if (state != SIMPLE && mdl.hasIdlSynonyms) {
                         found = false
 
                         // 2.1 Sparse.
-                        if (mdl.hasDslSynonyms)
-                            for (s ← get(mdl.dslSynonyms, elemId); comb ← 
dslCombs if !found)
-                                s.trySparseMatch(comb.map(_.data), req) match {
+                        if (mdl.hasIdlSynonyms)
+                            for (s ← get(mdl.idlSynonyms, elemId); comb ← 
idlCombs if !found)
+                                s.idlMatch(comb.map(_.data), req) match {
                                     case Some(res) ⇒
-                                        add("DSL sparse", elm, toTokens(res, 
ns), tokIdxs, s, toParts(res, s))
+                                        val typ = if (s.sparse) "IDL sparse" 
else "IDL continuous"
 
-                                        dslCache += comb
+                                        add(typ, elm, toTokens(res, ns), 
tokIdxs, s, toParts(res, s))
+
+                                        idlCache += comb
                                     case None ⇒ // No-op.
                                 }
-                        // 2.2 Continuous.
-                        else
-                            for (s ← get(mdl.dslSynonyms, elemId); comb ← 
dslCombs if !found)
-                                if (s.isMatch(comb.map(_.data), req)) {
-                                    add("DSL continuous", elm, toks, tokIdxs, 
s, toPartsComplex(comb, s))
-                                    dslCache += comb
-                                }
                     }
                 }
             }
@@ -628,17 +623,17 @@ object NCModelEnricher extends NCProbeEnricher with 
DecorateAsScala {
 
             lazy val h = mkComplexes(mdl, ns)
 
-            execute(mdl, ns, combosToks, if (ns.firstProbePhase) SIMPLE else 
DSL_NEXT, req, h, parent)
+            execute(mdl, ns, combosToks, if (ns.firstProbePhase) SIMPLE else 
IDL_NEXT, req, h, parent)
 
             if (ns.firstProbePhase) {
                 ns.firstProbePhase = false
 
-                execute(mdl, ns, combosToks, DSL_FIRST, req, h, parent)
+                execute(mdl, ns, combosToks, IDL_FIRST, req, h, parent)
             }
 
             processParsers(mdl, ns, span, req)
         }
     }
 
-    def isComplex(mdl: NCProbeModel): Boolean = mdl.dslSynonyms.nonEmpty || 
!mdl.model.getParsers.isEmpty
+    def isComplex(mdl: NCProbeModel): Boolean = mdl.hasIdlSynonyms || 
!mdl.model.getParsers.isEmpty
 }
\ No newline at end of file
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIdlSpec.scala 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIdlSpec.scala
index a02424e..c92108b 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIdlSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIdlSpec.scala
@@ -28,7 +28,7 @@ import scala.language.implicitConversions
   * IDL test model.
   */
 class NCIdlSpecModel extends NCModelAdapter(
-    "nlpcraft.intents.dsl.test", "IDL Test Model", "1.0"
+    "nlpcraft.intents.idl.test", "IDL Test Model", "1.0"
 ) {
     private implicit def convert(s: String): NCResult = NCResult.text(s)
 
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIdlSpec2.scala 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIdlSpec2.scala
index 31b4808..dd29cca 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIdlSpec2.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIdlSpec2.scala
@@ -27,7 +27,7 @@ import scala.language.implicitConversions
   * IDL test model.
   */
 class NCIdlSpecModel2 extends NCModelAdapter(
-    "nlpcraft.intents.dsl.test", "IDL Test Model", "1.0"
+    "nlpcraft.intents.idl.test", "IDL Test Model", "1.0"
 ) {
     override def getElements: util.Set[NCElement] = Set(NCTestElement("a"))
 
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlTestSpec.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlTestSpec.scala
index 424da4a..75b45e2 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlTestSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/NCIdlTestSpec.scala
@@ -40,7 +40,7 @@ class NCIdlTestSpec {
         if (NCEmbeddedProbe.start(null, 
Collections.singletonList(classOf[NCIdlTestModel].getName))) {
             cli = new NCTestClientBuilder().newBuilder.build
 
-            cli.open("nlpcraft.dsl.test")
+            cli.open("nlpcraft.idl.test")
         }
     }
 
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpec.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpec.scala
index 0f09a66..6b5da23 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpec.scala
@@ -37,16 +37,16 @@ class NCIdlCompilerSpec {
     
     /**
      *
-     * @param dsl
+     * @param idl
      */
-    private def checkCompileOk(dsl: String): Unit =
+    private def checkCompileOk(idl: String): Unit =
         try {
-            NCIdlCompiler.compileIntents(dsl, MODEL, MODEL_ID)
+            NCIdlCompiler.compileIntents(idl, MODEL, MODEL_ID)
 
             assert(true)
         }
         catch {
-            case e: Exception ⇒ assert(false, e)
+            case e: Exception ⇒ assert(assertion = false, e)
         }
 
     /**
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/idl_test_model.yaml
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/idl_test_model.yaml
index b436110..a9b70f1 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/idl_test_model.yaml
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/idl_test_model.yaml
@@ -15,7 +15,7 @@
 # limitations under the License.
 #
 
-id: "nlpcraft.dsl.test"
+id: "nlpcraft.idl.test"
 name: "IDL Test Model"
 version: "1.0"
 description: "IDL test model."

Reply via email to