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 eab619dd WIP.
eab619dd is described below
commit eab619ddcca67aea40bd39259784f7ce735d1413
Author: Sergey Kamov <[email protected]>
AuthorDate: Thu Apr 7 19:53:07 2022 +0300
WIP.
---
.../apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala | 6 +++---
.../apache/nlpcraft/examples/pizzeria/PizzeriaOrder.scala | 15 ++++++++++++---
.../nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala | 2 +-
3 files changed, 16 insertions(+), 7 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 faf3e891..ab5a69f9 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
@@ -92,13 +92,13 @@ class PizzeriaModel extends NCModelAdapter (new
NCModelConfig("nlpcraft.pizzeria
)
private def doShowStatus(o: PizzeriaOrder, newState: State) =
- val res = NCResult(s"Current order state: ${o.getDescription}",
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.getDescription} 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
@@ -111,7 +111,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.getDescription}", ASK_RESULT)
+ val res = NCResult(s"Executed: ${o.getDesc}", ASK_RESULT)
clear(im, o)
res
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 0e751b98..81dee08e 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,6 +17,8 @@
package org.apache.nlpcraft.examples.pizzeria
+import org.apache.nlpcraft.examples.pizzeria.PizzeriaOrder.DFLT_QTY
+
import java.util.Objects
import scala.collection.mutable
/**
@@ -132,11 +134,18 @@ class PizzeriaOrder:
*/
def setState(state: State): Unit = this.state = state
- def getDescription: String =
+ /**
+ *
+ * @return
+ */
+ def getDesc: String =
if !isEmpty then
def s(name: String, seq: Iterable[String]): String = if
seq.nonEmpty then s"$name: ${seq.mkString(", ")}" else ""
- val s1 = s("Pizza", getPizzas.map(p => s"${p.name},
'${p.size.getOrElse("undefined size")}'
${p.qty.getOrElse(PizzeriaOrder.DFLT_QTY)} p."))
- val s2 = s("Drinks", getDrinks.map(p => s"${p.name}
${p.qty.getOrElse(PizzeriaOrder.DFLT_QTY)} p."))
+ 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))
if s2.isEmpty then s1 else if s1.isEmpty then s2 else s"$s1 $s2"
else "Nothing ordered."
\ No newline at end of file
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 d899e4cc..09daddd9 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
@@ -90,7 +90,7 @@ class PizzeriaModelSpec:
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.getDescription}]"
+ def s(o: PizzeriaOrder) = if o == null then null else
s"Order [state=${o.getState}, desc=${o.getDesc}]"
val s1 = s(exp)
val s2 = s(lastOrder)
if s1 != s2 then