nlp_engine#

class besser.bot.nlp.nlp_engine.NLPEngine(bot)[source]#

Bases: object

The NLP Engine of a bot.

It is in charge of running different Natural Language Processing tasks required by the bot.

Parameters:

bot (Bot) – the bot the NLPEngine belongs to

_bot#

The bot the NLPEngine belongs to

Type:

Bot

_intent_classifiers#

The collection of Intent Classifiers of the NLPEngine. There is one for each bot state (only states with transitions triggered by intent matching)

Type:

dict[State, IntentClassifier]

_ner#

The NER (Named Entity Recognition) system of the NLPEngine

Type:

NER or None

_speech2text#

The Speech-to-Text System of the NLPEngine

Type:

Speech2Text or None

get_best_intent_prediction(intent_classifier_predictions)[source]#

Get the best intent prediction out of a list of intent predictions. If none of the predictions is well enough to be considered, return nothing.

Parameters:

intent_classifier_predictions (list[IntentClassifierPrediction]) –

Returns:

the best intent prediction or None if no intent prediction is well

enough

Return type:

IntentClassifierPrediction or None

get_property(prop)[source]#

Get a NLP property’s value from the NLPEngine’s bot.

Parameters:

prop (Property) – the property to get its value

Returns:

the property value, or None if the property is not an NLP property

Return type:

Any

initialize()[source]#

Initialize the NLPEngine.

property ner#

The bot name.

Type:

NER

predict_intent(session)[source]#

Predict the intent of a user message.

Parameters:

session (Session) – the user session

Returns:

the intent prediction

Return type:

IntentClassifierPrediction

speech2text(speech)[source]#

Transcribe a voice audio into its corresponding text representation.

Parameters:

speech (bytes) – the recorded voice that wants to be transcribed

Returns:

the speech transcription

Return type:

str

train()[source]#

Train the NLP components of the NLPEngine.