Interface NlpListener
-
- All Implemented Interfaces:
public interface NlpListenerUsed to customize behaviour of NLP parsing - and also to monitor NLP requests - on bot side. Has to be registered using ai.tock.bot.engine.BotRepository.registerNlpListener.
-
-
Method Summary
Modifier and Type Method Description IntenthandleKeyword(String sentence)Used to handle "secret" keywords. NlpResultprecompute(SendSentence sentence, UserTimeline userTimeline, Dialog dialog, BotDefinition botDefinition)Precomputes NLP result - if this method returns null, the NlpResult is used and no NLP call is sent. NlpQueryupdateQuery(SendSentence sentence, UserTimeline userTimeline, Dialog dialog, BotDefinition botDefinition, NlpQuery nlpQuery)This method is automatically called by the bot before a NLP request is sent in order to update the NLP query parameters. IntentAwarefindIntent(UserTimeline userTimeline, Dialog dialog, Event event, NlpResult nlpResult)This method is automatically called by the bot after a NLP request in order to select an intent. List<EntityValue>evaluateEntities(UserTimeline userTimeline, Dialog dialog, Event event, NlpResult nlpResult)Allows custom entity evaluation - default returns empty list. List<NlpEntityMergeContext>sortEntitiesToMerge(List<NlpEntityMergeContext> entities)Defines custom sort new entity values. NlpEntityMergeContextmergeEntityValues(DialogState dialogState, Action action, NlpEntityMergeContext entityToMerge)Allows to override NlpEntityMergeContext before trying to merge the entity context. Unitsuccess(NlpQuery query, NlpResult result)Called when nlp request is successful. Uniterror(NlpQuery query, Dialog dialog, Throwable throwable)Called when nlp request is throwing an error. -
-
Method Detail
-
handleKeyword
Intent handleKeyword(String sentence)
Used to handle "secret" keywords.
- Returns:
null if no keyword is detected. If not null the nlp call is not started and the returned intent is used.
-
precompute
NlpResult precompute(SendSentence sentence, UserTimeline userTimeline, Dialog dialog, BotDefinition botDefinition)
Precomputes NLP result - if this method returns null, the NlpResult is used and no NLP call is sent.
Default returns null.
-
updateQuery
NlpQuery updateQuery(SendSentence sentence, UserTimeline userTimeline, Dialog dialog, BotDefinition botDefinition, NlpQuery nlpQuery)
This method is automatically called by the bot before a NLP request is sent in order to update the NLP query parameters. Overrides it if you need more control on NLP request.
Default returns nlpQuery without change.
-
findIntent
IntentAware findIntent(UserTimeline userTimeline, Dialog dialog, Event event, NlpResult nlpResult)
This method is automatically called by the bot after a NLP request in order to select an intent. Overrides it if you need more control on intent choice.
If it returns null, ai.tock.bot.definition.BotDefinition.findIntent is called.
Default returns null.
-
evaluateEntities
List<EntityValue> evaluateEntities(UserTimeline userTimeline, Dialog dialog, Event event, NlpResult nlpResult)
Allows custom entity evaluation - default returns empty list.
-
sortEntitiesToMerge
List<NlpEntityMergeContext> sortEntitiesToMerge(List<NlpEntityMergeContext> entities)
Defines custom sort new entity values. This is useful when you want to evaluate an entity role only after an other entity role has been evaluated (entity dependence use case). Default does nothing.
-
mergeEntityValues
NlpEntityMergeContext mergeEntityValues(DialogState dialogState, Action action, NlpEntityMergeContext entityToMerge)
Allows to override NlpEntityMergeContext before trying to merge the entity context.
-
error
Unit error(NlpQuery query, Dialog dialog, Throwable throwable)
Called when nlp request is throwing an error.
Using this method, you can for example redirect to a custom story which will handle the error.
object MyNlpListener : NlpListener { override fun error(query: NlpQuery, dialog: Dialog, throwable: Throwable?) { super.error(query, dialog, throwable) dialog.state.currentIntent = bot.myCustomErrorStory.mainIntent() } }
-
-
-
-