This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-473
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-473 by this push:
new 5840bda WIP.
5840bda is described below
commit 5840bda3a5fd1d38320bd980902e7a2cdbb8b64b
Author: Sergey Kamov <[email protected]>
AuthorDate: Sat Jan 29 14:24:21 2022 +0300
WIP.
---
.../nlpcraft/internal/impl/NCModelScanner.scala | 23 +++++++++++-----------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala
index 723ab75..3e37363 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala
@@ -48,8 +48,6 @@ case class NCModelIntent(intent: NCIDLIntent, function:
NCIntentMatch => NCResul
* TODO: common comment for annotations usage. Do not apply annotations for
unused private methods and fields. Compiler can drop them.
*/
object NCModelScanner extends LazyLogging:
- private final val SEPARATORS = Seq('?', ',', '.', '-', '!')
-
private final val CLS_INTENT = classOf[NCIntent]
private final val CLS_INTENT_REF = classOf[NCIntentRef]
private final val CLS_QRY_RES = classOf[NCResult]
@@ -87,7 +85,7 @@ object NCModelScanner extends LazyLogging:
*
*/
private object IntentHolder:
- def apply(cfg: NCModelConfig, intent: NCIDLIntent, obj: Object, mtd:
Method): IntentHolder =
+ def apply(cfg: NCModelConfig, intent: NCIDLIntent, obj: AnyRef, mtd:
Method): IntentHolder =
new IntentHolder(intent, prepareCallback(cfg, mtd, obj, intent),
mtd)
/**
@@ -102,7 +100,7 @@ object NCModelScanner extends LazyLogging:
* @param iter
* @return
*/
- def col2Str(iter: Iterable[_]): String = iter.mkString("(", ",", ")")
+ private def col2Str(iter: Iterable[_]): String = iter.mkString("(", ",",
")")
/**
*
@@ -192,7 +190,7 @@ object NCModelScanner extends LazyLogging:
* @param args
* @return
*/
- private def invoke(cfg: NCModelConfig, method: Method, obj: Object, args:
scala.Array[AnyRef]): NCResult =
+ private def invoke(cfg: NCModelConfig, method: Method, obj: AnyRef, args:
scala.Array[AnyRef]): NCResult =
val methodObj = if Modifier.isStatic(method.getModifiers) then null
else obj
var flag = method.canAccess(methodObj)
@@ -228,7 +226,7 @@ object NCModelScanner extends LazyLogging:
* @param obj
* @return
*/
- private def getFieldObject(cfg: NCModelConfig, field: Field, obj: Object):
Object =
+ private def getFieldObject(cfg: NCModelConfig, field: Field, obj: AnyRef):
AnyRef =
lazy val fStr = field2Str(field)
val fieldObj = if Modifier.isStatic(field.getModifiers) then null else
obj
var flag = field.canAccess(fieldObj)
@@ -446,7 +444,7 @@ object NCModelScanner extends LazyLogging:
* @param intent
* @return
*/
- private def prepareCallback(cfg: NCModelConfig, method: Method, obj:
Object, intent: NCIDLIntent): NCIntentMatch => NCResult =
+ private def prepareCallback(cfg: NCModelConfig, method: Method, obj:
AnyRef, intent: NCIDLIntent): NCIntentMatch => NCResult =
// Checks method result type.
if method.getReturnType != CLS_QRY_RES then
E(s"Unexpected result type for @NCIntent annotated method
[mdlId=${cfg.getId}, intentId=${intent.id},
type=${class2Str(method.getReturnType)}, callback=${method2Str(method)}]")
@@ -522,26 +520,27 @@ object NCModelScanner extends LazyLogging:
* @return
*/
def scan(mdl: NCModel): Seq[NCModelIntent] =
+ require(mdl != null)
+
val cfg = mdl.getConfig
val intents = mutable.Buffer.empty[IntentHolder]
val intentDecls = mutable.HashMap.empty[String, NCIDLIntent]
- val objs = mutable.Buffer.empty[Object]
+ val objs = mutable.Buffer.empty[AnyRef]
val processed = mutable.HashSet.empty[Class[_]]
val samples = mutable.HashMap.empty[Method, Map[String,
Seq[Seq[String]]]]
def addDecl(intent: NCIDLIntent): Unit =
- intentDecls.get(intent.id) match {
+ intentDecls.get(intent.id) match
case Some(ex) =>
if ex.idl != intent.idl then
// TODO: text
E(s"Intent with given ID already found with different
definition [mdlId=${cfg.getId}, origin=${cfg.getOrigin}, id=${intent.id}]")
case None => // No-op.
- }
intentDecls += intent.id -> intent
- def addIntent(intent: NCIDLIntent, mtd: Method, obj: Object): Unit =
+ def addIntent(intent: NCIDLIntent, mtd: Method, obj: AnyRef): Unit =
if intents.exists(_.method == mtd) then
// TODO: text
E(s"The callback cannot have more one intent
[mdlId=${cfg.getId}, origin=${cfg.getOrigin}, callback=${method2Str(mtd)}]")
@@ -562,7 +561,7 @@ object NCModelScanner extends LazyLogging:
// First phase scan.
// For given object finds references via fields (NCIntentObject).
Scans also each reference recursively and collects them.
// For all methods of processed object collects samples
(NCIntentSample, NCIntentSampleRef) and intents (NCIntent)
- def scan(obj: Object): Unit =
+ def scan(obj: AnyRef): Unit =
objs += obj
processClassAnnotations(obj.getClass)
val methods = getAllMethods(obj)