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 5fae8ee9 WIP.
5fae8ee9 is described below
commit 5fae8ee935d211184a9da2bc9784ea9bdecd2cd3
Author: Sergey Kamov <[email protected]>
AuthorDate: Thu Apr 7 15:16:50 2022 +0300
WIP.
---
.../apache/nlpcraft/examples/order/PizzeriaModel.scala | 16 ++++++++--------
.../examples/order/components/ElementExtender.scala | 11 ++++++++---
.../examples/order/components/RequestValidator.scala | 8 +++++---
3 files changed, 21 insertions(+), 14 deletions(-)
diff --git
a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/order/PizzeriaModel.scala
b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/order/PizzeriaModel.scala
index 1f5817f2..8bcd5f29 100644
---
a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/order/PizzeriaModel.scala
+++
b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/order/PizzeriaModel.scala
@@ -195,7 +195,8 @@ class PizzeriaModel extends NCModelAdapter (new
NCModelConfig("nlpcraft.pizzeria
im,
(o: PizzeriaOrder) =>
require(ps.nonEmpty || ds.nonEmpty);
- o.add(ps.map(extractPizza), ds.map(extractDrink)); // It doesn't
depend on order validity and dialog state.
+ // It doesn't depend on order validity and dialog state.
+ o.add(ps.map(extractPizza), ds.map(extractDrink));
askIsReadyOrAskSpecify(o)
)
/**
@@ -207,13 +208,12 @@ class PizzeriaModel extends NCModelAdapter (new
NCModelConfig("nlpcraft.pizzeria
@NCIntent("intent=orderPizzaSize term(size)={# == 'ord:pizza:size'}")
def onOrderPizzaSize(im: NCIntentMatch, @NCIntentTerm("size") size:
NCEntity): NCResult = withLog(
im,
- (o: PizzeriaOrder) => o.getState match
- case DIALOG_SPECIFY =>
- if o.setPizzaNoSize(extractPizzaSize(size)) then
- o.setState(NO_DIALOG);
- askIsReadyOrAskSpecify(o)
- else throw UNEXPECTED_REQUEST
- case DIALOG_CONFIRM | NO_DIALOG | DIALOG_IS_READY |
DIALOG_SHOULD_CANCEL => throw UNEXPECTED_REQUEST
+ (o: PizzeriaOrder) =>
+ // If order in progress and has pizza with unknown size -it
doesn't depend on dialog state.
+ if !o.isEmpty then
+ if o.setPizzaNoSize(extractPizzaSize(size)) then
askIsReadyOrAskSpecify(o) else throw UNEXPECTED_REQUEST
+ else
+ throw UNEXPECTED_REQUEST
)
/**
*
diff --git
a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/order/components/ElementExtender.scala
b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/order/components/ElementExtender.scala
index 6797a742..d4a84201 100644
---
a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/order/components/ElementExtender.scala
+++
b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/order/components/ElementExtender.scala
@@ -32,7 +32,12 @@ import scala.jdk.CollectionConverters.*
case class EntityData(id: String, property: String)
/**
+ * Simple element extender.
+ * For each 'main' element it tries to find extra element. If it cane done
instead of this pair new element created.
+ * This new element has 'main' element ID. Extra element configured property
copied to this new element.
*
+ * Note that for simplified implementation, it doesn't care about words
between pairs elements and pairs,
+ * also it doesn't check correctness of words order.
*/
case class ElementExtender(mainDataSeq: Seq[EntityData], extraData:
EntityData) extends NCEntityMapper:
private def getToks(e: NCEntity): mutable.Seq[NCToken] =
e.getTokens.asScala
@@ -43,7 +48,7 @@ case class ElementExtender(mainDataSeq: Seq[EntityData],
extraData: EntityData)
val main = es.filter(e => mainDataMap.contains(e.getId))
val extra = es.filter(_.getId == extraData.id)
- if main.nonEmpty && main.size == extra.size then
+ if main.nonEmpty && main.size >= extra.size then
var ok = true
val mapped =
for ((e1, e2) <- main.zip(extra) if ok) yield
@@ -59,7 +64,7 @@ case class ElementExtender(mainDataSeq: Seq[EntityData],
extraData: EntityData)
override val getRequestId: String =
req.getRequestId
override val getId: String = mEnt.getId
- es = es --= main
- es = es --= extra
+ es = es --= main.take(mapped.size)
+ es = es --= extra.take(mapped.size)
(es ++ mapped).sortBy(getToks(_).head.getIndex).asJava
else entities
\ No newline at end of file
diff --git
a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/order/components/RequestValidator.scala
b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/order/components/RequestValidator.scala
index ea1534b7..f94e160b 100644
---
a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/order/components/RequestValidator.scala
+++
b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/order/components/RequestValidator.scala
@@ -36,7 +36,9 @@ class RequestValidator extends NCEntityValidator:
val cntNums = count("stanford:number")
val cntSize = count("ord:pizza:size")
- if cntNums != 1 && cntNums > cntPizza + cntDrink then
- throw new NCRejection("Too many unrecognized numerics in the
request.")
+ // Single size - it is order specification request.
if cntSize != 1 && cntSize > cntPizza then
- throw new NCRejection("Too many unrecognized pizza sizes in the
request.")
\ No newline at end of file
+ throw new NCRejection("There are unrecognized pizza sizes in the
request.")
+
+ if cntNums > cntPizza + cntDrink then
+ throw new NCRejection("There are many unrecognized numerics in the
request.")