This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-203
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-203 by this push:
new 257f911 WIP.
257f911 is described below
commit 257f911bf3eb3529aa6451a363bc81ca6db2ce77
Author: Sergey Kamov <[email protected]>
AuthorDate: Sat Dec 26 15:51:46 2020 +0300
WIP.
---
.../org/apache/nlpcraft/model/NCIntentDslSpec.scala | 20 +++++++++++++++++---
.../org/apache/nlpcraft/model/NCIntentDslSpec2.scala | 10 ++--------
2 files changed, 19 insertions(+), 11 deletions(-)
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec.scala
index 19913b2..9946582 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec.scala
@@ -21,6 +21,7 @@ import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue}
import org.junit.jupiter.api.Test
+import java.util
import scala.language.implicitConversions
/**
@@ -31,12 +32,22 @@ class NCIntentDslSpecModel extends NCModelAdapter(
) {
private implicit def convert(s: String): NCResult = NCResult.text(s)
+ override def getElements: util.Set[NCElement] = util.Collections.singleton(
+ new NCElement {
+ // It overrides city.
+ override def getId: String = "paris"
+ }
+ )
+
// Moscow population filter.
- @NCIntent("intent=bigCity term(city)~{id == 'nlpcraft:city' &&
~nlpcraft:city:citymeta['population'] >= 10381222}")
+ @NCIntent("intent=bigCity term(city)={id == 'nlpcraft:city' &&
~nlpcraft:city:citymeta['population'] >= 10381222}")
private def onBigCity(ctx: NCIntentMatch): NCResult = "OK"
- @NCIntent("intent=otherCity term(city)~{id == 'nlpcraft:city' }")
+ @NCIntent("intent=otherCity term(city)={id == 'nlpcraft:city' }")
private def onOtherCity(ctx: NCIntentMatch): NCResult = "OK"
+
+ @NCIntent("intent=userElement term(x)={id == 'paris' }")
+ private def onUserElement(ctx: NCIntentMatch): NCResult = "OK"
}
/**
@@ -44,7 +55,7 @@ class NCIntentDslSpecModel extends NCModelAdapter(
*/
@NCTestEnvironment(model = classOf[NCIntentDslSpecModel], startClient = true)
class NCIntentDslSpec extends NCTestContext {
- private def check(txt: String, intent: String): Unit = {
+ private def check(txt: String, intent: String): Unit = {
val res = getClient.ask(txt)
assertTrue(res.isOk, s"Checked: $txt")
@@ -57,5 +68,8 @@ class NCIntentDslSpec extends NCTestContext {
@Test
def testOtherCity(): Unit = check("San Francisco", "otherCity")
+
+ @Test
+ def testUserPriority(): Unit = check("Paris", "userElement")
}
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec2.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec2.scala
index b7223a7..b73833f 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec2.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec2.scala
@@ -34,14 +34,9 @@ class NCIntentDslSpecModel2 extends NCModelAdapter(
private implicit def convert(s: String): NCResult = NCResult.text(s)
override def getElements: util.Set[NCElement] =
- Set(
- new NCElement { override def getId: String = "a" },
- new NCElement { override def getId: String = "b" },
- new NCElement { override def getId: String = "c" },
- new NCElement { override def getId: String = "d" },
- new NCElement { override def getId: String = "e" }
+ Set("a", "b", "c", "d", "e").map(id ⇒ new NCElement { override def
getId: String = id }).asJava
- ).asJava
+ private def mk(id: String): NCElement = new NCElement { override def
getId: String = "a" }
// a. Mandatory, List, +, *, ?
@NCIntent("intent=aMandatory term(a)={id == 'a' }")
@@ -59,7 +54,6 @@ class NCIntentDslSpecModel2 extends NCModelAdapter(
@NCIntent("intent=aOptional term(a)={id == 'a' }?")
private def aOptional(ctx: NCIntentMatch): NCResult = "OK"
-
// b. List, +, *, ?
@NCIntent("intent=bList term(b)={id == 'b' }[1,3]")
private def bList(ctx: NCIntentMatch): NCResult = "OK"