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 423a18e8 WIP.
423a18e8 is described below

commit 423a18e880ce6deea3c2e88ab9faed8ddaa9f67e
Author: Sergey Kamov <[email protected]>
AuthorDate: Thu Apr 7 22:34:31 2022 +0300

    WIP.
---
 .../nlpcraft/examples/pizzeria/PizzeriaModel.scala |  8 ++++----
 .../nlpcraft/examples/pizzeria/PizzeriaOrder.scala | 24 ++++++++++------------
 2 files changed, 15 insertions(+), 17 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 6384a52f..f08ad8b2 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
@@ -94,13 +94,13 @@ class PizzeriaModel extends NCModelAdapter (new 
NCModelConfig("nlpcraft.pizzeria
         )
 
     private def doShowStatus(o: PizzeriaOrder, newState: State) =
-        val res = NCResult(s"Current order state: ${o.getDesc}", ASK_RESULT)
+        val res = NCResult(s"Current order state: ${o.getDesc}.", ASK_RESULT)
         o.setState(newState)
         res
 
     private def askConfirm(o: PizzeriaOrder): NCResult =
         require(o.isValid)
-        val res = NCResult(s"Let's specify your order. ${o.getDesc} Is it 
correct?", ASK_DIALOG)
+        val res = NCResult(s"Let's specify your order: ${o.getDesc}. Is it 
correct?", ASK_DIALOG)
         o.setState(DIALOG_CONFIRM)
         res
 
@@ -113,7 +113,7 @@ class PizzeriaModel extends NCModelAdapter (new 
NCModelConfig("nlpcraft.pizzeria
 
     private[pizzeria] def doExecute(im: NCIntentMatch, o: PizzeriaOrder): 
NCResult =
         require(o.isValid)
-        val res = NCResult(s"Executed: ${o.getDesc}", ASK_RESULT)
+        val res = NCResult(s"Executed: ${o.getDesc}.", ASK_RESULT)
         clear(im, o)
         res
 
@@ -232,7 +232,7 @@ class PizzeriaModel extends NCModelAdapter (new 
NCModelConfig("nlpcraft.pizzeria
     def onFinish(im: NCIntentMatch): NCResult = withLog(
         im,
         (o: PizzeriaOrder) => o.getState match
-            case DIALOG_CONFIRM => doExecuteOrAskSpecify(im, o) // Like YES  
if valid.
+            case DIALOG_CONFIRM => doExecuteOrAskSpecify(im, o) // Like YES if 
valid.
             case DIALOG_SPECIFY => askSpecify(o) // Ignore `finish`, specify 
again.
             case NO_DIALOG | DIALOG_IS_READY | DIALOG_SHOULD_CANCEL => 
askConfirmOrAskSpecify(o)
         )
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 3b6a03d9..f7708dbb 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
@@ -17,10 +17,12 @@
 
 package org.apache.nlpcraft.examples.pizzeria
 
-import org.apache.nlpcraft.examples.pizzeria.PizzeriaOrder.DFLT_QTY
-
 import java.util.Objects
 import scala.collection.mutable
+
+object OrderElement:
+    val DFLT_QTY = 1
+
 /**
   *
   */
@@ -35,22 +37,22 @@ private abstract class OrderElement:
   * @param size
   * @param qty
   */
-case class Pizza(name: String, var size: Option[String], var qty: Option[Int]) 
extends OrderElement
+case class Pizza(name: String, var size: Option[String], var qty: Option[Int]) 
extends OrderElement:
+    override def toString = s"$name '${size.getOrElse("undefined size")}' 
${qty.getOrElse(OrderElement.DFLT_QTY)} pcs"
 
 /**
   *
   * @param name
   * @param qty
   */
-case class Drink(name: String, var qty: Option[Int]) extends OrderElement
+case class Drink(name: String, var qty: Option[Int]) extends OrderElement:
+    override def toString = s"$name ${qty.getOrElse(OrderElement.DFLT_QTY)} 
pcs"
 
 enum State:
     case NO_DIALOG, DIALOG_IS_READY, DIALOG_SHOULD_CANCEL, DIALOG_SPECIFY, 
DIALOG_CONFIRM
 
 import org.apache.nlpcraft.examples.pizzeria.State.*
 
-object PizzeriaOrder:
-    private val DFLT_QTY = 1
 class PizzeriaOrder:
     private var state = NO_DIALOG
     private val pizzas = mutable.ArrayBuffer.empty[Pizza]
@@ -140,12 +142,8 @@ class PizzeriaOrder:
       */
     def getDesc: String =
         if !isEmpty then
-            def s(name: String, seq: Iterable[String]): String = if 
seq.nonEmpty then s"$name: ${seq.mkString(", ")}" else ""
-            def p2s(p: Pizza) = s"${p.name}, '${p.size.getOrElse("undefined 
size")}' ${p.qty.getOrElse(DFLT_QTY)} p."
-            def d2s(d: Drink) = s"${d.name}, ${d.qty.getOrElse(DFLT_QTY)} p."
-
-            val s1 = s("Pizza", getPizzas.map(p2s))
-            val s2 = s("Drinks", getDrinks.map(d2s))
+            val ps = if pizzas.nonEmpty then s"Pizza: ${pizzas.mkString(", 
")}" else ""
+            val ds = if drinks.nonEmpty then s"Drinks: ${drinks.mkString(", 
")}" else ""
 
-            if s2.isEmpty then s1 else if s1.isEmpty then s2 else s"$s1 $s2"
+            if ds.isEmpty then ps else if ps.isEmpty then ds else s"$ps, $ds"
         else "Nothing ordered."
\ No newline at end of file

Reply via email to