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

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


The following commit(s) were added to refs/heads/NLPCRAFT-520 by this push:
     new 8f6ea823 STM additional test.
8f6ea823 is described below

commit 8f6ea82351111ece2c03309bfd40894f2be7471e
Author: Sergey Kamov <[email protected]>
AuthorDate: Sun Jan 22 10:31:29 2023 +0400

    STM additional test.
---
 .../internal/conversation/NCConversationSpec.scala |  4 +-
 .../conversation/NCConversationSpec2.scala         | 73 ++++++++++++++++++++++
 .../nlp/parsers/NCSemanticTestElement.scala        |  4 +-
 3 files changed, 76 insertions(+), 5 deletions(-)

diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationSpec.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationSpec.scala
index 2d566338..a272bb78 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationSpec.scala
@@ -22,7 +22,7 @@ import org.apache.nlpcraft.annotations.*
 import org.apache.nlpcraft.nlp.parsers.*
 import org.apache.nlpcraft.nlp.util.*
 import org.scalatest.funsuite.AnyFunSuite
-
+import org.apache.nlpcraft.nlp.parsers.NCSemanticTestElement as TE
 import scala.util.Using
 
 /**
@@ -31,8 +31,6 @@ import scala.util.Using
 class NCConversationSpec extends AnyFunSuite:
     private val usrId = "userId"
 
-    import NCSemanticTestElement as TE
-
     /**
       *
       */
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationSpec2.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationSpec2.scala
new file mode 100644
index 00000000..478b4d75
--- /dev/null
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationSpec2.scala
@@ -0,0 +1,73 @@
+/*
+ * 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
+ *
+ *      https://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.internal.conversation
+
+import org.apache.nlpcraft.*
+import org.apache.nlpcraft.annotations.*
+import org.apache.nlpcraft.nlp.parsers.{NCSemanticTestElement as TE, *}
+import org.apache.nlpcraft.nlp.util.*
+import org.scalatest.funsuite.AnyFunSuite
+
+import scala.util.Using
+
+/**
+  *
+  */
+class NCConversationSpec2 extends AnyFunSuite:
+    /**
+      *
+      */
+    test("test") {
+        case class Holder(intentId: String, elements: Set[String])
+        object Holder:
+            def apply(intentId: String, elems: String*): Holder = new 
Holder(intentId, elems.toSet)
+
+        def mkResult(using im: NCIntentMatch)(elems: String*): NCResult = 
NCResult(Holder(im.getIntentId, elems*))
+
+        val mdl: NCModel =
+            new NCTestModelAdapter:
+                override val getPipeline: NCPipeline = mkEnPipeline(
+                    TE("sale"),
+                    TE("best", groups = Set("sale", "buy")),
+                    TE("buy")
+                )
+
+                @NCIntent("intent=salesInfoIntent term~{# == 'sale'}")
+                def saleInfo(using ctx: NCContext, im: NCIntentMatch) = 
mkResult("sale")
+
+                @NCIntent("intent=bestSellerIntent term~{# == 'sale'} term~{# 
== 'best'}")
+                def bestSeller(using ctx: NCContext, im: NCIntentMatch) = 
mkResult("best", "sale")
+
+                @NCIntent("intent=buysInfoIntent term~{# == 'buy'}")
+                def buyInfo(using ctx: NCContext, im: NCIntentMatch) = 
mkResult("buy")
+
+                @NCIntent("intent=bestBuyerIntent term~{# == 'buy'} term~{# == 
'best'}")
+                def bestBuyer(using ctx: NCContext, im: NCIntentMatch) = 
mkResult("best", "buy")
+
+        Using.resource(new NCModelClient(mdl)) { cli =>
+            val dialog = Seq(
+                "Give me the sales data" -> Holder("salesInfoIntent", "sale"),
+                "Who was the best?" -> Holder("bestSellerIntent", "best", 
"sale"),
+                "OK, give me the buy report now." -> 
Holder("buysInfoIntent","buy"),
+                "Who was the best?" -> Holder("bestBuyerIntent", "best", "buy")
+            )
+
+            for ((qry, h) <- dialog)
+                require(h == cli.ask(qry, "usrId").getBody)
+        }
+    }
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/parsers/NCSemanticTestElement.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/parsers/NCSemanticTestElement.scala
index d95ad025..ff6b8788 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/parsers/NCSemanticTestElement.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/parsers/NCSemanticTestElement.scala
@@ -33,11 +33,11 @@ case class NCSemanticTestElement(
     typ: String,
     synonyms: Set[String] = Set.empty,
     values: Map[String, Set[String]] = Map.empty,
-    groups: Seq[String] = Seq.empty,
+    groups: Set[String] = Set.empty,
     props: Map[String, AnyRef] = Map.empty
 ) extends NCSemanticElement:
     override val getType: String = typ
-    override val getGroups: Set[String] = groups.toSet
+    override val getGroups: Set[String] = groups ++ Set(typ)
     override val getValues: Map[String, Set[String]] = values
     override val getSynonyms: Set[String] = synonyms
     override val getProperties: Map[String, Object] = props

Reply via email to