Multiple Regex Pattern for 1 entity

Hello,

I’m trying to use regex to extract datetime entities. There are 2 datetime formats which i want to extract:

  • DD/MM/YYYY
  • DD-MM-YYYY

I tried to make a regex like this in my nlu.md:

   ## regex:date
    - [0-9]{1,2}?/[0-9]{1,2}?/[0-9]{4}
    - [0-9]{1,2}?\-[0-9]{1,2}?\-[0-9]{4}

Here my training data:

  • Tôi muốn đặt phòng họp vào 15/03/2019
  • Tôi muốn đặt phòng họp vào 02-12-2019
  • Tôi muốn đặt lịch phòng họp vào 12/02/2020
  • Tôi muốn đặt lịch phòng họp vào 11-9-2021
  • Tôi cần đặt lịch phòng họp vào ngày 13/6/2022
  • Tôi cần đặt lịch phòng họp vào ngày 28-11-2040
  • Đặt lịch phòng họp vào ngày 17/10/2024
  • Đặt lịch phòng họp vào ngày 30-04-2086
  • Tôi muốn đặt lịch phòng họp vào 13/08/2056
  • Tôi muốn đặt lịch phòng họp vào 25-7-2033
  • Tôi cần đặt lịch phòng họp vào 29/5/2037
  • Tôi cần đặt lịch phòng họp vào 07-01-2099

I am only able to extract 1 of 2 datetime formats, and whenever i remove a format in the ## regex:date, i extract the other format successfully.

So i want to know if Rasa can use multiple regex patterns for 1 entity like i did. And if that’s not the case then is there any work around for me to achieve this ? Thank you for your help.

Simple workaround is to just make one entity per format and use custom slot mappings to get either one into a slot when needed.

Yeah i was also thinking about having to use 2 different entities, but never thought about the custom slot mappings. Sounds like a good workaround to me, it feels pretty simple too. I will try implementing it and see how this will go. Thank you.

After a while thinking, i face a problem with custom slot mappings:

def slot_mappings(self):
    return {'date': [self.from_entity(entity='date_slash', intent='book_meeting_room'),
                     self.from_entity(entity='date_hyphen', intent='book_meeting_room')]}

How can it know which entity it should choose when they came from the same intent ?

Oh hell i just remembered that the symbol ‘|’ acts like OR in regex so i can just put it between the 2 formats in 1 regex pattern ! Silly me :smiley: