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

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


The following commit(s) were added to refs/heads/master by this push:
     new 835d175  Fix for NLPCRAFT-294.
835d175 is described below

commit 835d17519438850d6281db26f86b1446ed1a242a
Author: Aaron Radzinzski <[email protected]>
AuthorDate: Sat Apr 17 02:18:47 2021 +0300

    Fix for NLPCRAFT-294.
---
 .../scala/org/apache/nlpcraft/common/nlp/NCNlpSentenceNote.scala     | 5 +----
 nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCToken.java       | 2 +-
 .../apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala    | 1 +
 .../scala/org/apache/nlpcraft/model/intent/compiler/antlr4/NCIdl.g4  | 1 +
 .../nlpcraft/probe/mgrs/nlp/enrichers/model/NCModelEnricher.scala    | 4 ++--
 .../model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala    | 1 +
 6 files changed, 7 insertions(+), 7 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/NCNlpSentenceNote.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/NCNlpSentenceNote.scala
index 9adbe01..3e60c61 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/NCNlpSentenceNote.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/NCNlpSentenceNote.scala
@@ -42,7 +42,6 @@ class NCNlpSentenceNote(private val values: Map[String, 
JSerializable]) extends
     lazy val tokenIndexes: Seq[Int] = 
values("tokWordIndexes").asInstanceOf[java.util.List[Int]].asScala // Includes 
1st and last indices too.
     lazy val wordIndexes: Seq[Int] = 
values("wordIndexes").asInstanceOf[java.util.List[Int]].asScala // Includes 1st 
and last indices too.
     lazy val sparsity: Int = values("sparsity").asInstanceOf[Int]
-    lazy val isContiguous: Boolean = values("contiguous").asInstanceOf[Boolean]
     lazy val isDirect: Boolean = values("direct").asInstanceOf[Boolean]
     lazy val isUser: Boolean = {
         val i = noteType.indexOf(":")
@@ -198,7 +197,6 @@ object NCNlpSentenceNote {
         "tokMinIndex",
         "tokMaxIndex",
         "tokWordIndexes",
-        "contiguous",
         "sparsity"
     )
 
@@ -239,8 +237,7 @@ object NCNlpSentenceNote {
                ("maxIndex" → tokMaxIndex) :+
                ("wordIndexes" → tokWordIndexes) :+
                ("wordLength" → len) :+
-               ("sparsity" → sparsity) :+
-               ("contiguous" → (sparsity == 0))
+               ("sparsity" → sparsity)
             ).map(p ⇒ p._1 → p._2.asInstanceOf[JSerializable]): _*).toMap
         )
     }
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCToken.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCToken.java
index 1e71758..bdf7fe9 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCToken.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCToken.java
@@ -432,7 +432,7 @@ public interface NCToken extends NCMetadata {
 
     /**
      * A shortcut method to get numeric value of how sparse the token is. 
Sparsity zero means that all
-     * individual words in the token follow each other.
+     * individual words in the token follow each other (regardless of the 
order).
      * <p>
      * This method is equivalent to:
      * <pre class="brush: java">
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala
index 1846088..2389758 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala
@@ -1100,6 +1100,7 @@ trait NCIdlCompilerBase {
             case "tok_is_abstract" ⇒ arg1Tok() match { case x ⇒ stack.push(() 
⇒ { Z(toToken(x().value).isAbstract, 1) }) }
             case "tok_is_bracketed" ⇒ arg1Tok() match { case x ⇒ stack.push(() 
⇒ { Z(toToken(x().value).isBracketed, 1) }) }
             case "tok_is_direct" ⇒ arg1Tok() match { case x ⇒ stack.push(() ⇒ 
{ Z(toToken(x().value).isDirect, 1) }) }
+            case "tok_is_permutated" ⇒ arg1Tok() match { case x ⇒ 
stack.push(() ⇒ { Z(!toToken(x().value).isDirect, 1) }) }
             case "tok_is_english" ⇒ arg1Tok() match { case x ⇒ stack.push(() ⇒ 
{ Z(toToken(x().value).isEnglish, 1) }) }
             case "tok_is_freeWord" ⇒ arg1Tok() match { case x ⇒ stack.push(() 
⇒ { Z(toToken(x().value).isFreeWord, 1) }) }
             case "tok_is_quoted" ⇒ arg1Tok() match { case x ⇒ stack.push(() ⇒ 
{ Z(toToken(x().value).isQuoted, 1) }) }
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/antlr4/NCIdl.g4
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/antlr4/NCIdl.g4
index 1e62547..4d2d5dd 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/antlr4/NCIdl.g4
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/antlr4/NCIdl.g4
@@ -157,6 +157,7 @@ FUN_NAME
     | 'tok_is_abstract'
     | 'tok_is_bracketed'
     | 'tok_is_direct'
+    | 'tok_is_permutated'
     | 'tok_is_english'
     | 'tok_is_freeWord'
     | 'tok_is_quoted'
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 1e1b441..85faaba 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
@@ -591,11 +591,11 @@ object NCModelEnricher extends NCProbeEnricher with 
DecorateAsScala {
     private def alreadyMarked(ns: Sentence, elemId: String, toks: 
Seq[NlpToken], sliceToksIdxsSorted: Seq[Int]): Boolean = {
         lazy val toksIdxsSorted = toks.map(_.index).sorted
 
-        sliceToksIdxsSorted.map(ns).forall(_.exists(n ⇒ n.noteType == elemId 
&& n.isContiguous)) ||
+        sliceToksIdxsSorted.map(ns).forall(_.exists(n ⇒ n.noteType == elemId 
&& n.sparsity == 0)) ||
         toks.exists(_.exists(n ⇒
             n.noteType == elemId &&
             (
-                (n.isContiguous &&
+                (n.sparsity == 0 &&
                     (sliceToksIdxsSorted.containsSlice(n.tokenIndexes) || 
n.tokenIndexes.containsSlice(toksIdxsSorted))
                 )
                     ||
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
index cdf2e49..a83d448 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
@@ -63,6 +63,7 @@ class NCIdlFunctionsToken extends NCIdlFunctions {
             mkMeta(truth = s"tok_is_abstract() == false"),
             mkMeta(truth = s"tok_is_bracketed() == 
${meta("nlpcraft:nlp:bracketed")}"),
             mkMeta(truth = s"tok_is_direct() == 
${meta("nlpcraft:nlp:direct")}"),
+            mkMeta(truth = s"tok_is_permutated() != 
${meta("nlpcraft:nlp:direct")}"),
             mkMeta(truth = s"tok_is_english() == 
${meta("nlpcraft:nlp:english")}"),
             mkMeta(truth = s"tok_is_freeWord() == 
${meta("nlpcraft:nlp:freeword")}"),
             mkMeta(truth = s"tok_is_quoted() == 
${meta("nlpcraft:nlp:quoted")}"),

Reply via email to