This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch NLPCRAFT-520-scaladoc
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-520-scaladoc by this
push:
new ddf49cc8 WIP
ddf49cc8 is described below
commit ddf49cc8d9c8a7c541af267423c17abca421ee18
Author: Aaron Radzinski <[email protected]>
AuthorDate: Sat Jan 14 12:52:56 2023 -0800
WIP
---
build.sbt | 2 +-
nlpcraft-examples/calculator/README.md | 2 +-
.../nlpcraft/examples/time/CalculatorModel.scala | 4 +-
nlpcraft-examples/lightswitch-fr/README.md | 4 +-
.../examples/lightswitch/LightSwitchFrModel.scala | 2 +-
nlpcraft-examples/lightswitch-ru/README.md | 4 +-
.../examples/lightswitch/LightSwitchRuModel.scala | 2 +-
.../examples/lightswitch/LightSwitchModel.scala | 2 +-
nlpcraft-examples/pizzeria/README.md | 5 +-
.../nlpcraft/examples/pizzeria/PizzeriaModel.scala | 75 +++++-----------------
.../nlpcraft/examples/pizzeria/PizzeriaOrder.scala | 34 +---------
.../components/PizzeriaModelPipeline.scala | 14 ++--
.../pizzeria/components/PizzeriaOrderMapper.scala | 23 +++----
.../components/PizzeriaOrderValidator.scala | 7 +-
.../examples/pizzeria/PizzeriaModelSpec.scala | 4 +-
.../nlp/stanford/NCStanfordNLPEntityParser.scala | 14 ++--
.../nlp/stanford/NCStanfordNLPTokenParser.scala | 4 +-
17 files changed, 63 insertions(+), 139 deletions(-)
diff --git a/build.sbt b/build.sbt
index 182413fa..2b37b0fc 100644
--- a/build.sbt
+++ b/build.sbt
@@ -75,7 +75,7 @@ lazy val libs = Seq(
val commonScalaDoc = Seq(
"-skip-by-regex:org.apache.nlpcraft.internal",
"-skip-by-regex:org.apache.nlpcraft.nlp.enrichers.tools",
- "-project-footer", "Apache, NLPCraft",
+ "-project-footer", "Apache NLPCraft",
"-project-version", nlpcraftVer,
"-siteroot", ".",
"-doc-root-content", "scaladoc/docroot.md",
diff --git a/nlpcraft-examples/calculator/README.md
b/nlpcraft-examples/calculator/README.md
index d42c4c20..13565181 100644
--- a/nlpcraft-examples/calculator/README.md
+++ b/nlpcraft-examples/calculator/README.md
@@ -24,7 +24,7 @@
### Calculator Example
This example data model represents simple calculator. It supports '+', '-',
'*' and '/' operations for two integer arguments.
-Note that first argument can be omitted and last operation result is used
instead of it.
+Note that first argument can be omitted and last operation result will be used
instead.
### Documentation
See [Getting Started](https://nlpcraft.apache.org/getting-started.html) guide
for more instructions on how to run these examples.
diff --git
a/nlpcraft-examples/calculator/src/main/scala/org/apache/nlpcraft/examples/time/CalculatorModel.scala
b/nlpcraft-examples/calculator/src/main/scala/org/apache/nlpcraft/examples/time/CalculatorModel.scala
index f998c495..95cc4c7f 100644
---
a/nlpcraft-examples/calculator/src/main/scala/org/apache/nlpcraft/examples/time/CalculatorModel.scala
+++
b/nlpcraft-examples/calculator/src/main/scala/org/apache/nlpcraft/examples/time/CalculatorModel.scala
@@ -48,11 +48,11 @@ private object CalculatorModel:
import CalculatorModel.*
/**
- * This example provides very simple implementation for NLI-powered
calculator with memory of last operation result function.
+ * This example provides a simple implementation for NLI-powered calculator
that remembers the last operation result.
*
* Supported operations are: `+`, `-`, `*` and `/`.
* Operands values can be given as digits or in text.
- * When first operand is omitted than last operation result is used instead
of first.
+ * When first operand is omitted than last operation result is used instead.
*
* You can ask something like this:
* - User input: *2 + 2*. Expected result is **4**.
diff --git a/nlpcraft-examples/lightswitch-fr/README.md
b/nlpcraft-examples/lightswitch-fr/README.md
index 6c67f85d..ea1747a8 100644
--- a/nlpcraft-examples/lightswitch-fr/README.md
+++ b/nlpcraft-examples/lightswitch-fr/README.md
@@ -23,8 +23,8 @@
[](https://nlpcraft.apache.org/docs.html)
### Light Switch Example
-This example provides very simple implementation for NLI-powered light switch.
You can say something like `turn the lights off in
-the entire house` or `switch on the illumination in the master bedroom
closet`.
+This example provides a simple implementation for NLI-powered light switch for
French language. You can say something
+like `Éteignez les lumières dans toute la maison` or `S'il vous plait,
éteignez la lumière dans la chambre à l'étage`.
You can easily modify intent callbacks to perform the actual light switching
using HomeKit or Arduino-based
controllers.
diff --git
a/nlpcraft-examples/lightswitch-fr/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchFrModel.scala
b/nlpcraft-examples/lightswitch-fr/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchFrModel.scala
index 8cd4b29f..1b0dd5f3 100644
---
a/nlpcraft-examples/lightswitch-fr/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchFrModel.scala
+++
b/nlpcraft-examples/lightswitch-fr/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchFrModel.scala
@@ -26,7 +26,7 @@ import
org.apache.nlpcraft.examples.lightswitch.nlp.token.parser.NCFrTokenParser
import scala.jdk.CollectionConverters.*
/**
- * This example provides very simple implementation for NLI-powered light
switch.
+ * This example provides a simple implementation for NLI-powered light switch
for French language.
*
* You can say something like this:
* - Éteignez les lumières dans toute la maison.
diff --git a/nlpcraft-examples/lightswitch-ru/README.md
b/nlpcraft-examples/lightswitch-ru/README.md
index 6c67f85d..20fb9b8d 100644
--- a/nlpcraft-examples/lightswitch-ru/README.md
+++ b/nlpcraft-examples/lightswitch-ru/README.md
@@ -23,8 +23,8 @@
[](https://nlpcraft.apache.org/docs.html)
### Light Switch Example
-This example provides very simple implementation for NLI-powered light switch.
You can say something like `turn the lights off in
-the entire house` or `switch on the illumination in the master bedroom
closet`.
+This example provides a simple implementation for NLI-powered light switch for
Russian language. You can say something like
+`Выключи свет по всем доме` or `Свет на кухне, пожалуйста, приглуши`.
You can easily modify intent callbacks to perform the actual light switching
using HomeKit or Arduino-based
controllers.
diff --git
a/nlpcraft-examples/lightswitch-ru/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchRuModel.scala
b/nlpcraft-examples/lightswitch-ru/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchRuModel.scala
index efa272b1..a486b23f 100644
---
a/nlpcraft-examples/lightswitch-ru/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchRuModel.scala
+++
b/nlpcraft-examples/lightswitch-ru/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchRuModel.scala
@@ -28,7 +28,7 @@ import
org.apache.nlpcraft.examples.lightswitch.nlp.token.parser.NCRuTokenParser
import scala.jdk.CollectionConverters.*
/**
- * This example provides very simple implementation for NLI-powered light
switch.
+ * This example provides a simple implementation for NLI-powered light switch
for Russian language.
*
* You can say something like this:
* - Выключи свет по всем домe.
diff --git
a/nlpcraft-examples/lightswitch/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala
b/nlpcraft-examples/lightswitch/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala
index 853fdee2..1b3ad955 100644
---
a/nlpcraft-examples/lightswitch/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala
+++
b/nlpcraft-examples/lightswitch/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala
@@ -25,7 +25,7 @@ import
org.apache.nlpcraft.nlp.enrichers.NCEnStopWordsTokenEnricher
import org.apache.nlpcraft.nlp.parsers.{NCOpenNLPTokenParser,
NCSemanticEntityParser}
/**
- * This example provides very simple implementation for NLI-powered light
switch.
+ * This example provides a simple implementation for NLI-powered light switch.
*
* You can say something like this:
* - Turn the lights off in the entire house.
diff --git a/nlpcraft-examples/pizzeria/README.md
b/nlpcraft-examples/pizzeria/README.md
index 10b42416..7d59272b 100644
--- a/nlpcraft-examples/pizzeria/README.md
+++ b/nlpcraft-examples/pizzeria/README.md
@@ -23,9 +23,10 @@
[](https://nlpcraft.apache.org/docs.html)
### Pizzeria Example
-TODO:
+This example provides a simple implementation for NLI-powered pizzeria order
bot.
+
### Documentation
-TODO:
+See [Getting Started](https://nlpcraft.apache.org/getting-started.html) guide
for more instructions on how to run these examples.
For any questions, feedback or suggestions:
diff --git
a/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
b/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
index d45d59f9..f6f9a0c5 100644
---
a/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
+++
b/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
@@ -31,12 +31,10 @@ import org.apache.nlpcraft.nlp.*
* Extractors.
*/
private object PizzeriaExtractors:
+ private def extractQty(e: NCEntity, qty: String): Option[Int] =
Option.when(e.contains(qty))(e[String](qty).toDouble.toInt)
def extractPizzaSize(e: NCEntity): String =
e[String]("ord:pizza:size:value")
- def extractQty(e: NCEntity, qty: String): Option[Int] =
Option.when(e.contains(qty))(e[String](qty).toDouble.toInt)
- def extractPizza(e: NCEntity): Pizza =
- Pizza(e[String]("ord:pizza:value"), e.get[String]("ord:pizza:size"),
extractQty(e, "ord:pizza:qty"))
- def extractDrink(e: NCEntity): Drink =
- Drink(e[String]("ord:drink:value"), extractQty(e, "ord:drink:qty"))
+ def extractPizza(e: NCEntity): Pizza = Pizza(e[String]("ord:pizza:value"),
e.get[String]("ord:pizza:size"), extractQty(e, "ord:pizza:qty"))
+ def extractDrink(e: NCEntity): Drink = Drink(e[String]("ord:drink:value"),
extractQty(e, "ord:drink:qty"))
import PizzeriaExtractors.*
@@ -59,25 +57,17 @@ private object PizzeriaModel extends LazyLogging:
private def mkResult(msg: String): NCResult = NCResult(msg, ASK_RESULT)
private def mkDialog(msg: String): NCResult = NCResult(msg, ASK_DIALOG)
-
private def doRequest(body: Order => Result)(using ctx: NCContext, im:
NCIntentMatch): NCResult =
val o = getCurrentOrder()
-
logger.info(s"Intent '${im.getIntentId}' activated for text:
'${ctx.getRequest.getText}'.")
logger.info(s"Before call [desc=${o.getState.toString}, resState: $o.")
-
val (res, resState) = body.apply(o)
o.setState(resState)
-
logger.info(s"After call [desc=$o, resState: $resState.")
-
res
-
private def askIsReady(): Result = mkDialog("Is order ready?") ->
DIALOG_IS_READY
-
private def askSpecify(o: Order): Result =
require(!o.isValid)
-
o.findPizzaWithoutSize match
case Some(p) =>
mkDialog(s"Choose size (large, medium or small) for:
'${p.name}'") -> DIALOG_SPECIFY
@@ -86,33 +76,26 @@ private object PizzeriaModel extends LazyLogging:
mkDialog("Please order something. Ask `menu` to look what you
can order.") -> DIALOG_SPECIFY
private def askShouldStop(): Result = mkDialog("Should current order be
canceled?") -> DIALOG_SHOULD_CANCEL
-
private def doShowMenuResult(): NCResult =
mkResult(
"There are accessible for order: margherita, carbonara and
marinara. Sizes: large, medium or small. Also there are tea, coffee and cola."
)
-
private def doShowMenu(state: State): Result = doShowMenuResult() -> state
-
private def doShowStatus(o: Order, state: State): Result =
mkResult(s"Current order state: $o.") -> state
-
private def askConfirm(o: Order): Result =
require(o.isValid)
mkDialog(s"Let's specify your order: $o. Is it correct?") ->
DIALOG_CONFIRM
-
private def doResultWithClear(msg: String)(using ctx: NCContext, im:
NCIntentMatch): Result =
val conv = ctx.getConversation
conv.getData.remove(ctx.getRequest.getUserId)
conv.clearStm(_ => true)
conv.clearDialog(_ => true)
mkResult(msg) -> DIALOG_EMPTY
-
private def doStop(o: Order)(using ctx: NCContext, im: NCIntentMatch):
Result =
doResultWithClear(
if !o.isEmpty then "Everything cancelled. Ask `menu` to look what
you can order."
else "Nothing to cancel. Ask `menu` to look what you can order."
)
-
private def doContinue(): Result = mkResult("OK, please continue.") ->
DIALOG_EMPTY
private def askConfirmOrAskSpecify(o: Order): Result = if o.isValid then
askConfirm(o) else askSpecify(o)
private def askIsReadyOrAskSpecify(o: Order): Result = if o.isValid then
askIsReady() else askSpecify(o)
@@ -121,7 +104,7 @@ private object PizzeriaModel extends LazyLogging:
import org.apache.nlpcraft.examples.pizzeria.PizzeriaModel.*
/**
- * This example provides simple implementation for NLI-powered pizzeria order
bot.
+ * This example provides a simple implementation for NLI-powered pizzeria
order bot.
* This is single user implementation with user order state support.
* Bot can send dialog answers, ask to specify order or confirm order
execution.
*
@@ -147,10 +130,6 @@ class PizzeriaModel extends
NCModel(NCModelConfig("nlpcraft.pizzeria.ex", "Pizze
private def doExecuteOrAskSpecify(o: Order)(using ctx: NCContext, im:
NCIntentMatch): Result = if o.isValid then doExecute(o) else askSpecify(o)
- /**
- *
- * @param im
- */
@NCIntent("intent=yes term(yes)={# == 'ord:yes'}")
def onYes(using ctx: NCContext, im: NCIntentMatch): NCResult = doRequest(
o => o.getState match
@@ -160,10 +139,6 @@ class PizzeriaModel extends
NCModel(NCModelConfig("nlpcraft.pizzeria.ex", "Pizze
case DIALOG_SPECIFY | DIALOG_EMPTY => throw UNEXPECTED_REQUEST
)
- /**
- *
- * @param im
- */
@NCIntent("intent=no term(no)={# == 'ord:no'}")
def onNo(using ctx: NCContext, im: NCIntentMatch): NCResult = doRequest(
o => o.getState match
@@ -171,18 +146,11 @@ class PizzeriaModel extends
NCModel(NCModelConfig("nlpcraft.pizzeria.ex", "Pizze
case DIALOG_SHOULD_CANCEL => askConfirmOrAskSpecify(o)
case DIALOG_SPECIFY | DIALOG_EMPTY => throw UNEXPECTED_REQUEST
)
- /**
- *
- * @param im
- */
+
@NCIntent("intent=stop term(stop)={# == 'ord:stop'}")
// It doesn't depend on order validity and dialog state.
def onStop(using ctx: NCContext, im: NCIntentMatch): NCResult =
doRequest(askStopOrDoStop)
- /**
- *
- * @param im
- */
@NCIntent("intent=status term(status)={# == 'ord:status'}")
def onStatus(using ctx: NCContext, im: NCIntentMatch): NCResult =
doRequest(
o => o.getState match
@@ -190,10 +158,7 @@ class PizzeriaModel extends
NCModel(NCModelConfig("nlpcraft.pizzeria.ex", "Pizze
case DIALOG_SHOULD_CANCEL => doShowStatus(o, DIALOG_EMPTY) //
Changes state.
case DIALOG_EMPTY | DIALOG_IS_READY | DIALOG_SPECIFY =>
doShowStatus(o, o.getState) // Keeps same state.
)
- /**
- *
- * @param im
- */
+
@NCIntent("intent=finish term(finish)={# == 'ord:finish'}")
def onFinish(using ctx: NCContext, im: NCIntentMatch): NCResult =
doRequest(
o => o.getState match
@@ -201,36 +166,28 @@ class PizzeriaModel extends
NCModel(NCModelConfig("nlpcraft.pizzeria.ex", "Pizze
case DIALOG_SPECIFY => askSpecify(o) // Ignore `finish`, specify
again.
case DIALOG_EMPTY | DIALOG_IS_READY | DIALOG_SHOULD_CANCEL =>
askConfirmOrAskSpecify(o)
)
- /**
- *
- * @param im
- */
+
@NCIntent("intent=menu term(menu)={# == 'ord:menu'}")
// It doesn't depend and doesn't influence on order validity and dialog
state.
def onMenu(using ctx: NCContext, im: NCIntentMatch): NCResult =
doRequest(o => doShowMenu(o.getState))
- /**
- *
- * @param im
- * @param ps
- * @param ds
- */
@NCIntent("intent=order term(ps)={# == 'ord:pizza'}* term(ds)={# ==
'ord:drink'}*")
- def onOrder(using ctx: NCContext, im: NCIntentMatch, @NCIntentTerm("ps")
ps: List[NCEntity], @NCIntentTerm("ds") ds: List[NCEntity]): NCResult =
doRequest(
- o =>
+ def onOrder(
+ using ctx: NCContext,
+ im: NCIntentMatch,
+ @NCIntentTerm("ps") ps: List[NCEntity],
+ @NCIntentTerm("ds") ds: List[NCEntity]): NCResult = doRequest(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)
)
- /**
- *
- * @param im
- * @param size
- */
@NCIntent("intent=orderSpecify term(size)={# == 'ord:pizza:size'}")
- def onOrderSpecify(using ctx: NCContext, im: NCIntentMatch,
@NCIntentTerm("size") size: NCEntity): NCResult = doRequest(
+ def onOrderSpecify(
+ using ctx: NCContext,
+ im: NCIntentMatch,
+ @NCIntentTerm("size") size: NCEntity): NCResult = doRequest(
// If order in progress and has pizza with unknown size, it doesn't
depend on dialog state.
o => if !o.isEmpty && o.fixPizzaWithoutSize(extractPizzaSize(size))
then askIsReadyOrAskSpecify(o) else throw UNEXPECTED_REQUEST
)
diff --git
a/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaOrder.scala
b/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaOrder.scala
index 1cd14500..2aba94d2 100644
---
a/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaOrder.scala
+++
b/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaOrder.scala
@@ -28,9 +28,7 @@ private [pizzeria] enum PizzeriaOrderState:
private object OrderPosition:
val DFLT_QTY = 1
-/**
- *
- */
+
private trait OrderPosition:
val name: String
var qty: Option[Int]
@@ -65,21 +63,8 @@ private [pizzeria] class PizzeriaOrder:
private val pizzas = mutable.ArrayBuffer.empty[Pizza]
private val drinks = mutable.ArrayBuffer.empty[Drink]
- /**
- *
- */
def isEmpty: Boolean = pizzas.isEmpty && drinks.isEmpty
-
- /**
- *
- */
def isValid: Boolean = !isEmpty && findPizzaWithoutSize.isEmpty
-
- /**
- *
- * @param ps
- * @param ds
- */
def add(ps: Seq[Pizza], ds: Seq[Drink]): Unit =
def setByName[T <: OrderPosition](buf: mutable.ArrayBuffer[T], t: T):
Unit =
buf.find(_.name == t.name) match
@@ -102,32 +87,15 @@ private [pizzeria] class PizzeriaOrder:
for (d <- ds) setByName(drinks, d)
- /**
- *
- */
def findPizzaWithoutSize: Option[Pizza] = pizzas.find(_.size.isEmpty)
-
- /**
- *
- * @param size
- */
def fixPizzaWithoutSize(size: String): Boolean =
findPizzaWithoutSize match
case Some(p) =>
p.size = size.?
true
case None => false
- /**
- *
- */
def getState: PizzeriaOrderState = state
-
- /**
- *
- * @param state
- */
def setState(state: PizzeriaOrderState): Unit = this.state = state
-
override def toString: String =
if !isEmpty then
val ps = if pizzas.nonEmpty then s"pizza: ${pizzas.mkString(",
")}" else ""
diff --git
a/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaModelPipeline.scala
b/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaModelPipeline.scala
index 22fbe676..a8050d0d 100644
---
a/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaModelPipeline.scala
+++
b/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaModelPipeline.scala
@@ -3,10 +3,10 @@ package org.apache.nlpcraft.examples.pizzeria.components
import edu.stanford.nlp.pipeline.StanfordCoreNLP
import org.apache.nlpcraft.nlp.parsers.*
import org.apache.nlpcraft.*
-import org.apache.nlpcraft.nlp.stemmer.{NCEnStemmer, NCStemmer}
+import org.apache.nlpcraft.nlp.stemmer.*
import org.apache.nlpcraft.nlp.enrichers.NCEnStopWordsTokenEnricher
import org.apache.nlpcraft.nlp.parsers.NCSemanticEntityParser
-import org.apache.nlpcraft.nlp.stanford.{NCStanfordNLPEntityParser,
NCStanfordNLPTokenParser}
+import org.apache.nlpcraft.nlp.stanford.*
import java.util.Properties
@@ -29,7 +29,13 @@ private [pizzeria] object PizzeriaModelPipeline:
withTokenEnricher(new NCEnStopWordsTokenEnricher()).
withEntityParser(new NCStanfordNLPEntityParser(stanford,
Set("number"))).
withEntityParser(new NCSemanticEntityParser(new NCEnStemmer,
tokParser, "pizzeria_model.yaml")).
- withEntityMapper(PizzeriaOrderMapper(extra = D("ord:pizza:size",
"ord:pizza:size:value"), dests = D("ord:pizza", "ord:pizza:size"))).
- withEntityMapper(PizzeriaOrderMapper(extra = D("stanford:number",
"stanford:number:nne"), dests = D("ord:pizza", "ord:pizza:qty"), D("ord:drink",
"ord:drink:qty"))).
+ withEntityMapper(PizzeriaOrderMapper(
+ extra = D("ord:pizza:size", "ord:pizza:size:value"),
+ descr = D("ord:pizza", "ord:pizza:size"))
+ ).
+ withEntityMapper(PizzeriaOrderMapper(
+ extra = D("stanford:number", "stanford:number:nne"),
+ descr = D("ord:pizza", "ord:pizza:qty"), D("ord:drink",
"ord:drink:qty"))
+ ).
withEntityValidator(new PizzeriaOrderValidator()).
build
\ No newline at end of file
diff --git
a/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderMapper.scala
b/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderMapper.scala
index 77179afa..dd52711d 100644
---
a/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderMapper.scala
+++
b/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderMapper.scala
@@ -33,7 +33,8 @@ case class PizzeriaOrderMapperDesc(elementType: String,
propertyName: String)
/**
* Element extender.
- * For each 'main' dest element it tries to find related extra element and
convert this pair to new complex element.
+ *
+ * For each 'main' element it tries to find related extra element and convert
this pair to new complex element.
* New element:
* 1. Gets same type as main element, also all main element properties copied
into this new one.
* 2. Gets tokens from both elements.
@@ -44,29 +45,29 @@ case class PizzeriaOrderMapperDesc(elementType: String,
propertyName: String)
*/
private object PizzeriaOrderMapper:
extension(entity: NCEntity)
- def position: Double =
+ private def position: Double =
val toks = entity.getTokens
(toks.head.getIndex + toks.last.getIndex) / 2.0
- def tokens: List[NCToken] = entity.getTokens
+ private def tokens: List[NCToken] = entity.getTokens
private def str(es: Iterable[NCEntity]): String =
es.map(e =>
s"type=${e.getType}(${e.tokens.map(_.getIndex).mkString("[", ",",
"]")})").mkString("{", ", ", "}")
- def apply(extra: PizzeriaOrderMapperDesc, dests:
PizzeriaOrderMapperDesc*): PizzeriaOrderMapper = new PizzeriaOrderMapper(extra,
dests)
+ def apply(extra: PizzeriaOrderMapperDesc, descr:
PizzeriaOrderMapperDesc*): PizzeriaOrderMapper = new PizzeriaOrderMapper(extra,
descr)
import PizzeriaOrderMapper.*
/**
* Custom [[NCEntityMapper]] implementation. It creates new [[NCEntity]]
instances
- * based on `dests` elements extending them by `extra` element property.
- * If `dests` elements or `extra` element are not found or
+ * based on `descr` elements extending them by `extra` element property.
+ * If `descr` elements or `extra` element are not found or
* `dests` and `extra` elements aren't located side by side in user input
* then initial input [[NCEntity]] instances are passed as is.
*
* @param extra Extra data element description.
- * @param dests Base elements descriptions.
+ * @param descr Base elements descriptions.
*/
-case class PizzeriaOrderMapper(extra: PizzeriaOrderMapperDesc, dests:
Seq[PizzeriaOrderMapperDesc]) extends NCEntityMapper with LazyLogging:
+case class PizzeriaOrderMapper(extra: PizzeriaOrderMapperDesc, descr:
Seq[PizzeriaOrderMapperDesc]) extends NCEntityMapper with LazyLogging:
/** @inheritdoc */
override def map(req: NCRequest, cfg: NCModelConfig, ents:
List[NCEntity]): List[NCEntity] =
def map(destEnt: NCEntity, destProp: String, extraEnt: NCEntity):
NCEntity =
@@ -77,8 +78,8 @@ case class PizzeriaOrderMapper(extra:
PizzeriaOrderMapperDesc, dests: Seq[Pizzer
override val getRequestId: String = req.getRequestId
override val getType: String = destEnt.getType
- val destsMap = dests.map(p => p.elementType -> p).toMap
- val destEnts = mutable.HashSet.empty ++ ents.filter(e =>
destsMap.contains(e.getType))
+ val descrMap = descr.map(p => p.elementType -> p).toMap
+ val destEnts = mutable.HashSet.empty ++ ents.filter(e =>
descrMap.contains(e.getType))
val extraEnts = ents.filter(_.getType == extra.elementType)
if destEnts.nonEmpty && extraEnts.nonEmpty && destEnts.size >=
extraEnts.size then
@@ -91,7 +92,7 @@ case class PizzeriaOrderMapper(extra:
PizzeriaOrderMapperDesc, dests: Seq[Pizzer
dest2Extra += destEnt -> extraEnt
val unrelated = ents.filter(e => !used.contains(e))
- val artificial = for ((m, e) <- dest2Extra) yield map(m,
destsMap(m.getType).propertyName, e)
+ val artificial = for ((m, e) <- dest2Extra) yield map(m,
descrMap(m.getType).propertyName, e)
val unused = destEnts
val res = (unrelated ++ artificial ++
unused).sortBy(_.tokens.head.getIndex)
diff --git
a/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderValidator.scala
b/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderValidator.scala
index e42c2e58..c2ad67b6 100644
---
a/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderValidator.scala
+++
b/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderValidator.scala
@@ -34,8 +34,5 @@ class PizzeriaOrderValidator extends NCEntityValidator:
val cntSize = count("ord:pizza:size")
// Single size - it is order specification request.
- if cntSize != 1 && cntSize > cntPizza then
- throw new NCRejection("There are unrecognized pizza sizes in the
request, maybe because some misprints.")
-
- if cntNums > cntPizza + cntDrink then
- throw new NCRejection("There are many unrecognized numerics in the
request, maybe because some misprints.")
\ No newline at end of file
+ if (cntSize != 1 && cntSize > cntPizza) || cntNums > cntPizza +
cntDrink then
+ throw new NCRejection("Invalid pizza request.")
diff --git
a/nlpcraft-examples/pizzeria/src/test/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
b/nlpcraft-examples/pizzeria/src/test/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
index a8f2f719..974c6ae3 100644
---
a/nlpcraft-examples/pizzeria/src/test/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
+++
b/nlpcraft-examples/pizzeria/src/test/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelSpec.scala
@@ -55,7 +55,7 @@ private object PizzeriaModelSpec:
import PizzeriaModelSpec.*
/**
- *
+ * Pizza ordering spec.
*/
class PizzeriaModelSpec extends AnyFunSuite with BeforeAndAfter:
private val mdl = new ModelTestWrapper()
@@ -67,14 +67,12 @@ class PizzeriaModelSpec extends AnyFunSuite with
BeforeAndAfter:
after {
if client != null then client.close()
-
for ((seq, num) <- msgs.zipWithIndex)
println("#" * 150)
for (line <- seq) println(line)
errs.get(num) match
case Some(err) => err.printStackTrace()
case None => // No-op.
-
require(errs.isEmpty, s"There are ${errs.size} errors above.")
}
diff --git
a/nlpcraft-stanford/src/main/scala/org/apache/nlpcraft/nlp/stanford/NCStanfordNLPEntityParser.scala
b/nlpcraft-stanford/src/main/scala/org/apache/nlpcraft/nlp/stanford/NCStanfordNLPEntityParser.scala
index c381ceff..2f8df138 100644
---
a/nlpcraft-stanford/src/main/scala/org/apache/nlpcraft/nlp/stanford/NCStanfordNLPEntityParser.scala
+++
b/nlpcraft-stanford/src/main/scala/org/apache/nlpcraft/nlp/stanford/NCStanfordNLPEntityParser.scala
@@ -26,18 +26,14 @@ import scala.jdk.CollectionConverters.*
/**
* [[https://nlp.stanford.edu/ Stanford NLP]] based language independent
[[NCEntityParser entity parser]] configured by
- * given [[StanfordCoreNLP]] pipeline instance.
+ * given Stanford NLP pipeline instance.
*
- * This parser prepares [[NCEntity]] instances which are detected by prepared
[[StanfordCoreNLP]] pipeline.
- * These entities are created with ID `stanford:modelName`, where `modelName`
is model configured in [[StanfordCoreNLP pipeline]].
+ * This parser creates entities with ID `stanford:modelName`, where
`modelName` is model configured in Stanford NLP pipeline.
* Also this parser copies optional `nne` string and `confidence` double
[[NCPropertyMap metadata]] properties to the
- * created entities extracted from [[StanfordCoreNLP]] annotations.
+ * created entities extracted from Stanford NLP annotations.
- * **NOTE:** this parser can produce different types of [[NCEntity]]
instances and each input [[NCToken]] can be included
- * into several output [[NCEntity]] instances.
- *
- * @param stanford Configured [[StanfordCoreNLP]] pipeline instance.
- * @param supported Supported [[StanfordCoreNLP]] model names. Only supported
models will be used for [[NCEntity]] instances generation.
+ * @param stanford Stanford NLP pipeline instance.
+ * @param supported Supported Stanford NLP model names. Only supported models
will be used for [[NCEntity]] instances generation.
*/
class NCStanfordNLPEntityParser(stanford: StanfordCoreNLP, supported:
Set[String]) extends NCEntityParser:
require(stanford != null, "Stanford instance cannot be null.")
diff --git
a/nlpcraft-stanford/src/main/scala/org/apache/nlpcraft/nlp/stanford/NCStanfordNLPTokenParser.scala
b/nlpcraft-stanford/src/main/scala/org/apache/nlpcraft/nlp/stanford/NCStanfordNLPTokenParser.scala
index d3617dba..ffd84b30 100644
---
a/nlpcraft-stanford/src/main/scala/org/apache/nlpcraft/nlp/stanford/NCStanfordNLPTokenParser.scala
+++
b/nlpcraft-stanford/src/main/scala/org/apache/nlpcraft/nlp/stanford/NCStanfordNLPTokenParser.scala
@@ -28,9 +28,9 @@ import scala.collection.mutable
/**
* [[https://nlp.stanford.edu/ Stanford NLP]] based language independent
[[NCTokenParser entity parser]] configured
- * by given [[StanfordCoreNLP]] pipeline instance.
+ * by given Stanford NLP pipeline instance.
*
- * @param stanford Configured [[StanfordCoreNLP]] pipeline instance.
+ * @param stanford Stanford NLP pipeline instance.
*/
class NCStanfordNLPTokenParser(stanford: StanfordCoreNLP) extends
NCTokenParser:
require(stanford != null, "Stanford instance cannot be null.")