This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-283
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-283 by this push:
new ed5718c WIP.
ed5718c is described below
commit ed5718c57de309c9f5e1d216bf1b4635c4d3b993
Author: Sergey Kamov <[email protected]>
AuthorDate: Thu Mar 25 13:49:29 2021 +0300
WIP.
---
.../nlpcraft/model/dialog/NCDialogSpec.scala | 50 +++++++++++++++++++++-
.../compiler/functions/NCIdlFunctionsOther.scala | 16 +++++--
2 files changed, 62 insertions(+), 4 deletions(-)
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCDialogSpec.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCDialogSpec.scala
index 60b234b..1c80b8a 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCDialogSpec.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/dialog/NCDialogSpec.scala
@@ -17,16 +17,27 @@
package org.apache.nlpcraft.model.dialog
-import org.apache.nlpcraft.model.{NCElement, NCIntent, NCModel, NCResult}
+import org.apache.nlpcraft.model.{NCDialogFlowItem, NCElement, NCIntent,
NCModel, NCResult}
import org.apache.nlpcraft.{NCTestContext, NCTestElement, NCTestEnvironment}
import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue}
import org.junit.jupiter.api.Test
import java.util
+import scala.collection.JavaConverters._
/**
* Test model.
*/
+class NCDialogSpecModelFlow {
+ def trueAlways(flow: java.util.List[NCDialogFlowItem]): Boolean = true
+ def falseAlways(flow: java.util.List[NCDialogFlowItem]): Boolean = false
+ def trueAfterOnA7(flow: java.util.List[NCDialogFlowItem]): Boolean =
flow.asScala.exists(_.getIntentId == "onA7")
+ def trueAfterOnA7And8(flow: java.util.List[NCDialogFlowItem]): Boolean = {
+ val seq = flow.asScala
+ seq.exists(_.getIntentId == "onA7") && seq.exists(_.getIntentId ==
"onA8")
+ }
+}
+
class NCDialogSpecModel extends NCModel {
override def getId: String = this.getClass.getSimpleName
override def getName: String = this.getClass.getSimpleName
@@ -46,6 +57,21 @@ class NCDialogSpecModel extends NCModel {
@NCIntent("intent=onA4 flow='onA1 onA1' term~{tok_id() == 'a4'}")
def onA4(): NCResult = NCResult.text("ok")
+
+ @NCIntent("intent=onA5
flow=/org.apache.nlpcraft.model.dialog.NCDialogSpecModelFlow#trueAlways/
term~{tok_id() == 'a5'}")
+ def onA5(): NCResult = NCResult.text("ok")
+
+ @NCIntent("intent=onA6
flow=/org.apache.nlpcraft.model.dialog.NCDialogSpecModelFlow#falseAlways/
term~{tok_id() == 'a6'}")
+ def onA6(): NCResult = NCResult.text("ok")
+
+ @NCIntent("intent=onA7 term~{tok_id() == 'a7'}")
+ def onA7(): NCResult = NCResult.text("ok")
+
+ @NCIntent("intent=onA8
flow=/org.apache.nlpcraft.model.dialog.NCDialogSpecModelFlow#trueAfterOnA7/
term~{tok_id() == 'a8'}")
+ def onA8(): NCResult = NCResult.text("ok")
+
+ @NCIntent("intent=onA8
flow=/org.apache.nlpcraft.model.dialog.NCDialogSpecModelFlow#trueAfterOnA7And8/
term~{tok_id() == 'a9'}")
+ def onA9(): NCResult = NCResult.text("ok")
}
/**
@@ -116,4 +142,26 @@ class NCDialogSpec extends NCTestContext {
"a4" → "onA4",
"a4" → "onA4"
)
+
+ @Test
+ private[dialog] def test4(): Unit = {
+ // Always true.
+ checkIntent("a5", "onA5")
+ checkIntent("a5", "onA5")
+
+ // Always false.
+ require(getClient.ask("a6").isFailed)
+ require(getClient.ask("a6").isFailed)
+ }
+
+ @Test
+ private[dialog] def test5(): Unit =
+ f(
+ "a8" → null,
+ "a9" → null,
+ "a7" → "onA7",
+ "a9" → null,
+ "a8" → "onA8",
+ "a9" → "onA9"
+ )
}
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsOther.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsOther.scala
index 5d1ebc9..6d0dacf 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsOther.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsOther.scala
@@ -53,10 +53,20 @@ class NCIdlFunctionsOther extends NCIdlFunctions {
}
@Test
- def test3(): Unit = {
+ def test3(): Unit =
test(
- s"to_string(list(1, 2, 3)) == list('1', '2', '3')",
+ "to_string(list(1, 2, 3)) == list('1', '2', '3')",
"to_string(3.123) == '3.123'"
)
- }
+
+ @Test
+ def test4(): Unit =
+ test(
+ "true",
+ "true == true",
+ "false == false",
+ "false != true",
+ "true != false"
+ )
+
}