in nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala [336:368]
private def prepareCallback(cfg: NCModelConfig, method: Method, obj: AnyRef, intent: NCIDLIntent): NCCallbackInput => NCResult =
lazy val z = s"mdlId=${cfg.getId}, intentId=${intent.id}, type=${class2Str(method.getReturnType)}, callback=${method2Str(method)}"
// Checks method result type.
if method.getReturnType != CLS_QRY_RES && !CLS_QRY_RES.isAssignableFrom(method.getReturnType) then
E(s"Unexpected result type for @NCIntent annotated method [$z]")
val allParamTypes = method.getParameterTypes.toList
if allParamTypes.sizeIs < 2 then E(s"Unexpected parameters count for $I annotated method [count=${allParamTypes.size}, method=$z]")
if allParamTypes.head != CLS_CTX then E(s"First parameter for $I annotated method must be NCContext [method=$z]")
if allParamTypes(1) != CLS_INTENT_MATCH then E(s"Second parameter for $I annotated method must be NCIntentMatch [method=$z]")
val tokParamAnns = method.getParameterAnnotations.toList.drop(2).filter(_ != null)
val tokParamTypes = allParamTypes.drop(2)
// Checks entities parameters annotations count.
if tokParamAnns.sizeIs != tokParamTypes.length then
E(s"Unexpected annotations count for $I annotated method [count=${tokParamAnns.size}, $z]")
// Gets terms IDs.
val termIds = tokParamAnns.zipWithIndex.map {
case (annArr, idx) =>
val termAnns = annArr.filter(_.isInstanceOf[NCIntentTerm])
// Each method arguments (second and later) must have one 'NCIntentTerm' annotation.
termAnns.length match
case 1 => termAnns.head.asInstanceOf[NCIntentTerm].value
case 0 =>
if idx == 0 then E(s"Missing $IT annotation or wrong type of the 1st parameter (must be 'NCIntentMatch') for [$z]")
else E(s"Missing $IT annotation for [$z]")
case _ => E(s"Too many $IT annotations for [$z]")
}