This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-431
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-431 by this push:
new edd357e WIP.
edd357e is described below
commit edd357e0df79d164c49e547f64ae14870135c33d
Author: Sergey Kamov <[email protected]>
AuthorDate: Fri Aug 27 15:09:11 2021 +0300
WIP.
---
.../model/NCEnricherNestedModelSpec6.scala | 50 ++++++++++++++++++----
1 file changed, 41 insertions(+), 9 deletions(-)
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec6.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec6.scala
index b93acdd..ab2b035 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec6.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec6.scala
@@ -17,7 +17,7 @@
package org.apache.nlpcraft.probe.mgrs.nlp.enrichers.model
-import org.apache.nlpcraft.model.{NCElement, NCIntent, NCIntentMatch,
NCModelAdapter, NCResult}
+import org.apache.nlpcraft.model.{NCElement, NCIntent, NCModelAdapter,
NCResult}
import org.apache.nlpcraft.{NCTestContext, NCTestElement, NCTestEnvironment}
import org.junit.jupiter.api.Test
@@ -26,7 +26,9 @@ import java.util.Optional
import scala.jdk.CollectionConverters.SetHasAsJava
class NCNestedTestModel6 extends NCModelAdapter("nlpcraft.nested5.test.mdl",
"Test Model", "1.0") {
- override def getAbstractTokens: util.Set[String] = Set("a", "b",
"any").asJava
+ override def getEnabledBuiltInTokens: util.Set[String] =
Set.empty[String].asJava
+
+ override def getAbstractTokens: util.Set[String] = Set("a1", "b1", "any1",
"a2", "b2", "any2", "a3", "b3").asJava
override def getElements: util.Set[NCElement] =
Set(
@@ -34,19 +36,42 @@ class NCNestedTestModel6 extends
NCModelAdapter("nlpcraft.nested5.test.mdl", "Te
NCTestElement("b1"),
// We have to define any1 as 'not greedy'.
{ val e = NCTestElement("any1", "{//[a-zA-Z0-9]+//}[1, 3]");
e.greedy = Optional.of(false); e },
- NCTestElement("compose1", "^^[a1Ref]{tok_id() == 'a1'}^^
^^[any1Ref]{tok_id() == 'any1'}^^ ^^[b1Ref]{tok_id() == 'b1'}^^"),
+ NCTestElement(
+ "compose1",
+ "^^[a1Ref]{tok_id() == 'a1'}^^ " +
+ "^^[any1Ref]{tok_id() == 'any1'}^^ " +
+ "^^[b1Ref]{tok_id() == 'b1'}^^"
+ ),
NCTestElement("a2"),
NCTestElement("b2"),
- // We don't have to do anything here with greedy flag.
- NCTestElement("compose2", "^^[a2Ref]{tok_id() == 'a2'}^^
{//[a-zA-Z0-9]+//}[1, 3] ^^[b2Ref]{tok_id() == 'b2'}^^"),
+ // We have to define any1 as 'not greedy'.
+ { val e = NCTestElement("any2", "{//[a-zA-Z0-9]+//}[1, 3]");
e.greedy = Optional.of(false); e },
+ NCTestElement(
+ "compose2",
+ "^^[a2Ref]{tok_id() == 'a2'}^^ " +
+ "^^[any2Ref]{tok_id() == 'any2' && tok_is_between_ids('a2',
'b2') == true}^^ " +
+ "^^[b2Ref]{tok_id() == 'b2'}^^"
+ ),
+ NCTestElement("a3"),
+ NCTestElement("b3"),
+ // We don't have to do anything here with greedy flag.
+ NCTestElement(
+ "compose3",
+ "^^[a3Ref]{tok_id() == 'a3'}^^ " +
+ "{//[a-zA-Z0-9]+//}[1, 3] " +
+ "^^[b3Ref]{tok_id() == 'b3'}^^"
+ )
)
- @NCIntent("intent=compose1 term(city)={tok_id() == 'compose1'}")
- private def onCompose1(ctx: NCIntentMatch): NCResult = NCResult.text("OK")
+ @NCIntent("intent=compose1 term(x)={tok_id() == 'compose1'}")
+ private def onCompose1(): NCResult = NCResult.text("OK")
- @NCIntent("intent=compose2 term(city)={tok_id() == 'compose2'}")
- private def onCompose2(ctx: NCIntentMatch): NCResult = NCResult.text("OK")
+ @NCIntent("intent=compose2 term(x)={tok_id() == 'compose2'}")
+ private def onCompose2(): NCResult = NCResult.text("OK")
+
+ @NCIntent("intent=compose3 term(x)={tok_id() == 'compose3'}")
+ private def onCompose3(): NCResult = NCResult.text("OK")
}
/**
*
@@ -66,4 +91,11 @@ class NCEnricherNestedModelSpec6 extends NCTestContext {
checkIntent("a2 t1 t2 b2", "compose2")
checkIntent("a2 t1 b2", "compose2")
}
+
+ @Test
+ def testCompose3(): Unit = {
+ checkIntent("a3 t1 t2 t3 b3", "compose3")
+ checkIntent("a3 t1 t2 b3", "compose3")
+ checkIntent("a3 t1 b3", "compose3")
+ }
}