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
commit 5bc79df39bd7c701664afe2ec583b22e411e61f0 Author: Sergey Kamov <[email protected]> AuthorDate: Sat Feb 19 12:16:43 2022 +0300 Test fixes. --- .../internal/impl/NCModelPingPongSpec.scala | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelPingPongSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelPingPongSpec.scala index e128aab..98658bd 100644 --- a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelPingPongSpec.scala +++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelPingPongSpec.scala @@ -41,25 +41,27 @@ class NCModelPingPongSpec: private val MDL: NCTestModelAdapter = new NCTestModelAdapter(): - // TODO: how to reset it on any request? - var state: String = null - @NCIntent("intent=dialog term(dialog)={# == 'dialog'}") - def onDialog(@NCIntentTerm("dialog") dialog: NCEntity): NCResult = - state = "dialog" - R(ASK_DIALOG, s"Confirm your request 'dialog' request: ${dialog.mkText()}") + def onDialog(im: NCIntentMatch, @NCIntentTerm("dialog") dialog: NCEntity): NCResult = + R(ASK_DIALOG, s"Confirm your request 'dialog'!") @NCIntent("intent=confirm term(confirm)={# == 'confirm'}") - def onConfirm(@NCIntentTerm("confirm") confirm: NCEntity): NCResult = - if state == null || state != "dialog" then throw new NCRejection("Nothing to confirm.") + def onConfirm(im: NCIntentMatch, @NCIntentTerm("confirm") confirm: NCEntity): NCResult = + // TODO: I can compare only with last matched. + val lastIntentId = + im.getContext. + getConversation. + getDialogFlow.asScala.lastOption. + flatMap(p => Option(p.getIntentMatch.getIntentId)).orNull + + if lastIntentId != "dialog" then + throw new NCRejection("Nothing to confirm.") - state = "confirm" - R(ASK_RESULT, s"Confirmed by: ${confirm.mkText()}") + R(ASK_RESULT, s"'dialog' confirmed.") @NCIntent("intent=other term(other)={# == 'other'}") - def onOther(@NCIntentTerm("other") other: NCEntity): NCResult = - state = "other" - R(ASK_RESULT, s"Any by: ${other.mkText()}") + def onOther(im: NCIntentMatch, @NCIntentTerm("other") other: NCEntity): NCResult = + R(ASK_RESULT, s"Some request by: ${other.mkText()}") MDL.getPipeline.getEntityParsers.add( new NCSemanticEntityParser(
