# Write intent

**URL:** <https://forum.rasa.com/t/write-intent/49962>\
**Category:** Rasa Open Source\
**Created:** [December 13, 2021, 7:27am UTC](https://forum.rasa.com/t/write-intent/49962 "2021-12-13T07:27:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alonso](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Alonso](https://forum.rasa.com/u/Alonso)\
**Post date:** [December 13, 2021, 7:27am UTC](https://forum.rasa.com/t/write-intent/49962/1 "2021-12-13T07:27:59Z")

</div>

Hello again,

I’m trying to get the user to type a character string, consisting of + or -, followed by three letters and a number, example: `+COJ1`, `-TPL23`, `+ERD12`

But when I train I get the following:

```auto
UserWarning: Misaligned entity annotation in message 'Code +COJ1' with intent 'code_specific'. Make sure the start and end values of entities ([(8, 13, '+COJ1')]) in the training data match the token boundaries ([(0, 7, 'Code'), (9, 13, 'COJ1')]). Common causes:
  1) entities include trailing whitespaces or punctuation
  2) the tokenizer gives an unexpected result, due to languages such as Chinese that don't use whitespace for word separation
  More info at https://rasa.com/docs/rasa/training-data-format#nlu-training-data

```

This is the intent:

```auto
- intent: code_specific
  examples: |
    - Code [new code](code_number)
    - Code [+COJ1](code_number)

```

The problem is that if I put `Code [1](code_number)` in the intent, when I run rasa shell the next action works correctly, but if I leave it like this it does not.

Does anyone know why?

Thank you very much!

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [December 13, 2021, 9:39am UTC](https://forum.rasa.com/t/write-intent/49962/2 "2021-12-13T09:39:16Z")

</div>

Try using [Regex](https://rasa.com/docs/rasa/training-data-format#regular-expressions) to parse the entities.

It’s the recommended way for parsing ordered data like yours, always +/- followed by 3 letters and a number.

---

<div class="post-metadata">

**Author:** ![Alonso](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Alonso](https://forum.rasa.com/u/Alonso)\
**Post date:** [December 13, 2021, 10:03am UTC](https://forum.rasa.com/t/write-intent/49962/3 "2021-12-13T10:03:25Z")

</div>

I’ve read it but I don’t understand how to apply it ☹

It isn’t necessary to separate the code, i.e. it’s the same group of characters, it isn’t necessary to separate the sign from the letters and the number.

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [December 13, 2021, 12:15pm UTC](https://forum.rasa.com/t/write-intent/49962/4 "2021-12-13T12:15:49Z")

</div>

@Alonso

Demo code with a regular expression please do check the regular expression again. ref: [https://regex101.com](https://regex101.com)

```auto
nlu:
- regex: code_specific
  examples: |
    - [+-a-zA-Z0-9a-zA-Z]+
- intent: inform
  examples: |
     - Code [-TPL23](code_specific)
     - Code [+COJ1](code_specific)

```

You just need to update the config file with [`RegexFeaturizer`](https://rasa.com/docs/rasa/components#regexfeaturizer) and [`RegexEntityExtractor`](https://rasa.com/docs/rasa/components#regexentityextractor) | [NLU Training Data](https://rasa.com/docs/rasa/nlu-training-data/#regular-expressions)

I hope this will help you.

---

<div class="post-metadata">

**Author:** ![Alonso](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Alonso](https://forum.rasa.com/u/Alonso)\
**Post date:** [December 13, 2021, 2:58pm UTC](https://forum.rasa.com/t/write-intent/49962/5 "2021-12-13T14:58:58Z")

</div>

Yes, thank you both very much

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [December 13, 2021, 3:37pm UTC](https://forum.rasa.com/t/write-intent/49962/6 "2021-12-13T15:37:24Z")

</div>

I just wanna propose another Regex since Nik’s will work for anything (`m_m`, `4>3`, `12+A` will all match):

```auto
^(\+|\-)[a-zA-Z]{3}\d+$

```

Nik’s works for everything containing `+`, letters, numbers, and every [ASCII](https://www.asciitable.com/) character between `+` and `a`, all optional and in any order (basically the only thing that will break the pattern are the ASCII characters #32 to #42).

Mine works for tokens starting with + or -, followed by 3 uppercase or lowercase letters, then end with at least one digit.

In my Regex above, any amount of numbers at the end will be taken. If you want for example a minimum of 1 number and a maximum of 4, you can do the following:

```auto
^(\+|\-)[a-zA-Z]{3}\d{1,4}$

```

And, as Nik said, you need to keep at least 2 examples and add `RegexFeaturizer` and `RegexEntityExtractor` in your pipeline.

---

<div class="post-metadata">

**Author:** ![Alonso](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Alonso](https://forum.rasa.com/u/Alonso)\
**Post date:** [December 13, 2021, 4:05pm UTC](https://forum.rasa.com/t/write-intent/49962/7 "2021-12-13T16:05:43Z")

</div>

Thanks!!!
