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 dfa4c35 WIP.
dfa4c35 is described below
commit dfa4c352c5e5fc267fd38bbc7f0745565662d277
Author: Sergey Kamov <[email protected]>
AuthorDate: Fri Apr 1 21:35:13 2022 +0300
WIP.
---
.../src/main/java/org/apache/nlpcraft/examples/order/Order.scala | 9 ++-------
.../java/org/apache/nlpcraft/examples/order/OrderModel.scala | 6 +++---
2 files changed, 5 insertions(+), 10 deletions(-)
diff --git
a/nlpcraft-examples/order/src/main/java/org/apache/nlpcraft/examples/order/Order.scala
b/nlpcraft-examples/order/src/main/java/org/apache/nlpcraft/examples/order/Order.scala
index 769e8ab..e9d4aa9 100644
---
a/nlpcraft-examples/order/src/main/java/org/apache/nlpcraft/examples/order/Order.scala
+++
b/nlpcraft-examples/order/src/main/java/org/apache/nlpcraft/examples/order/Order.scala
@@ -22,11 +22,6 @@ import scala.collection.mutable
private enum PizzaSize:
case SMALL, MEDIUM, LARGE
-private class Pizza(name: String, var sizeOpt: Option[PizzaSize]):
- override def toString: String =
- val sz =
Option.when(sizeOpt.nonEmpty)(sizeOpt.toString.toLowerCase).getOrElse("unknown")
- s"$name $sz size"
-
object Order:
def getPizzaSizeKinds: String =
PizzaSize.values.map(_.toString.toLowerCase).mkString(", ")
def pizza2Str(name: String, size: PizzaSize): String = s"$name
${size.toString.toLowerCase} size"
@@ -43,9 +38,9 @@ class Order:
private val pizza = mutable.LinkedHashMap.empty[String, PizzaSize]
private val drinks = mutable.LinkedHashSet.empty[String]
- def addDrink(drink: String): Unit = drinks += drink
- def addPizza(name: String, size: PizzaSize): Unit = pizza += name -> size
+ def addDrink(name: String): Unit = drinks += name
def addPizza(name: String): Unit = pizza += name -> null
+ def addPizza(name: String, size: PizzaSize): Unit = pizza += name -> size
def inProgress(): Boolean = pizza.nonEmpty || drinks.nonEmpty
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 a8d58bb..1d3e257 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
@@ -40,7 +40,7 @@ class OrderModel extends NCModelAdapter(
private def getOrder(im: NCIntentMatch): Order =
ords.getOrElseUpdate(im.getContext.getRequest.getUserId, new Order)
private def extractPizzaKind(e: NCEntity): String =
e.get[String]("ord:pizza:kind:value")
- private def extractPizzaSize(e: NCEntity): String =
e.get[String]("ord:pizza:size:value")
+ private def extractPizzaSize(e: NCEntity): PizzaSize =
PizzaSize.valueOf(e.get[String]("ord:pizza:size:value").toUpperCase)
private def extractDrink(e: NCEntity): String =
e.get[String]("ord:drink:value")
private def confirmOrSpecify(ord: Order): NCResult =
@@ -114,7 +114,7 @@ class OrderModel extends NCModelAdapter(
case _ =>
val avgPos = getAvgPosition(p)
val nextNeighbour = hsSizes.minBy(p => Math.abs(avgPos -
p.position))
- ord.addPizza(extractPizzaKind(p),
PizzaSize.valueOf(extractPizzaSize(nextNeighbour.entity).toUpperCase))
+ ord.addPizza(extractPizzaKind(p),
extractPizzaSize(nextNeighbour.entity))
hsSizes -= nextNeighbour
})
@@ -137,7 +137,7 @@ class OrderModel extends NCModelAdapter(
val ord = getOrder(im)
require(!ord.isValid())
- val sz = PizzaSize.valueOf(extractPizzaSize(size).toUpperCase)
+ val sz = extractPizzaSize(size)
pizzaOpt match
case Some(pizza) => ord.addPizza(extractPizzaKind(pizza), sz)