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/02/16 11:22:29 UTC

[incubator-nlpcraft] branch NLPCRAFT-238 updated: WIP.

This is an automated email from the ASF dual-hosted git repository.

sergeykamov pushed a commit to branch NLPCRAFT-238
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/NLPCRAFT-238 by this push:
     new e45da44  WIP.
e45da44 is described below

commit e45da44e9970af4999520ff5b5ed43a796ac677f
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Tue Feb 16 14:22:16 2021 +0300

    WIP.
---
 .../model/properties/NCTokensPropertiesSpec.scala  | 122 +++++++++++++++++++++
 1 file changed, 122 insertions(+)

diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/properties/NCTokensPropertiesSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/properties/NCTokensPropertiesSpec.scala
new file mode 100644
index 0000000..fe8d57b
--- /dev/null
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/properties/NCTokensPropertiesSpec.scala
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.model.properties
+
+import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
+import org.apache.nlpcraft.model.{NCElement, NCIntent, NCIntentMatch, NCModelAdapter, NCResult}
+import org.junit.jupiter.api.Test
+
+import java.{lang, util}
+import java.util.Optional
+import scala.collection.JavaConverters._
+
+abstract class NCTokenPropertiesAbstractModel extends NCModelAdapter(
+    "nlpcraft.tokens.prop.test.mdl", "Tokens Properties Test Model", "1.0"
+) {
+    override def getElements: util.Set[NCElement] =
+        Map(
+            "ab" → "a b",
+            "xy" → "x y"
+        ).map { case (id, syn) ⇒
+            new NCElement {
+                override def getId: String = id
+                override def getSynonyms: util.List[String] = util.Collections.singletonList(syn)
+            }
+        }.toSet.asJava
+}
+
+// 1. Default model. Default behaviour with default jiggle values and permuted synonyms.
+class NCTokenPropertiesModel1() extends NCTokenPropertiesAbstractModel {
+    @NCIntent("intent=onAB term(t)={id == 'ab'}")
+    def onAB(ctx: NCIntentMatch): NCResult = NCResult.text("OK")
+
+    @NCIntent("intent=onXY term(t)={id == 'xy'}")
+    def onXY(ctx: NCIntentMatch): NCResult = NCResult.text("OK")
+}
+
+@NCTestEnvironment(model = classOf[NCTokenPropertiesModel1], startClient = true)
+class NCTokenPropertiesModel1Spec extends NCTestContext {
+    @Test
+    def test(): Unit = {
+        checkIntent("a b", "onAB")
+        checkIntent("b a", "onAB")
+        checkIntent("x y", "onXY")
+        checkIntent("y x", "onXY")
+    }
+}
+
+// 2. Permutation turned off.
+class NCTokenPropertiesModel2 extends NCTokenPropertiesAbstractModel {
+    override def isPermutateSynonyms: Boolean = false
+    override def getJiggleFactor: Int = 0
+
+    @NCIntent("intent=onAB term(t)={id == 'ab'}")
+    def onAB(ctx: NCIntentMatch): NCResult = NCResult.text("OK")
+
+    @NCIntent("intent=onXY term(t)={id == 'xy'}")
+    def onXY(ctx: NCIntentMatch): NCResult = NCResult.text("OK")
+}
+
+@NCTestEnvironment(model = classOf[NCTokenPropertiesModel2], startClient = true)
+class NCTokenPropertiesModel2Spec extends NCTestContext {
+    @Test
+    def test(): Unit = {
+        checkIntent("a b", "onAB")
+        require(getClient.ask("b a").isFailed)
+
+        checkIntent("x y", "onXY")
+        require(getClient.ask("b a").isFailed)
+        require(getClient.ask("y x").isFailed)
+    }
+}
+
+// 3. Permutation turned off for `ab` but enabled by default for 'xy'
+class NCTokenPropertiesModel3 extends NCTokenPropertiesAbstractModel {
+    override def getElements: util.Set[NCElement] = {
+        Set(
+            new NCElement {
+                override def getId: String = "ab"
+                override def getSynonyms: util.List[String] = util.Collections.singletonList("a b")
+                override def isPermutateSynonyms: Optional[lang.Boolean] = Optional.of(false)
+                override def getJiggleFactor: Optional[Integer] = Optional.of(0)
+            },
+            new NCElement {
+                override def getId: String = "xy"
+                override def getSynonyms: util.List[String] = util.Collections.singletonList("x y")
+            }
+        ).asJava
+    }
+
+    @NCIntent("intent=onAB term(t)={id == 'ab'}")
+    def onAB(ctx: NCIntentMatch): NCResult = NCResult.text("OK")
+
+    @NCIntent("intent=onXY term(t)={id == 'xy'}")
+    def onXY(ctx: NCIntentMatch): NCResult = NCResult.text("OK")
+}
+
+@NCTestEnvironment(model = classOf[NCTokenPropertiesModel3], startClient = true)
+class NCTokenPropertiesModel3Spec extends NCTestContext {
+    @Test
+    def test(): Unit = {
+        checkIntent("a b", "onAB")
+        require(getClient.ask("b a").isFailed)
+
+        checkIntent("x y", "onXY")
+        checkIntent("y x", "onXY")
+    }
+}
\ No newline at end of file