This is an automated email from the ASF dual-hosted git repository. aradzinski pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
commit 11314bd965e8642ee766793533e4ce312077423f Author: Aaron Radzinski <[email protected]> AuthorDate: Tue Sep 27 11:19:01 2022 -0700 Update NCModel.scala --- .../main/scala/org/apache/nlpcraft/NCModel.scala | 84 +++++++++++----------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModel.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModel.scala index 091f3329..16d41b34 100644 --- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModel.scala +++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModel.scala @@ -55,34 +55,33 @@ trait NCModel: def getPipeline: NCPipeline /** - * TODO: drop link to onVariant - * A callback that is called when a fully assembled query context is ready. This callback is called after - * all {@link # onVariant ( NCVariant )} callbacks are called but before any {@link # onMatchedIntent ( NCIntentMatch )} are - * called, i.e. right before the intent matching is performed. It's called always once per input query processing. - * Typical use case for this callback is to perform logging, debugging, statistic or usage collection, explicit - * update or initialization of conversation context, security audit or validation, etc. + * A callback that is called when a fully assembled query context is ready. This is the first of the callbacks + * that is called on the model and right before the intent matching is performed. It's called always once per + * input query processing. Typical use case for this callback is to perform logging, debugging, statistic or + * usage collection, explicit update or initialization of conversation context, security audit or validation, etc. * - * Default implementation returns `null`. + * Default implementation returns `None`. * * @param ctx Input query context. - * @return Optional query result to return interrupting the default workflow. Specifically, if this method - * returns a non-`null` result, it will be returned to the caller immediately overriding default behavior. - * If the method returns `null` - the default processing flow will continue. + * @return Optional query result to return interrupting the default processing workflow. Specifically, if + * this method returns a `Some` result, it will be returned to the caller immediately interrupting + * default processing workflow. If the method returns `None` - the default processing flow will continue. * @throws NCRejection This callback can throw the rejection exception to abort input query processing. */ - @throws[NCRejection] def onContext(ctx: NCContext): Option[NCResult] = None + @throws[NCRejection] + def onContext(ctx: NCContext): Option[NCResult] = None /** * A callback that is called when intent was successfully matched but right before its callback is called. This - * callback is called after {@link # onContext ( NCContext )} is called and may be called multiple times - * depending on its return value. If `true` is returned than the default workflow will continue and the - * matched intent's callback will be called. However, if `null` is returned than the entire existing set of + * callback is called after [[onContext()]] is called and may be called multiple times depending on its return + * value. If `true` is returned than the default processing workflow will continue and the + * matched intent's callback will be called. However, if `false` is returned than the entire existing set of * parsing variants will be matched against all declared intents again. Returning `false` allows this - * method to alter the state of the model (like soft-reset conversation or change metadata) and force the - * full re-evaluation of the parsing variants against all declared intents. + * method to alter the state of the model (like soft-reset conversation or change metadata) and force a + * full re-evaluation of the parsing variants against all declared intents again. * * Note that user logic should be careful not to induce infinite loop in this behavior. - * Note that this callback may not be called at all based on the return value of {@link # onContext ( NCContext )} callback. + * Note that this callback may not be called at all based on the return value of [[onContext()]] callback. * Typical use case for this callback is to perform logging, debugging, statistic or usage collection, explicit * update or initialization of conversation context, security audit or validation, etc. * @@ -90,53 +89,56 @@ trait NCModel: * * @param im Intent match context - the same instance that's passed to the matched intent callback. * @return If `true` is returned than the default workflow will continue and the matched intent's - * callback will be called. However, if `false` is returned than the entire existing set of - * parsing variants will be matched against all declared intents again. Returning false allows this - * method to alter the state of the model (like soft-reset conversation or change metadata) and force - * the re-evaluation of the parsing variants against all declared intents. Note that user logic should be - * careful not to induce infinite loop in this behavior. + * callback will be called. However, if `false` is returned than the entire existing set of + * parsing variants will be matched against all declared intents again. Returning false allows this + * method to alter the state of the model (like soft-reset conversation or change metadata) and force + * the re-evaluation of the parsing variants against all declared intents again. Note that user logic + * should be careful not to induce infinite loop in this behavior. * @throws NCRejection This callback can throw the rejection exception to abort user request processing. In this - * case the {@link # onRejection ( NCIntentMatch, NCRejection)} callback will be called next. + * case the [[onRejection()]] callback will be called next. */ - @throws[NCRejection] def onMatchedIntent(ctx: NCContext, im: NCIntentMatch) = true + @throws[NCRejection] + def onMatchedIntent(ctx: NCContext, im: NCIntentMatch): Boolean = true /** * A callback that is called when successful result is obtained from the intent callback and right before - * sending it back to the caller. This callback is called after {@link # onMatchedIntent ( NCIntentMatch )} is called. + * sending it back to the caller. This callback is called after [[onMatchedIntent()]] is called. * Note that this callback may not be called at all, and if called - it's called only once. Typical use case * for this callback is to perform logging, debugging, statistic or usage collection, explicit update or * initialization of conversation context, security audit or validation, etc. * - * Default implementation is a no-op returning `null`. + * Default implementation is a no-op returning `None`. * * @param im Intent match context - the same instance that's passed to the matched intent callback - * that produced this result. + * that produced this result. * @param res Existing result. * @return Optional query result to return interrupting the default workflow. Specifically, if this - * method returns a non-`null` result, it will be returned to the caller immediately overriding - * default behavior and existing query result or error processing, if any. If the method returns `null` - - * the default processing flow will continue. + * method returns a `Some` result, it will be returned to the caller immediately overriding + * default behavior and existing query result or error processing, if any. If the method returns `None` - + * the default processing flow will continue. */ def onResult(ctx: NCContext, im: NCIntentMatch, res: NCResult): Option[NCResult] = None /** * A callback that is called when intent callback threw NCRejection exception. This callback is called - * after {@link # onMatchedIntent ( NCIntentMatch )} is called. Note that this callback may not be called at all, + * after [[onMatchedIntent()]] is called. Note that this callback may not be called at all, * and if called - it's called only once. Typical use case for this callback is to perform logging, debugging, * statistic or usage collection, explicit update or initialization of conversation context, security audit or * validation, etc. * - * Default implementation is a no-op returning `null`. + * Default implementation is a no-op returning `None`. * * @param ctx Optional intent match context - the same instance that's passed to the matched intent callback - * that produced this rejection. It is `null` if rejection was triggered outside the intent callback. + * that produced this rejection. It is `None` if rejection was triggered outside the intent callback. + * @param im Optional intent match context - the same instance that's passed to the matched intent callback + * that produced this result. It is `None` if rejection was triggered outside the intent callback. * @param e Rejection exception. * @return Optional query result to return interrupting the default workflow. Specifically, if this method - * returns a non-`null` result, it will be returned to the caller immediately overriding default behavior - * and existing query result or error processing, if any. If the method returns `null` - the default - * processing flow will continue. + * returns a `Some` result, it will be returned to the caller immediately overriding default behavior + * and existing query result or error processing, if any. If the method returns `None` - the default + * processing flow will continue. */ - def onRejection(ctx: NCContext, im: Option[NCIntentMatch], e: NCRejection): Option[NCResult] = None + def onRejection(ctx: Option[NCContext], im: Option[NCIntentMatch], e: NCRejection): Option[NCResult] = None /** * A callback that is called when intent callback failed with unexpected exception. Note that this callback may @@ -144,13 +146,13 @@ trait NCModel: * to perform logging, debugging, statistic or usage collection, explicit update or initialization of conversation * context, security audit or validation, etc. * - * Default implementation is a no-op returning `null`. + * Default implementation is a no-op returning `None`. * * @param ctx Intent match context - the same instance that's passed to the matched intent that produced this error. * @param e Failure exception. * @return Optional query result to return interrupting the default workflow. Specifically, if this method - * returns a non-`null` result, it will be returned to the caller immediately overriding default - * behavior and existing query result or error processing, if any. If the method returns `null` - the - * default processing flow will continue. + * returns a `Some` result, it will be returned to the caller immediately overriding default + * behavior and existing query result or error processing, if any. If the method returns `None` - the + * default processing flow will continue. */ def onError(ctx: NCContext, e: Throwable): Option[NCResult] = None
