This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/master by this push:
new 31d9db35 DialogFlow bugfixes.
31d9db35 is described below
commit 31d9db354516dee3e4f59455eeb918c82069cbc7
Author: Sergey Kamov <[email protected]>
AuthorDate: Thu Apr 7 20:42:17 2022 +0300
DialogFlow bugfixes.
---
.../internal/dialogflow/NCDialogFlowManager.scala | 6 +++++-
.../internal/conversation/NCConversationSpec.scala | 25 ++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
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 112c01af..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
@@ -75,3 +75,28 @@ class NCConversationSpec:
// 'e1' received from conversation.
execOk("e2")
}
+
+ @Test
+ def testClearEmptyData(): Unit =
+ val mdl: NCModel =
+ new NCTestModelAdapter:
+ import NCSemanticTestElement as TE
+ override val getPipeline: NCPipeline =
+ val pl = mkEnPipeline
+
pl.getEntityParsers.add(NCTestUtils.mkEnSemanticParser(TE("e1")))
+ pl
+
+ @NCIntent("intent=i1 term(t1)~{# == 'e1'}")
+ def onMatch(im: NCIntentMatch): NCResult =
+ val conv = im.getContext.getConversation
+ conv.clearStm(_ => true)
+ conv.clearDialog(_ => true)
+ new NCResult()
+
+ 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")
+ }