This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-246
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-246 by this push:
new be46f71 WIP.
be46f71 is described below
commit be46f7144b038721ddc343dcd6aad3c3ea0af259
Author: Sergey Kamov <[email protected]>
AuthorDate: Tue Feb 23 17:56:05 2021 +0300
WIP.
---
.../nlpcraft/probe/mgrs/NCProbeVariants.scala | 14 ++++++++--
.../model/NCEnricherNestedModelSpec2.scala | 32 ++++++++++++++++------
.../model/NCEnricherNestedModelSpec3.scala | 12 ++------
3 files changed, 37 insertions(+), 21 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 16138c6..874ded9 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
@@ -21,9 +21,9 @@ import org.apache.nlpcraft.common.nlp.pos.NCPennTreebank
import org.apache.nlpcraft.common.nlp.{NCNlpSentence, NCNlpSentenceNote,
NCNlpSentenceToken}
import org.apache.nlpcraft.common.{NCE, TOK_META_ALIASES_KEY}
import org.apache.nlpcraft.model.NCVariant
-import org.apache.nlpcraft.model.impl.{NCTokenImpl, NCVariantImpl}
+import org.apache.nlpcraft.model.impl.{NCTokenImpl, NCTokenLogger,
NCVariantImpl}
-import java.io.{Serializable ⇒ JSerializable}
+import java.io.{Serializable => JSerializable}
import java.util
import java.util.Collections.singletonList
import scala.collection.JavaConverters._
@@ -211,7 +211,9 @@ object NCProbeVariants {
if (nlpTokOpt.isEmpty && key.id ==
"nlpcraft:nlp")
nlpTokOpt = find(_ ⇒ true)
- val nlpTok = nlpTokOpt.getOrElse(throw new
NCE(s"Part not found for: $key"))
+ val nlpTok = nlpTokOpt.getOrElse(
+ throw new NCE(s"Part not found for:
$key, token: $tok, lastPhase=$lastPhase")
+ )
NCTokenImpl(mdl, srvReqId, nlpTok)
}
@@ -273,6 +275,12 @@ object NCProbeVariants {
vars = bestVars.sortBy(sortedVars.indexOf)
}
+ for (v ← vars; t ← v.asScala)
+ require(
+ t.getIndex >= 0,
+ s"Invalid token: $t with index: ${t.getIndex},
sentence:\n${NCTokenLogger.prepareTable(v.asScala)}"
+ )
+
vars
}
}
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec2.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec2.scala
index 3872867..5897136 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec2.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec2.scala
@@ -26,9 +26,7 @@ import java.util
/**
* Nested Elements test model.
*/
-class NCNestedTestModel2 extends NCModelAdapter(
- "nlpcraft.nested2.test.mdl", "Nested Data Test Model", "1.0"
-) {
+class NCNestedTestModel21 extends NCModelAdapter("nlpcraft.nested2.test.mdl",
"Nested Test Model", "1.0") {
override def getElements: util.Set[NCElement] =
Set(NCTestElement("e1", "{^^(id == 'nlpcraft:num')^^|*} word"))
@@ -37,17 +35,35 @@ class NCNestedTestModel2 extends NCModelAdapter(
@NCIntent("intent=onNumAndE1 term(t1)={id == 'nlpcraft:num'} term(t1)={id
== 'e1'}")
def onNumAndE1(ctx: NCIntentMatch): NCResult = NCResult.text("OK")
+
+ override def isPermutateSynonyms: Boolean = false
+ override def getJiggleFactor: Int = 0
}
/**
* Nested elements model enricher test.
*/
-@NCTestEnvironment(model = classOf[NCNestedTestModel2], startClient = true)
-class NCEnricherNestedModelSpec2 extends NCTestContext {
+@NCTestEnvironment(model = classOf[NCNestedTestModel21], startClient = true)
+class NCEnricherNestedModelSpec21 extends NCTestContext {
@Test
def test(): Unit = {
- checkIntent("word", "onE1")
- checkIntent("10 word", "onE1")
- checkIntent("10 10 word", "onNumAndE1")
+// checkIntent("word", "onE1")
+// checkIntent("10 word", "onE1")
+ checkIntent("11 12 word", "onNumAndE1")
}
}
+
+/**
+ * Nested Elements test model.
+ */
+class NCNestedTestModel22 extends NCNestedTestModel21 {
+ override def isPermutateSynonyms: Boolean = true
+ override def getJiggleFactor: Int = 4
+}
+
+/**
+ * Nested elements model enricher test.
+ */
+@NCTestEnvironment(model = classOf[NCNestedTestModel22], startClient = true)
+class NCEnricherNestedModelSpec22 extends NCEnricherNestedModelSpec21
+
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec3.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec3.scala
index e1fedca..8fc474b 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec3.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec3.scala
@@ -44,18 +44,10 @@ class NCNestedTestModel3 extends NCModelAdapter(
}
/**
- * Nested elements model enricher test.
+ * It shouldn't be too slow.
*/
@NCTestEnvironment(model = classOf[NCNestedTestModel3], startClient = true)
class NCEnricherNestedModelSpec3 extends NCTestContext {
@Test
- def test(): Unit = {
- println("Started")
-
- val t = System.currentTimeMillis()
-
- checkIntent("a " * 12, "onE2")
-
- println(s"Passed: ${System.currentTimeMillis() - t}")
- }
+ def test(): Unit = checkIntent("a " * 18, "onE2")
}