Regex to entity

I would like to use regex instead of list of possible values in nlu file. I had some imagination how to do it but it does not works as I was expecting. It was working with list, where were listed every possible value, entity UpdateNumber was filled correctly. But it does not working with regex, please have somebody an experience with regex?

nlu.md:

## regex:update_number
- ([A-Z]{2}[0-9]{3}/[0-9]{2}/[A-Z]{1})

## intent:give_update_number
- the update number is [update_number](UpdateNumber)
- [update_number](UpdateNumber)

stories.md:

  - utter_ask_update_number
* give_update_number[BC001/17/S](UpdateNumber)
  - action_validate_update_number

You need to provide examples under the intent with values for the update_number, the regex is not designed to replace that value. So have something like:

- the update number is [BC001/17/S](UpdateNumber)

Also your story format should be like this:

* give_update_number{"UpdateNumber":"xyz"}

2 Likes

Thank you, but it is exactly as it was working before, there were list of examples. So, is not possible to use regex instead of this list and in which case has to be used regex?

As far as I understand the regex part is just to further specify how exactly the entity has to look. The entity examples given in the intent examples are just for the NLU to “understand” in which context the entity can appear … am I near right?

I just added a regex definition a few minutes ago because intent examples alone didn’t work - but with the regex part it is working now!

I am little bit confused, please could you be more specific? I would like to know: where you added “regex definition for entity”?

In my case it is working with value from example (intent definition), but in case when I use different value (which is matched by regex) entity is not filled.

1 Like

In my special case I tried to match licence plates from cars in a Germany specific format. So in my nlu_data.md I have following lines

## intent: inform
- Mein Kennzeichen ist [AS-DF-1234](carplate)
[and some other intent examples]

## regex:carplate
- [a-zA-Z]{1,3}-[a-zA-Z]{1,4}-[0-9]{1,4}

With this I’m able to detect values which are covered by the regex but not by the examples

Yes exactly, so you still need examples of the context, and then the regex helps to extract entities of that format

1 Like

Still no success, it is working only for my examples…

So, how many intent examples and training stories do you have for car plates? Do you use the same values for training in stories?

Hm, strange. I have about 5-10 intent examples for that special case and I created so far 5 stories in total via interactive learning

Can you post your training data file here?

Thank you for your help! After I added 10 “examples” into intent it is working. Also I have 3 stories with different examples.

Only for the others, which cold fell lost as me:

nlu.md:

> ## regex:UpdateNumber
> - [A-Z]{2}[0-9]{3}/[0-9]{2}/[A-Z]{1}
> 
> ## intent:give_update_number
> - the update number is [BC001/17/S](UpdateNumber)
> - [BC001/17/S](UpdateNumber)
> - the update number is [JB007/34/P](UpdateNumber)
> - [JB007/34/P](UpdateNumber)
....10x similar rows

stories.md

> ## story_resend_update_notification_01
> * update_notification
>   - utter_ask_update_number
> * give_update_number{"UpdateNumber":"BC001/17/S"}
>   - action_validate_update_number
> ... 3x similar stories with different values

So again, thank you to all!

1 Like

Another question: how I can train bot to ask again for entity if value did not match pattern OR use some condition how to decide next steps? Only for example:

## story_resend_update_notification_01
* update_notification
  - utter_ask_update_number
* give_update_number[BC001/17/S](UpdateNumber)
  - action_validate_update_number
  - is_not_valid(UpdateNumber) OR (UpdateNumber) == [BC001/17/S]
  - utter_ask_update_number_again

Can you post your action of “is_not_valid” here? What is the definition of “is_not_valid”?

I have implemented action_validate_update_number which checks whether provided UpdateNumber matched our pattern. So this action with result false means: provided UpdateNumber is not valid, please provide it again. So there is not such action, it is exactly what I need to find out how to force bot for asking “Number was not valid, please provide it again!”.

My idea is: how to train bot in case when input does not matched pattern to ask user for it again? Something like condition but in this case bot has to decide if input was true OR else.

I’m also looking for solutions. But your story can not achieve your purpose obviously. Because there is no change in intent or event or entity. If you have the result, tell me please.

@cMarex Hmm, so what exactly is the problem you’re having now? You say part of it was solved right? Though your story format is wrong * give_update_number[BC001/17/S](UpdateNumber) --> * give_update_number{"UpdateNumber":"BC..."}

As for the action_validate_update_number, you should handle this with a boolean slot for example. something like is_valid_number and have a story for when it’s set to true and when it’s set to false

1 Like

Hello, please could you provide an example how it should be written in stories? I do not have imagination how can rasa-core controls workflow, I always see examples when user controls workflow.

Thank you in advance…

Have you looked at these examples? http://rasa.com/docs/core/slotfilling/

1 Like

Thank you, now I see them. I was guessing that should be something like this but I was not sure.

Thank you again!

Hi @akelad, one small clarification - so if I have two to three entities which need to be validated, I need to write those many combinations of stories for the entities values true and false is it…?