simple_ner#

class besser.bot.nlp.ner.simple_ner.SimpleNER(nlp_engine, bot)[source]#

Bases: NER

A simple NER.

It can find an entity value in a user message only with exact matching (i.e. slight variations on an entity value within a user message will make the NER fail)

Parameters:
  • nlp_engine (NLPEngine) – the NLPEngine that handles the NLP processes of the bot

  • bot (Bot) – the bot the NER belongs to

_abc_impl = <_abc._abc_data object>#
predict(state, message)[source]#

Predict the entities of a given message.

Parameters:
  • state (State) – the state where the user is in. It is necessary to know the entities that can be matched (not all entities can be matched from a specific state, only those of the state’s intents)

  • message (str) – the message to predict the entities

Returns:

the result of the NER prediction

Return type:

NERPrediction

train()[source]#

Train the NER.

besser.bot.nlp.ner.simple_ner.base_entity_ner(sentence, entity_name, nlp_engine)[source]#

Do NER with a base entity.

Given a sentence and a base entity, look for a value of the base entity in the sentence.

Parameters:
  • sentence (str) – the text to do the NER to

  • entity_name (str) – the base entity name

  • nlp_engine (NLPEngine) – the NLPEngine that handles the NLP processes of the bot

Returns:

the sentence (that can be modified), the matched fragment,

and the extra info. If no value has been found, return None

Return type:

tuple[str or None, str or None, dict or None]

besser.bot.nlp.ner.simple_ner.get_custom_entity_values_dict(intent, processed_values=False)[source]#

Get a dictionary containing, for each entity value v (including synonyms) among all paramters in an intent, a tuple with: 1 - the intent parameters where v could be a match and 2 - the main value of v (if v is not a synonym and it is the main value, it will be duplicated):

{value/synonym: ([intent_parameters], value)}

Parameters:
  • intent (Intent) – the target intent

  • processed_values (bool) – whether to retrieve the entities processed values or not

Returns:

the dictionary

Return type:

dict[str, tuple[list[IntentParameter], str]]