This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-491
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-491 by this push:
new cffdece WIP.
cffdece is described below
commit cffdece12a810213045598b47b0a2bdac1abb93d
Author: Sergey Kamov <[email protected]>
AuthorDate: Fri Apr 1 21:20:46 2022 +0300
WIP.
---
.../nlpcraft/examples/order/OrderModel.scala | 38 ++++++++++++++++------
.../order/src/main/resources/order_model.yaml | 5 +++
2 files changed, 33 insertions(+), 10 deletions(-)
diff --git
a/nlpcraft-examples/order/src/main/java/org/apache/nlpcraft/examples/order/OrderModel.scala
b/nlpcraft-examples/order/src/main/java/org/apache/nlpcraft/examples/order/OrderModel.scala
index 9dad41b..a8d58bb 100644
---
a/nlpcraft-examples/order/src/main/java/org/apache/nlpcraft/examples/order/OrderModel.scala
+++
b/nlpcraft-examples/order/src/main/java/org/apache/nlpcraft/examples/order/OrderModel.scala
@@ -53,20 +53,38 @@ class OrderModel extends NCModelAdapter(
@NCIntent("intent=confirm term(confirm)={has(ent_groups, 'confirm')}")
def onConfirm(im: NCIntentMatch, @NCIntentTerm("confirm") confirm:
NCEntity): NCResult =
val ord = getOrder(im)
+ val dlg = im.getContext.getConversation.getDialogFlow
- if !ord.inProgress() then throw new NCRejection("No orders in
progress.")
-
- if confirm.getId == "ord:confirm:yes" then
- if ord.isValid() then
- println(s"Done: $ord")
- ord.clear()
- NCResult("Congratulations. Your order executed. You can start
make new orders.", ASK_RESULT)
- else
- NCResult(ord.ask2Specify(), ASK_DIALOG)
- else
+ def cancelAll(): NCResult =
ord.clear()
NCResult("Order canceled. We are ready for new orders.",
ASK_RESULT)
+ // 'stop' command.
+ if !dlg.isEmpty && dlg.get(dlg .size() - 1).getIntentMatch.getIntentId
== "ord:stop" then
+ confirm.getId match
+ case "ord:confirm:yes" => cancelAll()
+ case "ord:confirm:no" => confirmOrSpecify(ord)
+ case _ => throw new AssertionError()
+ // 'confirm' command.
+ else
+ if !ord.inProgress() then throw new NCRejection("No orders in
progress.")
+
+ confirm.getId match
+ case "ord:confirm:yes" =>
+ if ord.isValid() then
+ println(s"Done: $ord")
+ ord.clear()
+ NCResult("Congratulations. Your order executed. You
can start make new orders.", ASK_RESULT)
+ else
+ NCResult(ord.ask2Specify(), ASK_DIALOG)
+ case "ord:confirm:no" => cancelAll()
+ case _ => throw new AssertionError()
+
+ @NCIntent("intent=stop term(stop)={# == 'ord:stop'}")
+ def onStop(im: NCIntentMatch, @NCIntentTerm("stop") stop: NCEntity):
NCResult =
+ if getOrder(im).inProgress() then NCResult("Are you sure that you
want to cancel current order?", ASK_DIALOG)
+ else NCResult("Nothing to cancel", ASK_RESULT)
+
@NCIntent(
"intent=order " +
" term(common)={# == 'ord:common'}* " +
diff --git a/nlpcraft-examples/order/src/main/resources/order_model.yaml
b/nlpcraft-examples/order/src/main/resources/order_model.yaml
index 728f875..660601a 100644
--- a/nlpcraft-examples/order/src/main/resources/order_model.yaml
+++ b/nlpcraft-examples/order/src/main/resources/order_model.yaml
@@ -58,3 +58,8 @@ elements:
synonyms:
- "{no|nope|incorrect|wrong}"
- "{you are|*} {not|are not|aren't } {correct|right}"
+
+ - id: "ord:stop"
+ description: "Stop and cancel all."
+ synonyms:
+ - "{stop|cancel} {it|all|everything|*}"
\ No newline at end of file