Filling slot with a list of entities | Rasa

Viewed 1564

I am trying to get phone number form the user but sometimes the Speach recognition returns charachters instead of numbers, for instance:

"my contact is zero three one one seven two one one."

so to get these values i am using duckling with number dimenssion to detect this. it detects all the numbers as entities, so now what i need is to get all number values from the wntities and conactnate them to get full number and put it’s value in slot. I have tried using self.from_entity('number') but it only returns last value from the list.

is there any way to this, or any work around i should consider.

2 Answers

My rasa version number is 1.9.6. I used regular expression to extract mobile no. We can reformat regex:mobileno based upon the requirements.

## intent:inform
- [97504*****](mobileno)
- [87459*****](mobileno)

## regex:mobileno
- [6789]{1}\d{4}?[\d]{5}$

rasa shell nlu output

Next Message: 
9999999999
{
  "intent": {
    "name": "inform",
    "confidence": 0.9978736042976379
  },
  "entities": [
    {
      "entity": "mobileno",
      "start": 0,
      "end": 10,
      "extractor": "DIETClassifier",
      "value": "999999999"
    }
  ],
  ...,
  ...,
  "text": "9999999999"
}

You could do this in a validation function by checking all values for the number entity extracted for a certain user message, and concatenating them. So you'd still fill your slot from_entity but in your validation function you'd actually go fetch all the values. There's an example for a similar thing for a sentence with dates/times, you'll need to follow the function definitions to see the details: https://github.com/RasaHQ/financial-demo/blob/d6f54f77b081b2136c892fce0fc2e999a2589616/actions/actions.py#L267

Related