This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-443-1
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-443-1 by this push:
new c373eea WIP.
c373eea is described below
commit c373eea2dd661cf0973c9a61cefd053560c26bcc
Author: Sergey Kamov <[email protected]>
AuthorDate: Thu Sep 23 18:55:43 2021 +0300
WIP.
---
.../nlpcraft/probe/mgrs/NCProbeVariants.scala | 2 +-
.../probe/mgrs/synonyms/NCSynonymsManager.scala | 19 +-
.../nlp/enrichers/sort/NCEnricherSortSpec.scala | 338 ++++++++++-----------
3 files changed, 175 insertions(+), 184 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeVariants.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeVariants.scala
index 8bc0113..8aced5f 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeVariants.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeVariants.scala
@@ -268,7 +268,7 @@ object NCProbeVariants {
for ((tok, tokNlp) <- toks.zip(nlpSen) if tokNlp.isUser)
process(tok, tokNlp)
- ok = ok && NCSynonymsManager.isStillValid(srvReqId,
toks.toSeq, nlpSen)
+ ok = ok && NCSynonymsManager.isStillValid(srvReqId, toks.toSeq)
if (ok) Some(new NCVariantImpl(toks.asJava)) else None
})
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/synonyms/NCSynonymsManager.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/synonyms/NCSynonymsManager.scala
index 25987dd..0825d20 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/synonyms/NCSynonymsManager.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/synonyms/NCSynonymsManager.scala
@@ -18,7 +18,7 @@
package org.apache.nlpcraft.probe.mgrs.synonyms
import io.opencensus.trace.Span
-import org.apache.nlpcraft.common.nlp.{NCNlpSentence, NCNlpSentenceNote,
NCNlpSentenceToken}
+import org.apache.nlpcraft.common.nlp.{NCNlpSentenceNote, NCNlpSentenceToken}
import org.apache.nlpcraft.common.{NCService, U}
import org.apache.nlpcraft.model._
import org.apache.nlpcraft.model.intent.{NCIdlContext, NCIdlFunction}
@@ -285,12 +285,11 @@ object NCSynonymsManager extends NCService {
*
* @param srvReqId
* @param senToks
- * @param nlpSen
*/
- def isStillValid(srvReqId: String, senToks: Seq[NCToken], nlpSen:
NCNlpSentence): Boolean =
+ def isStillValid(srvReqId: String, senToks: Seq[NCToken]): Boolean =
idlCache.get(srvReqId) match {
case Some(m) =>
- lazy val allCheckedSenToks = {
+ val allCheckedSenToks = {
val set = mutable.HashSet.empty[Key]
def add(t: NCToken): Unit = {
@@ -301,14 +300,6 @@ object NCSynonymsManager extends NCService {
senToks.foreach(add)
- set ++=
- senToks.flatMap(t =>
- nlpSen.getInitialNlpNote(t.getStartCharIndex,
t.getEndCharIndex) match {
- case Some(nlpNote) =>
Some(Key(nlpNote.noteType, t.getStartCharIndex, t.getEndCharIndex))
- case None => None
- }
- )
-
set
}
@@ -321,8 +312,8 @@ object NCSynonymsManager extends NCService {
v.predicate.apply(
tok, NCIdlContext(toks =
winHistVariant, req = v.request)
).value.asInstanceOf[Boolean] &&
- winHistVariant.map(Key(_)).forall(
- allCheckedSenToks.contains
+
winHistVariant.map(Key(_)).forall(t =>
+ t.id == "nlpcraft:nlp" ||
allCheckedSenToks.contains(t)
)
)
)
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCEnricherSortSpec.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCEnricherSortSpec.scala
index d19de00..7b8d858 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCEnricherSortSpec.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCEnricherSortSpec.scala
@@ -50,11 +50,11 @@ class NCEnricherSortSpec extends NCEnricherBaseSpec {
@Test
def test(): Unit =
runBatch(
-// _ => checkExists(
-// "sort A",
-// srt(text = "sort", typ = SUBJ_ONLY, note = "A", index = 1),
-// usr("A", "A")
-// ),
+ _ => checkExists(
+ "sort A",
+ srt(text = "sort", typ = SUBJ_ONLY, note = "A", index = 1),
+ usr("A", "A")
+ ),
_ => checkExists(
"sort A by A",
srt(text = "sort", subjNote = "A", subjIndex = 1, byNote =
"A", byIndex = 3),
@@ -62,169 +62,169 @@ class NCEnricherSortSpec extends NCEnricherBaseSpec {
nlp(text = "by", isStop = true),
usr(text = "A", id = "A")
),
-// _ => checkExists(
-// "sort A, C by A, C",
-// srt(text = "sort", subjNotes = Seq("A", "C"), subjIndexes =
Seq(1, 3), byNotes = Seq("A", "C"), byIndexes = Seq(5, 7)),
-// usr(text = "A", id = "A"),
-// nlp(text = ",", isStop = true),
-// usr(text = "C", id = "C"),
-// nlp(text = "by", isStop = true),
-// usr(text = "A", id = "A"),
-// nlp(text = ",", isStop = true),
-// usr(text = "C", id = "C")
-// ),
-// _ => checkExists(
-// "sort A C by A C",
-// srt(text = "sort", subjNotes = Seq("A", "C"), subjIndexes =
Seq(1, 2), byNotes = Seq("A", "C"), byIndexes = Seq(4, 5)),
-// usr(text = "A", id = "A"),
-// usr(text = "C", id = "C"),
-// nlp(text = "by", isStop = true),
-// usr(text = "A", id = "A"),
-// usr(text = "C", id = "C")
-// ),
-// _ => checkExists(
-// "sort A B by A B",
-// srt(text = "sort", subjNotes = Seq("A", "B"), subjIndexes =
Seq(1, 2), byNotes = Seq("A", "B"), byIndexes = Seq(4, 5)),
-// usr(text = "A", id = "A"),
-// usr(text = "B", id = "B"),
-// nlp(text = "by", isStop = true),
-// usr(text = "A", id = "A"),
-// usr(text = "B", id = "B")
-// ),
-// _ => checkExists(
-// "sort A B by A B",
-// srt(text = "sort", subjNote = "AB", subjIndex = 1, byNote =
"AB", byIndex = 3),
-// usr(text = "A B", id = "AB"),
-// nlp(text = "by", isStop = true),
-// usr(text = "A B", id = "AB")
-// ),
-// _ => checkExists(
-// "A classify",
-// usr(text = "A", id = "A"),
-// srt(text = "classify", typ = SUBJ_ONLY, note = "A", index =
0)
-// ),
-// _ => checkExists(
-// "the A the classify",
-// nlp(text = "the", isStop = true),
-// usr(text = "A", id = "A"),
-// nlp(text = "the", isStop = true),
-// srt(text = "classify", typ = SUBJ_ONLY, note = "A", index =
1)
-// ),
-// _ => checkExists(
-// "segment A by top down",
-// srt(text = "segment", typ = SUBJ_ONLY, note = "A", index =
1, asc = false),
-// usr(text = "A", id = "A"),
-// nlp(text = "by top down", isStop = true)
-// ),
-// _ => checkExists(
-// "segment A in bottom up order",
-// srt(text = "segment", typ = SUBJ_ONLY, note = "A", index =
1, asc = true),
-// usr(text = "A", id = "A"),
-// nlp(text = "in bottom up order", isStop = true)
-// ),
-// // `by` is redundant word here
-// _ => checkExists(
-// "segment A by in bottom up order",
-// srt(text = "segment", typ = SUBJ_ONLY, note = "A", index =
1),
-// usr(text = "A", id = "A"),
-// nlp(text = "by"),
-// nlp(text = "in"),
-// nlp(text = "bottom"),
-// nlp(text = "up"),
-// nlp(text = "order")
-// ),
-// _ => checkExists(
-// "the segment the A the in bottom up the order the",
-// nlp(text = "the", isStop = true),
-// srt(text = "segment", typ = SUBJ_ONLY, note = "A", index =
3, asc = true),
-// nlp(text = "the", isStop = true),
-// usr(text = "A", id = "A"),
-// nlp(text = "the in bottom up the order the", isStop = true)
-// ),
-// _ => checkExists(
-// "the segment the A the by bottom up the order the",
-// nlp(text = "the", isStop = true),
-// srt(text = "segment", typ = SUBJ_ONLY, note = "A", index =
3, asc = true),
-// nlp(text = "the", isStop = true),
-// usr(text = "A", id = "A"),
-// nlp(text = "the by bottom up the order the", isStop = true)
-// ),
-// _ => checkExists(
-// "A classify",
-// usr(text = "A", id = "A"),
-// srt(text = "classify", typ = SUBJ_ONLY, note = "A", index =
0)
-// ),
-// _ => checkAll(
-// "A B classify",
-// Seq(
-// usr(text = "A B", id = "AB"),
-// srt(text = "classify", typ = SUBJ_ONLY, note = "AB",
index = 0)
-// ),
-// Seq(
-// usr(text = "A", id = "A"),
-// usr(text = "B", id = "B"),
-// srt(text = "classify", subjNotes = Seq("A", "B"),
subjIndexes = Seq(0, 1))
-// ),
-// Seq(
-// usr(text = "A", id = "A"),
-// usr(text = "B", id = "B"),
-// srt(text = "classify", subjNotes = Seq("B"), subjIndexes
= Seq(1))
-// )
-// ),
-// _ => checkAll(
-// "D classify",
-// Seq(
-// usr(text = "D", id = "D1"),
-// srt(text = "classify", typ = SUBJ_ONLY, note = "D1",
index = 0)
-// ),
-// Seq(
-// usr(text = "D", id = "D2"),
-// srt(text = "classify", typ = SUBJ_ONLY, note = "D2",
index = 0)
-// )
-// ),
-// _ => checkAll(
-// "sort by A",
-// Seq(
-// srt(text = "sort by", typ = BY_ONLY, note = "A", index =
1),
-// usr(text = "A", id = "A")
-// )
-// ),
-// _ => checkExists(
-// "organize by A, B top down",
-// srt(text = "organize by", byNotes = Seq("A", "B"), byIndexes
= Seq(1, 3), asc = Some(false)),
-// usr(text = "A", id = "A"),
-// nlp(text = ",", isStop = true),
-// usr(text = "B", id = "B"),
-// nlp(text = "top down", isStop = true)
-// ),
-// _ => checkExists(
-// "organize by A, B from bottom up order",
-// srt(text = "organize by", byNotes = Seq("A", "B"), byIndexes
= Seq(1, 3), asc = Some(true)),
-// usr(text = "A", id = "A"),
-// nlp(text = ",", isStop = true),
-// usr(text = "B", id = "B"),
-// nlp(text = "from bottom up order", isStop = true)
-// ),
-// _ => checkExists(
-// "organize by A, B the descending",
-// srt(text = "organize by", byNotes = Seq("A", "B"), byIndexes
= Seq(1, 3), asc = Some(false)),
-// usr(text = "A", id = "A"),
-// nlp(text = ",", isStop = true),
-// usr(text = "B", id = "B"),
-// nlp(text = "the descending", isStop = true)
-// ),
-// _ => checkExists(
-// "organize by A, B, asc",
-// srt(text = "organize by", byNotes = Seq("A", "B"), byIndexes
= Seq(1, 3), asc = Some(true)),
-// usr(text = "A", id = "A"),
-// nlp(text = ",", isStop = true),
-// usr(text = "B", id = "B"),
-// nlp(text = ", asc", isStop = true)
-// ),
-// _ => checkExists(
-// "sort A the A the A",
-// srt(text = "sort", typ = SUBJ_ONLY, note = "wrapperA", index
= 1),
-// usr("A the A the A", "wrapperA")
-// )
+ _ => checkExists(
+ "sort A, C by A, C",
+ srt(text = "sort", subjNotes = Seq("A", "C"), subjIndexes =
Seq(1, 3), byNotes = Seq("A", "C"), byIndexes = Seq(5, 7)),
+ usr(text = "A", id = "A"),
+ nlp(text = ",", isStop = true),
+ usr(text = "C", id = "C"),
+ nlp(text = "by", isStop = true),
+ usr(text = "A", id = "A"),
+ nlp(text = ",", isStop = true),
+ usr(text = "C", id = "C")
+ ),
+ _ => checkExists(
+ "sort A C by A C",
+ srt(text = "sort", subjNotes = Seq("A", "C"), subjIndexes =
Seq(1, 2), byNotes = Seq("A", "C"), byIndexes = Seq(4, 5)),
+ usr(text = "A", id = "A"),
+ usr(text = "C", id = "C"),
+ nlp(text = "by", isStop = true),
+ usr(text = "A", id = "A"),
+ usr(text = "C", id = "C")
+ ),
+ _ => checkExists(
+ "sort A B by A B",
+ srt(text = "sort", subjNotes = Seq("A", "B"), subjIndexes =
Seq(1, 2), byNotes = Seq("A", "B"), byIndexes = Seq(4, 5)),
+ usr(text = "A", id = "A"),
+ usr(text = "B", id = "B"),
+ nlp(text = "by", isStop = true),
+ usr(text = "A", id = "A"),
+ usr(text = "B", id = "B")
+ ),
+ _ => checkExists(
+ "sort A B by A B",
+ srt(text = "sort", subjNote = "AB", subjIndex = 1, byNote =
"AB", byIndex = 3),
+ usr(text = "A B", id = "AB"),
+ nlp(text = "by", isStop = true),
+ usr(text = "A B", id = "AB")
+ ),
+ _ => checkExists(
+ "A classify",
+ usr(text = "A", id = "A"),
+ srt(text = "classify", typ = SUBJ_ONLY, note = "A", index = 0)
+ ),
+ _ => checkExists(
+ "the A the classify",
+ nlp(text = "the", isStop = true),
+ usr(text = "A", id = "A"),
+ nlp(text = "the", isStop = true),
+ srt(text = "classify", typ = SUBJ_ONLY, note = "A", index = 1)
+ ),
+ _ => checkExists(
+ "segment A by top down",
+ srt(text = "segment", typ = SUBJ_ONLY, note = "A", index = 1,
asc = false),
+ usr(text = "A", id = "A"),
+ nlp(text = "by top down", isStop = true)
+ ),
+ _ => checkExists(
+ "segment A in bottom up order",
+ srt(text = "segment", typ = SUBJ_ONLY, note = "A", index = 1,
asc = true),
+ usr(text = "A", id = "A"),
+ nlp(text = "in bottom up order", isStop = true)
+ ),
+ // `by` is redundant word here
+ _ => checkExists(
+ "segment A by in bottom up order",
+ srt(text = "segment", typ = SUBJ_ONLY, note = "A", index = 1),
+ usr(text = "A", id = "A"),
+ nlp(text = "by"),
+ nlp(text = "in"),
+ nlp(text = "bottom"),
+ nlp(text = "up"),
+ nlp(text = "order")
+ ),
+ _ => checkExists(
+ "the segment the A the in bottom up the order the",
+ nlp(text = "the", isStop = true),
+ srt(text = "segment", typ = SUBJ_ONLY, note = "A", index = 3,
asc = true),
+ nlp(text = "the", isStop = true),
+ usr(text = "A", id = "A"),
+ nlp(text = "the in bottom up the order the", isStop = true)
+ ),
+ _ => checkExists(
+ "the segment the A the by bottom up the order the",
+ nlp(text = "the", isStop = true),
+ srt(text = "segment", typ = SUBJ_ONLY, note = "A", index = 3,
asc = true),
+ nlp(text = "the", isStop = true),
+ usr(text = "A", id = "A"),
+ nlp(text = "the by bottom up the order the", isStop = true)
+ ),
+ _ => checkExists(
+ "A classify",
+ usr(text = "A", id = "A"),
+ srt(text = "classify", typ = SUBJ_ONLY, note = "A", index = 0)
+ ),
+ _ => checkAll(
+ "A B classify",
+ Seq(
+ usr(text = "A B", id = "AB"),
+ srt(text = "classify", typ = SUBJ_ONLY, note = "AB", index
= 0)
+ ),
+ Seq(
+ usr(text = "A", id = "A"),
+ usr(text = "B", id = "B"),
+ srt(text = "classify", subjNotes = Seq("A", "B"),
subjIndexes = Seq(0, 1))
+ ),
+ Seq(
+ usr(text = "A", id = "A"),
+ usr(text = "B", id = "B"),
+ srt(text = "classify", subjNotes = Seq("B"), subjIndexes =
Seq(1))
+ )
+ ),
+ _ => checkAll(
+ "D classify",
+ Seq(
+ usr(text = "D", id = "D1"),
+ srt(text = "classify", typ = SUBJ_ONLY, note = "D1", index
= 0)
+ ),
+ Seq(
+ usr(text = "D", id = "D2"),
+ srt(text = "classify", typ = SUBJ_ONLY, note = "D2", index
= 0)
+ )
+ ),
+ _ => checkAll(
+ "sort by A",
+ Seq(
+ srt(text = "sort by", typ = BY_ONLY, note = "A", index =
1),
+ usr(text = "A", id = "A")
+ )
+ ),
+ _ => checkExists(
+ "organize by A, B top down",
+ srt(text = "organize by", byNotes = Seq("A", "B"), byIndexes =
Seq(1, 3), asc = Some(false)),
+ usr(text = "A", id = "A"),
+ nlp(text = ",", isStop = true),
+ usr(text = "B", id = "B"),
+ nlp(text = "top down", isStop = true)
+ ),
+ _ => checkExists(
+ "organize by A, B from bottom up order",
+ srt(text = "organize by", byNotes = Seq("A", "B"), byIndexes =
Seq(1, 3), asc = Some(true)),
+ usr(text = "A", id = "A"),
+ nlp(text = ",", isStop = true),
+ usr(text = "B", id = "B"),
+ nlp(text = "from bottom up order", isStop = true)
+ ),
+ _ => checkExists(
+ "organize by A, B the descending",
+ srt(text = "organize by", byNotes = Seq("A", "B"), byIndexes =
Seq(1, 3), asc = Some(false)),
+ usr(text = "A", id = "A"),
+ nlp(text = ",", isStop = true),
+ usr(text = "B", id = "B"),
+ nlp(text = "the descending", isStop = true)
+ ),
+ _ => checkExists(
+ "organize by A, B, asc",
+ srt(text = "organize by", byNotes = Seq("A", "B"), byIndexes =
Seq(1, 3), asc = Some(true)),
+ usr(text = "A", id = "A"),
+ nlp(text = ",", isStop = true),
+ usr(text = "B", id = "B"),
+ nlp(text = ", asc", isStop = true)
+ ),
+ _ => checkExists(
+ "sort A the A the A",
+ srt(text = "sort", typ = SUBJ_ONLY, note = "wrapperA", index =
1),
+ usr("A the A the A", "wrapperA")
+ )
)
}