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 b4dc0edf Minor fixes.
b4dc0edf is described below

commit b4dc0edf93280cd181a90173ef166c47e2d03ca9
Author: Sergey Kamov <[email protected]>
AuthorDate: Mon May 2 23:16:03 2022 +0300

    Minor fixes.
---
 .../nlpcraft/examples/pizzeria/PizzeriaModel.scala | 65 +++++++++++-----------
 .../nlpcraft/examples/pizzeria/PizzeriaOrder.scala | 12 +++-
 .../examples/pizzeria/PizzeriaOrderState.scala     | 24 --------
 .../examples/pizzeria/PizzeriaModelSpec.scala      |  8 +--
 4 files changed, 44 insertions(+), 65 deletions(-)

diff --git 
a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
 
b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
index dcf35362..2d157cb9 100644
--- 
a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
+++ 
b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
@@ -68,16 +68,16 @@ class PizzeriaModel extends NCModelAdapter(new 
NCModelConfig("nlpcraft.pizzeria.
         val o = getOrder(im.getContext)
 
         logger.info(s"Intent '${im.getIntentId}' activated for text: 
'${im.getContext.getRequest.getText}'.")
-        logger.info(s"Before call [desc=${o.getState.toString}, resState: 
${o.getDesc}.")
+        logger.info(s"Before call [desc=${o.getState.toString}, resState: 
${o.getDescription}.")
 
         val (res, resState) = body.apply(o)
         o.setState(resState)
 
-        logger.info(s"After call  [desc=${o.getDesc}, resState: $resState.")
+        logger.info(s"After call  [desc=${o.getDescription}, resState: 
$resState.")
 
         res
 
-    private def askIsReady(o: Order): ResultState = NCResult(s"Is order 
ready?", ASK_DIALOG) -> DIALOG_IS_READY
+    private def askIsReady(): ResultState = NCResult(s"Is order ready?", 
ASK_DIALOG) -> DIALOG_IS_READY
 
     private def askSpecify(o: Order): ResultState =
         require(!o.isValid)
@@ -89,23 +89,23 @@ class PizzeriaModel extends NCModelAdapter(new 
NCModelConfig("nlpcraft.pizzeria.
                 require(o.isEmpty)
                 NCResult(s"Please order something. Ask `menu` to look what you 
can order.", ASK_DIALOG) -> DIALOG_SPECIFY
 
-    private def askShouldStop(o: Order): ResultState =
+    private def askShouldStop(): ResultState =
         NCResult(s"Should current order be canceled?", ASK_DIALOG) -> 
DIALOG_SHOULD_CANCEL
 
-    private def doShowMenu(newState: State): ResultState =
+    private def doShowMenu(): NCResult =
         NCResult(
             "There are accessible for order: margherita, carbonara and 
marinara. Sizes: large, medium or small. " +
             "Also there are tea, coffee and cola.",
             ASK_RESULT
-        ) -> newState
+        )
 
-    private def doShowStatus(o: Order): NCResult = NCResult(s"Current order 
state: ${o.getDesc}.", ASK_RESULT)
+    private def doShowStatus(o: Order): NCResult = NCResult(s"Current order 
state: ${o.getDescription}.", ASK_RESULT)
 
     private def askConfirm(o: Order): ResultState =
         require(o.isValid)
-        NCResult(s"Let's specify your order: ${o.getDesc}. Is it correct?", 
ASK_DIALOG) -> DIALOG_CONFIRM
+        NCResult(s"Let's specify your order: ${o.getDescription}. Is it 
correct?", ASK_DIALOG) -> DIALOG_CONFIRM
 
-    private def withClear(res: NCResult, newState: State, im: NCIntentMatch, 
o: Order): ResultState =
+    private def withClear(res: NCResult, newState: State, im: NCIntentMatch): 
ResultState =
         val ctx = im.getContext
         val conv = ctx.getConversation
         conv.getData.remove(ctx.getRequest.getUserId)
@@ -116,20 +116,24 @@ class PizzeriaModel extends NCModelAdapter(new 
NCModelConfig("nlpcraft.pizzeria.
     // Access level set for tests reasons.
     private[pizzeria] def doExecute(im: NCIntentMatch, o: Order): ResultState =
         require(o.isValid)
-        withClear(NCResult(s"Executed: ${o.getDesc}.", ASK_RESULT), 
DIALOG_EMPTY, im, o)
+        withClear(NCResult(s"Executed: ${o.getDescription}.", ASK_RESULT), 
DIALOG_EMPTY, im)
 
     private def doStop(im: NCIntentMatch, o: Order): ResultState =
-        val res =
-            if !o.isEmpty then NCResult(s"Everything cancelled. Ask `menu` to 
look what you can order.", ASK_RESULT)
-            else NCResult(s"Nothing to cancel. Ask `menu` to look what you can 
order.", ASK_RESULT)
-
-        withClear(res, DIALOG_EMPTY, im, o)
+        withClear(
+            NCResult(
+                if !o.isEmpty then s"Everything cancelled. Ask `menu` to look 
what you can order."
+                else s"Nothing to cancel. Ask `menu` to look what you can 
order.",
+                ASK_RESULT
+            ),
+            DIALOG_EMPTY,
+            im
+        )
 
-    private def doContinue(o: Order): ResultState = NCResult(s"OK, please 
continue.", ASK_RESULT) -> DIALOG_EMPTY
+    private def doContinue(): ResultState = NCResult(s"OK, please continue.", 
ASK_RESULT) -> DIALOG_EMPTY
     private def askConfirmOrAskSpecify(o: Order): ResultState = if o.isValid 
then askConfirm(o) else askSpecify(o)
-    private def askIsReadyOrAskSpecify(o: Order): ResultState = if o.isValid 
then askIsReady(o) else askSpecify(o)
+    private def askIsReadyOrAskSpecify(o: Order): ResultState = if o.isValid 
then askIsReady() else askSpecify(o)
     private def doExecuteOrAskSpecify(im: NCIntentMatch, o: Order): 
ResultState = if o.isValid then doExecute(im, o) else askSpecify(o)
-    private def askStopOrDoStop(im: NCIntentMatch, o: Order): ResultState = if 
o.isValid then askShouldStop(o) else doStop(im, o)
+    private def askStopOrDoStop(im: NCIntentMatch, o: Order): ResultState = if 
o.isValid then askShouldStop() else doStop(im, o)
 
     /**
       *
@@ -155,7 +159,7 @@ class PizzeriaModel extends NCModelAdapter(new 
NCModelConfig("nlpcraft.pizzeria.
     def onNo(im: NCIntentMatch): NCResult = execute(
         im,
         o => o.getState match
-            case DIALOG_CONFIRM | DIALOG_IS_READY => doContinue(o)
+            case DIALOG_CONFIRM | DIALOG_IS_READY => doContinue()
             case DIALOG_SHOULD_CANCEL => askConfirmOrAskSpecify(o)
             case DIALOG_SPECIFY | DIALOG_EMPTY => throw UNEXPECTED_REQUEST
         )
@@ -201,7 +205,7 @@ class PizzeriaModel extends NCModelAdapter(new 
NCModelConfig("nlpcraft.pizzeria.
       */
     @NCIntent("intent=menu term(menu)={# == 'ord:menu'}")
     // It doesn't depend and doesn't influence on order validity and dialog 
state.
-    def onMenu(im: NCIntentMatch): NCResult = execute(im, o => 
doShowMenu(o.getState))
+    def onMenu(im: NCIntentMatch): NCResult = execute(im, o => doShowMenu() -> 
o.getState)
 
     /**
       *
@@ -211,15 +215,14 @@ class PizzeriaModel extends NCModelAdapter(new 
NCModelConfig("nlpcraft.pizzeria.
       * @return
       */
     @NCIntent("intent=order term(ps)={# == 'ord:pizza'}* term(ds)={# == 
'ord:drink'}*")
-    def onOrder(im: NCIntentMatch, @NCIntentTerm("ps") ps: List[NCEntity], 
@NCIntentTerm("ds") ds: List[NCEntity]): NCResult =
-        execute(
-            im,
-            o =>
-                require(ps.nonEmpty || ds.nonEmpty);
-                // It doesn't depend on order validity and dialog state.
-                o.add(ps.map(extractPizza), ds.map(extractDrink));
-                askIsReadyOrAskSpecify(o)
-        )
+    def onOrder(im: NCIntentMatch, @NCIntentTerm("ps") ps: List[NCEntity], 
@NCIntentTerm("ds") ds: List[NCEntity]): NCResult = execute(
+        im,
+        o =>
+            require(ps.nonEmpty || ds.nonEmpty);
+            // It doesn't depend on order validity and dialog state.
+            o.add(ps.map(extractPizza), ds.map(extractDrink));
+            askIsReadyOrAskSpecify(o)
+    )
 
     /**
       *
@@ -231,9 +234,9 @@ class PizzeriaModel extends NCModelAdapter(new 
NCModelConfig("nlpcraft.pizzeria.
     def onOrderSpecify(im: NCIntentMatch, @NCIntentTerm("size") size: 
NCEntity): NCResult = execute(
         im,
         // If order in progress and has pizza with unknown size, it doesn't 
depend on dialog state.
-        o => if !o.isEmpty && o.setPizzaNoSize(extractPizzaSize(size)) then 
askIsReadyOrAskSpecify(o) else throw UNEXPECTED_REQUEST
+        o => if !o.isEmpty && o.fixPizzaNoSize(extractPizzaSize(size)) then 
askIsReadyOrAskSpecify(o) else throw UNEXPECTED_REQUEST
     )
 
     override def onRejection(im: NCIntentMatch, e: NCRejection): NCResult =
         // TODO: improve logic after 
https://issues.apache.org/jira/browse/NLPCRAFT-495 ticket resolving.
-        if im == null || getOrder(im.getContext).isEmpty then 
doShowMenu(getOrder(im.getContext).getState)._1 else throw e
\ No newline at end of file
+        if im == null || getOrder(im.getContext).isEmpty then doShowMenu() 
else throw e
\ No newline at end of file
diff --git 
a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaOrder.scala
 
b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaOrder.scala
index bed6dc3d..a86dc976 100644
--- 
a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaOrder.scala
+++ 
b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaOrder.scala
@@ -20,7 +20,13 @@ package org.apache.nlpcraft.examples.pizzeria
 import java.util.Objects
 import scala.collection.mutable
 
-object OrderElement:
+/**
+  * Order states.
+  */
+enum PizzeriaOrderState:
+    case DIALOG_EMPTY, DIALOG_IS_READY, DIALOG_SHOULD_CANCEL, DIALOG_SPECIFY, 
DIALOG_CONFIRM
+
+private object OrderElement:
     val DFLT_QTY = 1
 /**
   *
@@ -120,7 +126,7 @@ class PizzeriaOrder:
       *
        * @param size
       */
-    def setPizzaNoSize(size: String): Boolean =
+    def fixPizzaNoSize(size: String): Boolean =
         findPizzaNoSize match
             case Some(p) =>
                 p.size = Option(size)
@@ -142,7 +148,7 @@ class PizzeriaOrder:
       *
       * @return
       */
-    def getDesc: String =
+    def getDescription: String =
         if !isEmpty then
             val ps = if pizzas.nonEmpty then s"pizza: ${pizzas.mkString(", 
")}" else ""
             val ds = if drinks.nonEmpty then s"drinks: ${drinks.mkString(", 
")}" else ""
diff --git 
a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaOrderState.scala
 
b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaOrderState.scala
deleted file mode 100644
index 8823fdbf..00000000
--- 
a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaOrderState.scala
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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
- *
- *      http://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.examples.pizzeria
-
-/**
-  * Order states.
-  */
-enum PizzeriaOrderState:
-    case DIALOG_EMPTY, DIALOG_IS_READY, DIALOG_SHOULD_CANCEL, DIALOG_SPECIFY, 
DIALOG_CONFIRM
diff --git 
a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
 
b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
index d8130d0e..cf1bdab2 100644
--- 
a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
+++ 
b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
@@ -92,7 +92,7 @@ class PizzeriaModelSpec:
                 // Check execution result on last request.
                 if idx == reqs.size - 1 then
                     val lastOrder = mdl.getLastExecutedOrder
-                    def s(o: PizzeriaOrder) = if o == null then null else 
s"Order [state=${o.getState}, desc=${o.getDesc}]"
+                    def s(o: PizzeriaOrder) = if o == null then null else 
s"Order [state=${o.getState}, desc=${o.getDescription}]"
                     val s1 = s(exp)
                     val s2 = s(lastOrder)
                     if s1 != s2 then
@@ -107,12 +107,6 @@ class PizzeriaModelSpec:
 
         testNum += 1
 
-    private def mkOrder(state: PizzeriaOrderState, ps: Seq[Pizza], ds: 
Seq[Drink]): PizzeriaOrder =
-        val o = new PizzeriaOrder
-        o.setState(state)
-        o.add(ps, ds)
-        o
-
     @Test
     def test(): Unit =
         given Conversion[String, (String, NCResultType)] with

Reply via email to