Entities from the intent

Hello everyone,

I need to compare the entities from the user message with the entities from the intent associated. I know how to extract the entities from the user message in a custom action, but I don’t know how to extract automatically all the entities (defined in the nlu file) from the intent.

Thank you in advance,

Mar

What do you mean by the “entities defined from the intent”?

Do you mean the entities given in the intent’s examples?

If yes, you can also access those in Custom Actions, from the domain variable.


Edit: Nevermind, I was not focused, sorry. As its name implies, domain contains the domain, not NLU!

@mar Can I ask what is the significance of extracting the entities? Firstly, the entities you have defined is the nlu training example under specific intent, and all the stories. I guess that what user will mention in the bot/user conversation? Secondly, what do you mean by extract automatically all the entities? I guess, the bot/user conversation will be set based on question and respective answer for some extent? Please clarify us this approach. :thinking:

yes I’m referring to the entities given in the intent’s example, and how can I get them from the domain?

@mar I guess Chris suggesting this or something else :

you can extract the value using this:

ent = tracker.latest_message['entities'][0]['value']

“ent” is an array with a dict inside, so the “[0]” is for get in the dict and you can obtain anything inside using the name of the key, in this case “value”.

I meant to have in a custom action the entities I defined for an intent in the nlu file. The idea is to compare those entities with the ones given in the user message.

You can see the entities defined in the domain using the domain variable, but you cannot read the NLU files.

Unless (I haven’t tried this), you can read the nlu.yml directly from a custom action and parse the YAML:

import yaml

nlu = None

with open('../data/nlu.yml') as file: # or whatever relative path you have
    nlu = yaml.safe_load(file)