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

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


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

commit 68b6f3fb3d5745b03435d67d2219ca0265afe72f
Author: Sergey Kamov <[email protected]>
AuthorDate: Tue Mar 29 22:38:11 2022 +0300

    WIP.
---
 .../nlpcraft/internal/impl/NCModelClientImpl.scala |  6 +-
 .../internal/conversation/NCConversationSpec.scala | 69 ++++++++++++++++++++++
 2 files changed, 73 insertions(+), 2 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelClientImpl.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelClientImpl.scala
index 8637096..3ac8100 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelClientImpl.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelClientImpl.scala
@@ -26,7 +26,6 @@ import 
org.apache.nlpcraft.internal.dialogflow.NCDialogFlowManager
 import org.apache.nlpcraft.internal.impl.*
 import org.apache.nlpcraft.internal.intent.matcher.*
 import org.apache.nlpcraft.internal.util.*
-import org.apache.nlpcraft.internal.intent.matcher.NCIntentSolveType.*
 
 import java.util
 import java.util.concurrent.*
@@ -83,6 +82,8 @@ class NCModelClientImpl(mdl: NCModel) extends LazyLogging:
         val convHldr = convMgr.getConversation(userId)
         val allEnts = plData.variants.flatMap(_.getEntities.asScala)
 
+        convHldr.updateEntities()
+
         val conv: NCConversation =
             new NCConversation:
                 override val getData: NCPropertyMap = convHldr.getUserData
@@ -109,7 +110,7 @@ class NCModelClientImpl(mdl: NCModel) extends LazyLogging:
       * @return
       */
     def ask(txt: String, data: JMap[String, AnyRef], usrId: String): NCResult =
-        ask0(txt, data, usrId, REGULAR).swap.toOption.get
+        ask0(txt, data, usrId, NCIntentSolveType.REGULAR).swap.toOption.get
 
     /**
       *
@@ -193,4 +194,5 @@ class NCModelClientImpl(mdl: NCModel) extends LazyLogging:
         convMgr.close()
 
     def getWinnerIntent(txt: String, data: JMap[String, AnyRef], usrId: 
String, saveHistory: Boolean): NCWinnerIntent =
+        import NCIntentSolveType.*
         ask0(txt, data, usrId, if saveHistory then TEST_HISTORY else 
TEST_NO_HISTORY).toOption.get
\ No newline at end of file
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
new file mode 100644
index 0000000..7b23d5c
--- /dev/null
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/conversation/NCConversationSpec.scala
@@ -0,0 +1,69 @@
+/*
+ * 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.nlp.entity.parser.semantic.NCSemanticTestElement
+import org.junit.jupiter.api.Test
+import org.apache.nlpcraft.nlp.util.*
+import org.junit.jupiter.api.Assertions.{assertFalse, assertTrue}
+
+import scala.jdk.CollectionConverters.*
+import scala.util.Using
+
+class NCConversationSpec:
+    private val usrId = "userId"
+
+    @Test
+    def test(): Unit =
+        val mdl: NCModel = new NCModel:
+            import NCSemanticTestElement as TE
+
+            override def getPipeline: NCPipeline = new 
NCPipelineBuilder().withSemantic("en", Seq(TE("e1"), TE("e2")).asJava).build()
+            override def getConfig: NCModelConfig = CFG
+
+            @NCIntent("intent=i1 term(t1)={# == 'e1'} term(t2)={# == 'e2'}?")
+            def onMatch(@NCIntentTerm("t1") t1: NCEntity, @NCIntentTerm("t2") 
t2: Option[NCEntity]): NCResult = new NCResult()
+
+        Using.resource(new NCModelClient(mdl)) { cli =>
+            def execOk(txt: String): Unit = cli.ask(txt, null, usrId)
+            def execReject(txt: String): Unit =
+                try
+                    cli.ask(txt, null, usrId)
+                    require(false)
+                catch
+                    case e: NCRejection => // OK.
+                    case e: Throwable => throw e
+
+            // missed 'e1'
+            execReject("e2")
+            execOk("e1 e2")
+
+            // 'e1' received from conversation.
+            execOk("e2")
+
+            cli.clearStm(usrId)
+            cli.clearDialog(usrId)
+
+            // missed 'e1' again.
+            execReject("e2")
+            execOk("e1 e2")
+
+            // 'e1' received from conversation.
+            execOk("e2")
+        }

Reply via email to