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 17:59:32 UTC
[incubator-nlpcraft] 03/06: 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 24a169c0e5346c9d9e9c25066a4b11d85cffa5ff
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Wed Apr 14 13:15:35 2021 +0300
WIP.
---
.../mgrs/nlp/enrichers/model/NCModelEnricher.scala | 22 +++++-----
.../model/NCEnricherNestedModelSpec.scala | 48 +++++++++++-----------
2 files changed, 34 insertions(+), 36 deletions(-)
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 29ec156..8ca93f2 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
@@ -36,7 +36,6 @@ import scala.collection.convert.DecorateAsScala
import scala.collection.mutable.ArrayBuffer
import scala.collection.{Map, Seq, mutable}
-
/**
* Model elements enricher.
*/
@@ -501,10 +500,7 @@ object NCModelEnricher extends NCProbeEnricher with DecorateAsScala {
mdl.elements.keys.map(k ⇒ k → mutable.ArrayBuffer.empty[Seq[Int]])
lazy val idlCache = mutable.HashSet.empty[Seq[Complex]]
- var found = false
-
def add(typ: String, elm: NCElement, res: Seq[NlpToken], allToksIdxs: Seq[Int], s: Synonym, parts: Seq[TokType] = Seq.empty): Unit = {
- found = true
val resIdxs = res.map(_.index)
val continuous = U.isContinuous(resIdxs.sorted)
@@ -555,7 +551,7 @@ object NCModelEnricher extends NCProbeEnricher with DecorateAsScala {
case _ ⇒ false
}
- found = false
+ var found = false
// 1.1 Continuous.
if (simpleEnabled)
@@ -563,14 +559,18 @@ object NCModelEnricher extends NCProbeEnricher with DecorateAsScala {
case Some(h) ⇒
def tryMap(syns: Map[String, Synonym], notFound: () ⇒ Unit): Unit =
syns.get(tokStems) match {
- case Some(s) ⇒ add("simple continuous", elm, toks, tokIdxs, s)
+ case Some(s) ⇒
+ found = true
+ add("simple continuous", elm, toks, tokIdxs, s)
case None ⇒ notFound()
}
def tryScan(syns: Seq[Synonym]): Unit =
for (s ← syns if !found)
- if (s.isMatch(toks))
+ if (s.isMatch(toks)) {
+ found = true
add("simple continuous scan", elm, toks, tokIdxs, s)
+ }
tryMap(
h.txtDirectSynonyms,
@@ -585,8 +585,8 @@ object NCModelEnricher extends NCProbeEnricher with DecorateAsScala {
}
// 1.2 Sparse.
- if (simpleEnabled && !found)
- for (s ← get(mdl.sparseSynonyms, elemId) if !found)
+ if (simpleEnabled)
+ for (s ← get(mdl.sparseSynonyms, elemId))
s.sparseMatch(toks) match {
case Some(res) ⇒ add("simple sparse", elm, res, tokIdxs, s)
case None ⇒ // No-op.
@@ -594,11 +594,9 @@ object NCModelEnricher extends NCProbeEnricher with DecorateAsScala {
// 2. IDL.
if (state != SIMPLE && mdl.hasIdlSynonyms) {
- found = false
-
// 2.1 Sparse.
if (mdl.hasIdlSynonyms)
- for (s ← get(mdl.idlSynonyms, elemId); comb ← idlCombs if !found)
+ for (s ← get(mdl.idlSynonyms, elemId); comb ← idlCombs)
s.idlMatch(comb.map(_.data), req) match {
case Some(res) ⇒
val typ = if (s.sparse) "IDL sparse" else "IDL continuous"
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec.scala
index 00ee50f..91d037b 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec.scala
@@ -79,34 +79,34 @@ class NCEnricherNestedModelSpec2 extends NCEnricherNestedModelSpec1 {
@Test
def test2(): Unit =
runBatch(
-// _ ⇒ checkExists(
-// "test tomorrow",
-// usr(text = "test tomorrow", id = "x3")
-// ),
-// _ ⇒ checkExists(
-// "tomorrow test",
-// usr(text = "tomorrow test", id = "x3")
-// ),
+ _ ⇒ checkExists(
+ "test tomorrow",
+ usr(text = "test tomorrow", id = "x3")
+ ),
+ _ ⇒ checkExists(
+ "tomorrow test",
+ usr(text = "tomorrow test", id = "x3")
+ ),
_ ⇒ checkExists(
"test xxx tomorrow",
usr(text = "test tomorrow", id = "x3"),
nlp(text = "xxx"),
),
-// _ ⇒ checkExists(
-// "y the y",
-// usr(text = "y y", id = "y3"),
-// nlp(text = "the", isStop = true)
-// ),
-// _ ⇒ checkExists(
-// "y xxx y",
-// usr(text = "y y", id = "y3"),
-// nlp(text = "xxx")
-// ),
-// _ ⇒ checkExists(
-// "aaa y xxx y",
-// nlp(text = "aaa"),
-// usr(text = "y y", id = "y3"),
-// nlp(text = "xxx")
-// )
+ _ ⇒ checkExists(
+ "y the y",
+ usr(text = "y y", id = "y3"),
+ nlp(text = "the", isStop = true)
+ ),
+ _ ⇒ checkExists(
+ "y xxx y",
+ usr(text = "y y", id = "y3"),
+ nlp(text = "xxx")
+ ),
+ _ ⇒ checkExists(
+ "aaa y xxx y",
+ nlp(text = "aaa"),
+ usr(text = "y y", id = "y3"),
+ nlp(text = "xxx")
+ )
)
}
\ No newline at end of file