You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by se...@apache.org on 2022/07/07 07:32:25 UTC
[incubator-nlpcraft] 02/02: Example refactoring.
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
commit 41e4569d3bd23a5f71bf99b34604ebfa70a4c3ca
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Thu Jul 7 10:32:13 2022 +0300
Example refactoring.
---
.../nlpcraft/examples/pizzeria/PizzeriaModel.scala | 48 ++++++++++------------
.../examples/pizzeria/PizzeriaModelPipeline.scala | 15 ++++---
.../nlpcraft/examples/pizzeria/PizzeriaOrder.scala | 1 -
.../components/PizzeriaOrderExtender.scala | 28 ++++++-------
.../components/PizzeriaOrderValidator.scala | 9 +---
.../examples/pizzeria/PizzeriaModelSpec.scala | 10 ++---
.../pizzeria/cli/PizzeriaModelServer.scala | 4 +-
.../stanford/NCStanfordNLPEntityParser.scala | 7 ++--
8 files changed, 52 insertions(+), 70 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 5369f1fe..d259b67f 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
@@ -20,15 +20,11 @@ package org.apache.nlpcraft.examples.pizzeria
import com.typesafe.scalalogging.LazyLogging
import org.apache.nlpcraft.*
import org.apache.nlpcraft.NCResultType.*
+import org.apache.nlpcraft.annotations.*
import org.apache.nlpcraft.examples.pizzeria.{PizzeriaOrder as Order, PizzeriaOrderState as State}
import org.apache.nlpcraft.examples.pizzeria.PizzeriaOrderState.*
import org.apache.nlpcraft.nlp.*
-import java.util.Properties
-import scala.collection.mutable
-import scala.jdk.CollectionConverters.*
-import scala.jdk.OptionConverters.*
-
/**
* * Pizza model helper.
*/
@@ -38,7 +34,7 @@ object PizzeriaModel extends LazyLogging:
private def extractPizzaSize(e: NCEntity): String = e.get[String]("ord:pizza:size:value")
private def extractQty(e: NCEntity, qty: String): Option[Int] = Option.when(e.contains(qty))(e.get[String](qty).toDouble.toInt)
private def extractPizza(e: NCEntity): Pizza =
- Pizza(e.get[String]("ord:pizza:value"), e.getOpt[String]("ord:pizza:size").toScala, extractQty(e, "ord:pizza:qty"))
+ Pizza(e.get[String]("ord:pizza:value"), e.getOpt[String]("ord:pizza:size"), extractQty(e, "ord:pizza:qty"))
private def extractDrink(e: NCEntity): Drink =
Drink(e.get[String]("ord:drink:value"), extractQty(e, "ord:drink:qty"))
@@ -56,10 +52,10 @@ 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 im: NCIntentMatch): NCResult =
- val o = getOrder(im.getContext)
+ private def doRequest(body: Order => Result)(using ctx: NCContext, im: NCIntentMatch): NCResult =
+ val o = getOrder(ctx)
- logger.info(s"Intent '${im.getIntentId}' activated for text: '${im.getContext.getRequest.getText}'.")
+ logger.info(s"Intent '${im.getIntentId}' activated for text: '${ctx.getRequest.getText}'.")
logger.info(s"Before call [desc=${o.getState.toString}, resState: ${o.getDescription}.")
val (res, resState) = body.apply(o)
@@ -97,8 +93,7 @@ object PizzeriaModel extends LazyLogging:
require(o.isValid)
mkDialog(s"Let's specify your order: ${o.getDescription}. Is it correct?") -> DIALOG_CONFIRM
- private def doResultWithClear(msg: String)(using im: NCIntentMatch): Result =
- val ctx = im.getContext
+ private def doResultWithClear(msg: String)(using ctx: NCContext, im: NCIntentMatch): Result =
val conv = ctx.getConversation
conv.getData.remove(ctx.getRequest.getUserId)
conv.clearStm(_ => true)
@@ -106,8 +101,7 @@ object PizzeriaModel extends LazyLogging:
mkResult(msg) -> DIALOG_EMPTY
-
- private def doStop(o: Order)(using im: NCIntentMatch): Result =
+ private def doStop(o: Order)(using ctx: NCContext, im: NCIntentMatch): Result =
doResultWithClear(
if !o.isEmpty then s"Everything cancelled. Ask `menu` to look what you can order."
else s"Nothing to cancel. Ask `menu` to look what you can order."
@@ -116,7 +110,7 @@ object PizzeriaModel extends LazyLogging:
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)
- private def askStopOrDoStop(o: Order)(using im: NCIntentMatch): Result = if o.isValid then askShouldStop() else doStop(o)
+ private def askStopOrDoStop(o: Order)(using ctx: NCContext, im: NCIntentMatch): Result = if o.isValid then askShouldStop() else doStop(o)
type Result = (NCResult, State)
@@ -130,11 +124,11 @@ import org.apache.nlpcraft.examples.pizzeria.PizzeriaModel.*
*/
class PizzeriaModel extends NCModelAdapter(new NCModelConfig("nlpcraft.pizzeria.ex", "Pizzeria Example Model", "1.0"), PizzeriaModelPipeline.PIPELINE) with LazyLogging:
// This method is defined in class scope and has package access level for tests reasons.
- private[pizzeria] def doExecute(o: Order)(using im: NCIntentMatch): Result =
+ private[pizzeria] def doExecute(o: Order)(using ctx: NCContext, im: NCIntentMatch): Result =
require(o.isValid)
doResultWithClear(s"Executed: ${o.getDescription}.")
- private def doExecuteOrAskSpecify(o: Order)(using im: NCIntentMatch): Result = if o.isValid then doExecute(o) else askSpecify(o)
+ private def doExecuteOrAskSpecify(o: Order)(using ctx: NCContext, im: NCIntentMatch): Result = if o.isValid then doExecute(o) else askSpecify(o)
/**
*
@@ -142,7 +136,7 @@ class PizzeriaModel extends NCModelAdapter(new NCModelConfig("nlpcraft.pizzeria.
* @return
*/
@NCIntent("intent=yes term(yes)={# == 'ord:yes'}")
- def onYes(using im: NCIntentMatch): NCResult = doRequest(
+ def onYes(using ctx: NCContext, im: NCIntentMatch): NCResult = doRequest(
o => o.getState match
case DIALOG_CONFIRM => doExecute(o)
case DIALOG_SHOULD_CANCEL => doStop(o)
@@ -156,7 +150,7 @@ class PizzeriaModel extends NCModelAdapter(new NCModelConfig("nlpcraft.pizzeria.
* @return
*/
@NCIntent("intent=no term(no)={# == 'ord:no'}")
- def onNo(using im: NCIntentMatch): NCResult = doRequest(
+ def onNo(using ctx: NCContext, im: NCIntentMatch): NCResult = doRequest(
o => o.getState match
case DIALOG_CONFIRM | DIALOG_IS_READY => doContinue()
case DIALOG_SHOULD_CANCEL => askConfirmOrAskSpecify(o)
@@ -169,7 +163,7 @@ class PizzeriaModel extends NCModelAdapter(new NCModelConfig("nlpcraft.pizzeria.
*/
@NCIntent("intent=stop term(stop)={# == 'ord:stop'}")
// It doesn't depend on order validity and dialog state.
- def onStop(using im: NCIntentMatch): NCResult = doRequest(askStopOrDoStop)
+ def onStop(using ctx: NCContext, im: NCIntentMatch): NCResult = doRequest(askStopOrDoStop)
/**
*
@@ -177,7 +171,7 @@ class PizzeriaModel extends NCModelAdapter(new NCModelConfig("nlpcraft.pizzeria.
* @return
*/
@NCIntent("intent=status term(status)={# == 'ord:status'}")
- def onStatus(using im: NCIntentMatch): NCResult = doRequest(
+ def onStatus(using ctx: NCContext, im: NCIntentMatch): NCResult = doRequest(
o => o.getState match
case DIALOG_CONFIRM => askConfirm(o) // Ignore `status`, confirm again.
case DIALOG_SHOULD_CANCEL => doShowStatus(o, DIALOG_EMPTY) // Changes state.
@@ -189,7 +183,7 @@ class PizzeriaModel extends NCModelAdapter(new NCModelConfig("nlpcraft.pizzeria.
* @return
*/
@NCIntent("intent=finish term(finish)={# == 'ord:finish'}")
- def onFinish(using im: NCIntentMatch): NCResult = doRequest(
+ def onFinish(using ctx: NCContext, im: NCIntentMatch): NCResult = doRequest(
o => o.getState match
case DIALOG_CONFIRM => doExecuteOrAskSpecify(o) // Like YES if valid.
case DIALOG_SPECIFY => askSpecify(o) // Ignore `finish`, specify again.
@@ -202,7 +196,7 @@ class PizzeriaModel extends NCModelAdapter(new NCModelConfig("nlpcraft.pizzeria.
*/
@NCIntent("intent=menu term(menu)={# == 'ord:menu'}")
// It doesn't depend and doesn't influence on order validity and dialog state.
- def onMenu(using im: NCIntentMatch): NCResult = doRequest(o => doShowMenu(o.getState))
+ def onMenu(using ctx: NCContext, im: NCIntentMatch): NCResult = doRequest(o => doShowMenu(o.getState))
/**
*
@@ -212,7 +206,7 @@ class PizzeriaModel extends NCModelAdapter(new NCModelConfig("nlpcraft.pizzeria.
* @return
*/
@NCIntent("intent=order term(ps)={# == 'ord:pizza'}* term(ds)={# == 'ord:drink'}*")
- def onOrder(using im: NCIntentMatch, @NCIntentTerm("ps") ps: List[NCEntity], @NCIntentTerm("ds") ds: List[NCEntity]): NCResult = doRequest(
+ 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.
@@ -227,11 +221,11 @@ class PizzeriaModel extends NCModelAdapter(new NCModelConfig("nlpcraft.pizzeria.
* @return
*/
@NCIntent("intent=orderSpecify term(size)={# == 'ord:pizza:size'}")
- def onOrderSpecify(using 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
)
- override def onRejection(im: NCIntentMatch, e: NCRejection): NCResult =
- // TODO: improve logic after https://issues.apache.org/jira/browse/NLPCRAFT-495 ticket resolving.
- if im == null || getOrder(im.getContext).isEmpty then throw e else doShowMenuResult()
\ No newline at end of file
+ override def onRejection(ctx: NCContext, im: Option[NCIntentMatch], e: NCRejection): Option[NCResult] =
+ if im.isEmpty || getOrder(ctx).isEmpty then throw e
+ Option(doShowMenuResult())
\ No newline at end of file
diff --git a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelPipeline.scala b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelPipeline.scala
index 3fb48f62..ca233a4d 100644
--- a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelPipeline.scala
+++ b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/PizzeriaModelPipeline.scala
@@ -1,16 +1,15 @@
package org.apache.nlpcraft.examples.pizzeria
import edu.stanford.nlp.pipeline.StanfordCoreNLP
+import java.util.Properties
import opennlp.tools.stemmer.PorterStemmer
import org.apache.nlpcraft.examples.pizzeria.components.*
import org.apache.nlpcraft.nlp.entity.parser.semantic.*
-import org.apache.nlpcraft.nlp.entity.parser.stanford.NCStanfordNLPEntityParser
import org.apache.nlpcraft.nlp.token.enricher.NCEnStopWordsTokenEnricher
import org.apache.nlpcraft.nlp.token.parser.stanford.NCStanfordNLPTokenParser
import org.apache.nlpcraft.*
+import org.apache.nlpcraft.nlp.entity.parser.stanford.NCStanfordNLPEntityParser
-import scala.jdk.CollectionConverters.*
-import java.util.Properties
/**
* PizzeriaModel pipeline, based on Stanford NLP engine, including model custom components.
@@ -31,13 +30,13 @@ object PizzeriaModelPipeline:
new NCPipelineBuilder().
withTokenParser(tokParser).
withTokenEnricher(new NCEnStopWordsTokenEnricher()).
- withEntityParser(new NCStanfordNLPEntityParser(stanford, "number")).
- withEntityParser(new NCSemanticEntityParser(stemmer, tokParser, "pizzeria_model.yaml")).
+ withEntityParser(new NCStanfordNLPEntityParser(stanford, Set("number"))).
+ withEntityParser(NCSemanticEntityParser(stemmer, tokParser, "pizzeria_model.yaml")).
withEntityMappers(
- Seq(
+ List(
Ex(Seq(D("ord:pizza", "ord:pizza:size")), D("ord:pizza:size", "ord:pizza:size:value")),
Ex(Seq(D("ord:pizza", "ord:pizza:qty"), D("ord:drink", "ord:drink:qty")), D("stanford:number", "stanford:number:nne")),
- ).asJava
+ )
).
withEntityValidator(new PizzeriaOrderValidator()).
- build()
\ No newline at end of file
+ build
\ No newline at end of file
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 c003a2f1..66cc2c06 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,7 +17,6 @@
package org.apache.nlpcraft.examples.pizzeria
-import java.util.Objects
import scala.collection.mutable
/**
diff --git a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderExtender.scala b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderExtender.scala
index 38652c91..2a915ab2 100644
--- a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderExtender.scala
+++ b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderExtender.scala
@@ -19,12 +19,9 @@ package org.apache.nlpcraft.examples.pizzeria.components
import org.apache.nlpcraft.*
-import java.util
-import java.util.List as JList
-import scala.collection.mutable
-import scala.jdk.CollectionConverters.*
import com.typesafe.scalalogging.LazyLogging
import org.apache.nlpcraft.NCResultType.ASK_DIALOG
+import scala.collection.*
/**
*
@@ -47,9 +44,9 @@ case class EntityData(id: String, property: String)
object PizzeriaOrderExtender:
extension(entity: NCEntity)
def position: Double =
- val toks = entity.getTokens.asScala
+ val toks = entity.getTokens
(toks.head.getIndex + toks.last.getIndex) / 2.0
- def tokens: mutable.Seq[NCToken] = entity.getTokens.asScala
+ def tokens: List[NCToken] = entity.getTokens
import PizzeriaOrderExtender.*
@@ -59,19 +56,18 @@ import PizzeriaOrderExtender.*
* @param extraData
*/
case class PizzeriaOrderExtender(mainDataSeq: Seq[EntityData], extraData: EntityData) extends NCEntityMapper with LazyLogging:
- override def map(req: NCRequest, cfg: NCModelConfig, entities: JList[NCEntity]): JList[NCEntity] =
+ override def map(req: NCRequest, cfg: NCModelConfig, entities: List[NCEntity]): List[NCEntity] =
def combine(mainEnt: NCEntity, mainProp: String, extraEnt: NCEntity): NCEntity =
new NCPropertyMapAdapter with NCEntity:
- mainEnt.keysSet().forEach(k => put(k, mainEnt.get(k)))
+ mainEnt.keysSet.foreach(k => put(k, mainEnt.get(k)))
put[String](mainProp, extraEnt.get[String](extraData.property).toLowerCase)
- override val getTokens: JList[NCToken] = (mainEnt.tokens ++ extraEnt.tokens).sortBy(_.getIndex).asJava
+ override val getTokens: List[NCToken] = (mainEnt.tokens ++ extraEnt.tokens).sortBy(_.getIndex)
override val getRequestId: String = req.getRequestId
override val getId: String = mainEnt.getId
- val es = entities.asScala
val mainById = mainDataSeq.map(p => p.id -> p).toMap
- val main = mutable.HashSet.empty ++ es.filter(e => mainById.contains(e.getId))
- val extra = es.filter(_.getId == extraData.id)
+ val main = mutable.HashSet.empty ++ entities.filter(e => mainById.contains(e.getId))
+ val extra = entities.filter(_.getId == extraData.id)
if main.nonEmpty && extra.nonEmpty && main.size >= extra.size then
val used = (main ++ extra).toSet
@@ -82,15 +78,15 @@ case class PizzeriaOrderExtender(mainDataSeq: Seq[EntityData], extraData: Entity
main -= m
main2Extra += m -> e
- val unrelated = es.filter(e => !used.contains(e))
+ val unrelated = entities.filter(e => !used.contains(e))
val artificial = for ((m, e) <- main2Extra) yield combine(m, mainById(m.getId).property, e)
val unused = main
val res = (unrelated ++ artificial ++ unused).sortBy(_.tokens.head.getIndex)
def s(es: Iterable[NCEntity]) =
- es.map(e => s"id=${e.getId}(${e.tokens.map(_.getIndex).mkString("[", ",", "]")})").mkString("{", ", ", "}")
- logger.debug(s"Elements mapped [input=${s(es)}, output=${s(res)}]")
+ entities.map(e => s"id=${e.getId}(${e.tokens.map(_.getIndex).mkString("[", ",", "]")})").mkString("{", ", ", "}")
+ logger.debug(s"Elements mapped [input=${s(entities)}, output=${s(res)}]")
- res.asJava
+ res
else entities
\ No newline at end of file
diff --git a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderValidator.scala b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderValidator.scala
index 1d193cb2..ef11b744 100644
--- a/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderValidator.scala
+++ b/nlpcraft-examples/pizzeria/src/main/java/org/apache/nlpcraft/examples/pizzeria/components/PizzeriaOrderValidator.scala
@@ -19,17 +19,12 @@ package org.apache.nlpcraft.examples.pizzeria.components
import org.apache.nlpcraft.*
-import java.util
-import scala.jdk.CollectionConverters.*
-
/**
* Rejects some invalid variant with more detailed information instead of standard rejections.
*/
class PizzeriaOrderValidator extends NCEntityValidator:
- override def validate(req: NCRequest, cfg: NCModelConfig, ents: util.List[NCEntity]): Unit =
- val es = ents.asScala
-
- def count(id: String): Int = es.count(_.getId == id)
+ override def validate(req: NCRequest, cfg: NCModelConfig, entities: List[NCEntity]): Unit =
+ def count(id: String): Int = entities.count(_.getId == id)
val cntPizza = count("ord:pizza")
val cntDrink = count("ord:drink")
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 123529c5..d0efd41d 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
@@ -32,7 +32,7 @@ object PizzeriaModelSpec:
private class ModelTestWrapper extends PizzeriaModel:
private var o: PizzeriaOrder = _
- override def doExecute(o: PizzeriaOrder)(using im: NCIntentMatch): Result =
+ override def doExecute(o: PizzeriaOrder)(using ctx: NCContext, im: NCIntentMatch): Result =
val res = super.doExecute(o)
this.o = o
res
@@ -84,13 +84,13 @@ class PizzeriaModelSpec:
for (((txt, expType), idx) <- reqs.zipWithIndex)
try
mdl.clearLastExecutedOrder()
- val resp = client.ask(txt, null, "userId")
+ val resp = client.ask(txt, "userId")
testMsgs += s">> Request: $txt"
- testMsgs += s">> Response: '${resp.getType}': ${resp.getBody}"
+ testMsgs += s">> Response: '${resp.resultType}': ${resp.body}"
- if expType != resp.getType then
- errs += testNum -> new Exception(s"Unexpected result type [num=$testNum, txt=$txt, expected=$expType, type=${resp.getType}]")
+ if expType != resp.resultType then
+ errs += testNum -> new Exception(s"Unexpected result type [num=$testNum, txt=$txt, expected=$expType, type=${resp.resultType}]")
// Check execution result on last request.
if idx == reqs.size - 1 then
diff --git a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelServer.scala b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelServer.scala
index aa8fd12a..056d071a 100644
--- a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelServer.scala
+++ b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/pizzeria/cli/PizzeriaModelServer.scala
@@ -64,8 +64,8 @@ object PizzeriaModelServer:
if req == null || req.isEmpty then Exception(s"Empty request.")
val resp = nlpClient.ask(req, null, "userId")
- val prompt = if resp.getType == ASK_DIALOG then "(Your should answer on the model's question below)\n" else ""
- doResponse(s"$prompt${resp.getBody}")
+ val prompt = if resp.resultType == ASK_DIALOG then "(Your should answer on the model's question below)\n" else ""
+ doResponse(s"$prompt${resp.body}")
catch
case e: NCRejection => doResponse(s"Request rejected: ${e.getMessage}")
case e: Throwable =>
diff --git a/nlpcraft-stanford/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/stanford/NCStanfordNLPEntityParser.scala b/nlpcraft-stanford/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/stanford/NCStanfordNLPEntityParser.scala
index 0e75ec0b..5a9dda13 100644
--- a/nlpcraft-stanford/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/stanford/NCStanfordNLPEntityParser.scala
+++ b/nlpcraft-stanford/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/stanford/NCStanfordNLPEntityParser.scala
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.nlpcraft.nlp.entity.parser.stanford.impl
+package org.apache.nlpcraft.nlp.entity.parser.stanford
import edu.stanford.nlp.ling.CoreAnnotations.NormalizedNamedEntityTagAnnotation
import edu.stanford.nlp.pipeline.*
@@ -23,7 +23,6 @@ import org.apache.nlpcraft.*
import java.util
import java.util.stream.Collectors
-import java.util.{Properties, ArrayList as JAList, List as JList, Set as JSet}
import scala.collection.mutable
import scala.jdk.CollectionConverters.*
@@ -32,11 +31,11 @@ import scala.jdk.CollectionConverters.*
* @param stanford
* @param supported
*/
-class NCStanfordNLPEntityParserImpl(stanford: StanfordCoreNLP, supported: Set[String]) extends NCEntityParser:
+class NCStanfordNLPEntityParser(stanford: StanfordCoreNLP, supported: Set[String]) extends NCEntityParser:
require(stanford != null, "Stanford instance cannot be null.")
require(supported != null, "Supported elements set cannot be null.")
- private val supportedLc = supported.asScala.map(_.toLowerCase)
+ private val supportedLc = supported.map(_.toLowerCase)
override def parse(req: NCRequest, cfg: NCModelConfig, toks: List[NCToken]): List[NCEntity] =
val doc = new CoreDocument(req.getText)