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

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

commit 052e8f5e5e6ad149e8081d5a76e19f59e394e019
Author: Sergey Kamov <skhdlem...@gmail.com>
AuthorDate: Thu Apr 7 20:41:42 2022 +0300

    WIP.
---
 .../internal/dialogflow/NCDialogFlowManager.scala  |  6 +++-
 .../internal/conversation/NCConversationSpec.scala | 39 ++++++----------------
 2 files changed, 16 insertions(+), 29 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/dialogflow/NCDialogFlowManager.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/dialogflow/NCDialogFlowManager.scala
index 20b3f9e2..e93b1fce 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/dialogflow/NCDialogFlowManager.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/dialogflow/NCDialogFlowManager.scala
@@ -194,6 +194,10 @@ class NCDialogFlowManager(cfg: NCModelConfig) extends 
LazyLogging:
       */
     def clear(usrId: String, pred: NCDialogFlowItem => Boolean): Unit =
         flow.synchronized {
-            flow(usrId) = flow(usrId).filterNot(pred)
+            flow.get(usrId) match
+                case Some(fu) =>
+                    fu --= fu.filter(pred)
+                    if fu.isEmpty then flow -= usrId
+                case None => // No-op.
             flow.notifyAll()
         }
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 c7b158c6..6db52f25 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
@@ -76,7 +76,8 @@ class NCConversationSpec:
             execOk("e2")
         }
 
-    def testX(): Unit =
+    @Test
+    def testClearEmptyData(): Unit =
         val mdl: NCModel =
             new NCTestModelAdapter:
                 import NCSemanticTestElement as TE
@@ -87,33 +88,15 @@ class NCConversationSpec:
 
                 @NCIntent("intent=i1 term(t1)~{# == 'e1'}")
                 def onMatch(im: NCIntentMatch): NCResult =
-                    im.getContext.getConversation.clearStm()
+                    val conv = im.getContext.getConversation
+                    conv.clearStm(_ => true)
+                    conv.clearDialog(_ => true)
                     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")
+        Using.resource(new NCModelClient(mdl)) { client =>
+            client.ask("e1", null, "userId")
+            client.clearDialog("userId1", _ => true)
+            client.clearDialog("userId2")
+            client.clearStm("userId3", _ => true)
+            client.clearStm("user4")
         }

Reply via email to