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 86bccc9c31dcb24cbcfff1783e81cc868fff8803 Author: Sergey Kamov <[email protected]> AuthorDate: Wed Apr 7 12:25:41 2021 +0300 WIP. --- .../mgrs/nlp/enrichers/sort/NCSortEnricher.scala | 21 ++++++++++----------- .../nlpcraft/examples/sql/NCSqlModelSpec.scala | 7 ------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCSortEnricher.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCSortEnricher.scala index 95c123e..4d0b270 100644 --- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCSortEnricher.scala +++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCSortEnricher.scala @@ -188,7 +188,7 @@ object NCSortEnricher extends NCProbeEnricher { * * @param toksNoteData */ - private def split(toks: Seq[NCNlpSentenceToken], toksNoteData: Seq[NoteData], nullable: Boolean): Seq[Seq[NoteData]] = { + private def split(toks: Seq[NCNlpSentenceToken], othersRefs: Seq[NCNlpSentenceToken], toksNoteData: Seq[NoteData], nullable: Boolean): Seq[Seq[NoteData]] = { val res = if (toksNoteData.nonEmpty) { val res = mutable.ArrayBuffer.empty[Seq[NoteData]] @@ -205,8 +205,10 @@ object NCSortEnricher extends NCProbeEnricher { between.isEmpty || between.forall(p ⇒ p.isStopWord || p.stem == stemAnd) } - val minIdx = toks.dropWhile(t ⇒ !isUserNotValue(t)).head.index - val maxIdx = toks.reverse.dropWhile(t ⇒ !isUserNotValue(t)).head.index + val toks2 = toks.filter(othersRefs.contains) + + val minIdx = toks2.dropWhile(t ⇒ !isUserNotValue(t)).head.index + val maxIdx = toks2.reverse.dropWhile(t ⇒ !isUserNotValue(t)).head.index require(minIdx <= maxIdx) @@ -311,12 +313,9 @@ object NCSortEnricher extends NCProbeEnricher { val others = toks.filter(t ⇒ !all.contains(t)) if (others.nonEmpty) { - val i1 = others.head.index - val i2 = others.last.index + val idxs = others.map(_.index).toSet - val othersRefs = others.filter( - t ⇒ t.exists(n ⇒ isUserNotValue(n) && n.tokenIndexes.head >= i1 && n.tokenIndexes.last <= i2) - ) + val othersRefs = others.filter(t ⇒ t.exists(n ⇒ isUserNotValue(n) && n.tokenIndexes.toSet.subsetOf(idxs))) if ( othersRefs.nonEmpty && @@ -348,12 +347,12 @@ object NCSortEnricher extends NCProbeEnricher { if (data1.nonEmpty || data2.nonEmpty) { val seq1 = if (data1.nonEmpty) - split(part1, data1, nullable = false) + split(part1, othersRefs, data1, nullable = false) else - split(part2, data2, nullable = false) + split(part2, othersRefs, data2, nullable = false) val seq2 = if (data1.nonEmpty && data2.nonEmpty) - split(part2, data2, nullable = true) + split(part2, othersRefs, data2, nullable = true) else Seq.empty val asc = orderOpt.flatMap(o ⇒ Some(order(o.synonymIndex)._2)) diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/examples/sql/NCSqlModelSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/examples/sql/NCSqlModelSpec.scala index 3483bd4..55dd983 100644 --- a/nlpcraft/src/test/scala/org/apache/nlpcraft/examples/sql/NCSqlModelSpec.scala +++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/examples/sql/NCSqlModelSpec.scala @@ -107,13 +107,6 @@ class NCSqlModelSpec extends NCEnricherBaseSpec { usr(text = "ship date", id = "col:date"), ), _ ⇒ checkExists( - txt = "give me the orders sorted by ship date", - nlp(text = "give me the", isStop = true), - usr(text = "orders", id = "tbl:orders"), - srt(text = "sorted by", typ = BY_ONLY, note = "col:date", index = 3), - usr(text = "ship date", id = "col:date"), - ), - _ ⇒ checkExists( txt = "give me the orders sorted by ship date asc", nlp(text = "give me the", isStop = true), usr(text = "orders", id = "tbl:orders"),
