This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch NLPCRAFT-283
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-283 by this push:
new 3b37e1c Code review.
3b37e1c is described below
commit 3b37e1cc41863ffa8c36dac4cce98d8ce05bc74c
Author: Aaron Radzinski <[email protected]>
AuthorDate: Fri Mar 26 10:16:37 2021 -0700
Code review.
---
.../org/apache/nlpcraft/common/util/NCUtils.scala | 25 +++++++++++++---------
.../model/intent/solver/NCIntentSolverEngine.scala | 18 ++++++++--------
2 files changed, 24 insertions(+), 19 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
index 0634dd6..42023ae 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
@@ -1944,7 +1944,8 @@ object NCUtils extends LazyLogging {
}
/**
- *
+ * Calling a method with one parameter and a non-null return value.
+ *
* @param objFac
* @param mtdName
* @param arg
@@ -1957,18 +1958,22 @@ object NCUtils extends LazyLogging {
val obj: Any = objFac()
if (obj == null)
- throw new NCE(s"Invalid 'null' object created for method:
$mtdName")
+ throw new NCE(s"Invalid 'null' object created attempting to
call method: $mtdName")
- val argClazz = classTag[T].runtimeClass
- val retClazz = classTag[R].runtimeClass
+ val argCls = classTag[T].runtimeClass
+ val retCls = classTag[R].runtimeClass
- def mkErrors = s"[name=${obj.getClass.getName}#$mtdName,
argType=$argClazz, retType=$retClazz]"
+ def mkErrors = s"[" +
+ s"name=${obj.getClass.getName}#$mtdName(...), " +
+ s"argType=${argCls.getCanonicalName}, " +
+ s"retType=${retCls.getCanonicalName}" +
+ s"]"
val mtd =
try
- obj.getClass.getMethod(mtdName, argClazz)
+ obj.getClass.getMethod(mtdName, argCls)
catch {
- case e: NoSuchMethodException ⇒ throw new NCE(s"Expected
method not found $mkErrors", e)
+ case e: NoSuchMethodException ⇒ throw new NCE(s"Method not
found $mkErrors", e)
}
var flag = mtd.canAccess(obj)
@@ -1986,7 +1991,7 @@ object NCUtils extends LazyLogging {
try
mtd.invoke(obj, arg.asInstanceOf[Object])
catch {
- case e: Throwable ⇒ throw new NCE(s"Method execution
error $mkErrors", e)
+ case e: Throwable ⇒ throw new NCE(s"Failed to execute
method $mkErrors", e)
}
if (res == null)
@@ -1995,7 +2000,7 @@ object NCUtils extends LazyLogging {
try
res.asInstanceOf[R]
catch {
- case e: ClassCastException ⇒ throw new NCE(s"Invalid
method signature (result type) $mkErrors", e)
+ case e: ClassCastException ⇒ throw new NCE(s"Invalid
method result type $mkErrors", e)
}
}
finally {
@@ -2005,7 +2010,7 @@ object NCUtils extends LazyLogging {
}
catch {
case e: NCE ⇒ throw e
- case e: Throwable ⇒ throw new NCE("Unexpected error.", e)
+ case e: Throwable ⇒ throw new NCE(s"Unexpected error calling
method: $mtdName(...)", e)
}
/**
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/solver/NCIntentSolverEngine.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/solver/NCIntentSolverEngine.scala
index 2c6d3dc..7dbdcbf 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/solver/NCIntentSolverEngine.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/solver/NCIntentSolverEngine.scala
@@ -435,18 +435,18 @@ object NCIntentSolverEngine extends LazyLogging with
NCOpenCensusTrace {
val str = flow.map(_.getIntentId).mkString(" ")
def x(s: String): Unit = {
- logger.info(s"Intent '$intentId' ${bo(s)} regex dialog flow
$varStr:")
+ logger.info(s"Intent '$intentId' $s regex dialog flow
$varStr:")
logger.info(s" |-- ${c("Intent IDs :")} $str")
logger.info(s" +-- ${c("Match regex :")}
${flowRegex.get.toString}")
}
if (!flowRegex.get.matcher(str).find(0)) {
- x("did not match")
+ x(s"${bo(r("did not match"))}")
flowMatched = false
}
else
- x("matched")
+ x(s"matched")
}
else if (intent.flowMtdName.isDefined) {
val clsName = intent.flowClsName.orNull
@@ -469,12 +469,12 @@ object NCIntentSolverEngine extends LazyLogging with
NCOpenCensusTrace {
}
def x(s: String): Unit = {
- logger.info(s"Intent '$intentId' ${bo(s)} custom flow callback
$varStr:")
+ logger.info(s"Intent '$intentId' $s custom flow callback
$varStr:")
logger.info(s" +-- ${c("Custom callback :")} $fqn")
}
if (!res) {
- x("did not match")
+ x(s"${bo(r("did not match"))}")
flowMatched = false
}
@@ -541,7 +541,7 @@ object NCIntentSolverEngine extends LazyLogging with
NCOpenCensusTrace {
case None ⇒
// Term is missing. Stop further processing for this
intent. This intent cannot be matched.
- logger.info(s"Intent '$intentId' ${r("did not")} match
because of unmatched term '$term' $varStr.")
+ logger.info(s"Intent '$intentId' ${bo(r("did not
match"))} because of unmatched term '$term' $varStr.")
abort = true
}
@@ -557,15 +557,15 @@ object NCIntentSolverEngine extends LazyLogging with
NCOpenCensusTrace {
var res: Option[IntentMatch] = None
if (usedSenToks.isEmpty && usedConvToks.isEmpty)
- logger.info(s"Intent '$intentId' ${r("did not")} match
because no tokens were matched $varStr.")
+ logger.info(s"Intent '$intentId' ${bo(r("did not match"))}
because no tokens were matched $varStr.")
else if (usedSenToks.isEmpty && usedConvToks.nonEmpty)
- logger.info(s"Intent '$intentId' ${r("did not")} match
because all its matched tokens came from STM $varStr.")
+ logger.info(s"Intent '$intentId' ${bo(r("did not match"))}
because all its matched tokens came from STM $varStr.")
else if (unusedSenToks.exists(_.token.isUserDefined))
NCTokenLogger.prepareTable(unusedSenToks.filter(_.token.isUserDefined).map(_.token)).
info(
logger,
Some(
- s"Intent '$intentId' ${r("did not")} match
because of remaining unused user tokens $varStr." +
+ s"Intent '$intentId' ${bo(r("did not match"))}
because of remaining unused user tokens $varStr." +
s"\nUnused user tokens for intent '$intentId'
$varStr:"
)
)