# Mapping same entity to different slots

**URL:** <https://forum.rasa.com/t/mapping-same-entity-to-different-slots/1389>\
**Category:** Rasa Open Source\
**Created:** [September 25, 2018, 5:03pm UTC](https://forum.rasa.com/t/mapping-same-entity-to-different-slots/1389 "2018-09-25T17:03:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sabyasachee](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/sabyasachee/32/583_2.png) [@sabyasachee](https://forum.rasa.com/u/sabyasachee)\
**Post date:** [September 25, 2018, 5:03pm UTC](https://forum.rasa.com/t/mapping-same-entity-to-different-slots/1389/1 "2018-09-25T17:03:37Z")

</div>

rasa\_core: 0.11.4 python: 3.6.6 OS: macOS 10.14

I am building a flight information retrieval system. I have an entity type: location and two slots, origin and destination. The system can ask the user about the city of origin: utter\_ask\_origin and also ask about the city of destination: utter\_ask\_destination. In both cases, the user might give a simple answer like Los Angeles or New York. The intent of this message is inform\_location with location entity: Los Angeles or New York. In the first case, I need it to be mapped to slot: origin and in the second case I need it to be mapped to slot: destination. What is the best way to do that?

domain.yml

```auto
intents:
  - greet
  - goodbye
  - ask_flights
  - inform_origin
  - inform_dest
  - inform_location
  - inform_date
  - inform_airline
  - easter_egg
  - affirm
  - negate

slots:
  origin:
    type: text
  destination:
    type: text
  date:
    type: text
  airline:
    type: text

entities:
  - origin
  - destination
  - location
  - date
  - airline

templates:
  utter_greet:
    - "Hello! How can I help you?"
    - "Welcome! What can I do for you?"
  utter_goodbye:
    - "Bye!"
    - "Goodbye!"
  utter_ask_origin:
    - "What is your origin city?"
    - "Where do you want to travel from?"
    - "Name the city from where you want to start?"
  utter_ask_destination:
    - "What is your destination city?"
    - "Where do you want to travel to?"
    - "Name the city you want to reach?"
  utter_ask_date:
    - "What is your date of journey?"
    - "When do you want to travel?"
  utter_ask_airline:
    - "Which airline do you want to travel with?"
  utter_easter_egg:
    - "Fight on for ol’ SC!"

actions:
  - utter_greet
  - utter_goodbye
  - utter_ask_origin
  - utter_ask_dest
  - utter_ask_date
  - utter_ask_airline
  - utter_easter_egg
  - action_time

```

---

<div class="post-metadata">

**Author:** ![sabyasachee](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/sabyasachee/32/583_2.png) [@sabyasachee](https://forum.rasa.com/u/sabyasachee)\
**Post date:** [September 26, 2018, 10:59pm UTC](https://forum.rasa.com/t/mapping-same-entity-to-different-slots/1389/2 "2018-09-26T22:59:50Z")

</div>

I am replying to my own question, and asking another question of my own!

To map the same entity type to different slots in my case, I declare another slot called asked\_type that I set to ask\_origin if the bot asks the user for the origin location and set to ask\_destination if the bot asks for the destination location. Then when I retrieve a location entity, depending upon the slot value for asked\_type I can accordingly either populate the origin slot or destination slot.

But I noticed that this works only if I had some prior context which for this case was the bot asking the user about the origin location or destination location. What happens when the user starts by asking something like - “I want to search for flights from Boston to New York…”. Now I retrieve 2 location entities and I don’t know which of them is origin and destination, solely from the intent. Also I have no prior context.

I can ask the user to disambiguate for us each location by questioning them whether say, Boston, is their origin or destination, but this seems a messy solution. What can I do?

---

<div class="post-metadata">

**Author:** ![naoko](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/naoko/32/196_2.png) [@naoko](https://forum.rasa.com/u/naoko)\
**Post date:** [November 26, 2018, 4:56pm UTC](https://forum.rasa.com/t/mapping-same-entity-to-different-slots/1389/3 "2018-11-26T16:56:14Z")

</div>

I’m answering your original question here as I had to solve the exact same issue. “How can I map the same entity to different slot”. You can solve this with new `FormAction` with `slot_mapping`. In NLU, you can just train “country” entity only. Then, in `FormAction`, you define both as `required_slots` like this `return ["origin", "destination"]`. then in `slot_mappings`, you define like this

```auto
return dict(
            origin=self.from_entity(entity='country'),
            destination=self.from_entity(entity='country')
        )

```

---

<div class="post-metadata">

**Author:** ![red-frog](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/red-frog/32/2293_2.png) [@red-frog](https://forum.rasa.com/u/red-frog)\
**Post date:** [March 22, 2019, 3:07am UTC](https://forum.rasa.com/t/mapping-same-entity-to-different-slots/1389/4 "2019-03-22T03:07:15Z")

</div>

How to define which the country is origin and other is desination?Thanks

---

<div class="post-metadata">

**Author:** ![red-frog](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/red-frog/32/2293_2.png) [@red-frog](https://forum.rasa.com/u/red-frog)\
**Post date:** [March 22, 2019, 3:07am UTC](https://forum.rasa.com/t/mapping-same-entity-to-different-slots/1389/5 "2019-03-22T03:07:39Z")

</div>

@naoko

---

<div class="post-metadata">

**Author:** ![naoko](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/naoko/32/196_2.png) [@naoko](https://forum.rasa.com/u/naoko)\
**Post date:** [March 23, 2019, 9:10pm UTC](https://forum.rasa.com/t/mapping-same-entity-to-different-slots/1389/6 "2019-03-23T21:10:32Z")

</div>

@red-frog, when FormAction is executed, it asks slot by slot.  
when `REQUESTED_SLOT` is ‘origin’ then it will run `utter_ask_origin` when `REQUESTED_SLOT` is ‘destination’ then it will run `utter_ask_destination` So mapping of that is already done. Hope this helps!

---

<div class="post-metadata">

**Author:** ![red-frog](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/red-frog/32/2293_2.png) [@red-frog](https://forum.rasa.com/u/red-frog)\
**Post date:** [March 24, 2019, 10:28am UTC](https://forum.rasa.com/t/mapping-same-entity-to-different-slots/1389/7 "2019-03-24T10:28:11Z")

</div>

@naoko yeah, work fine. very Thanks!

---

<div class="post-metadata">

**Author:** ![shanushawan](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@shanushawan](https://forum.rasa.com/u/shanushawan)\
**Post date:** [April 8, 2019, 5:05am UTC](https://forum.rasa.com/t/mapping-same-entity-to-different-slots/1389/8 "2019-04-08T05:05:23Z")

</div>

Continuing the discussion from [Mapping same entity to different slots](http://forum.rasa.com/t/mapping-same-entity-to-different-slots/1389/3):

do i need to call slot\_mapping method in run function. if yes, please tell me how to do that @naoko

---

<div class="post-metadata">

**Author:** ![twittmin](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/twittmin/32/2091_2.png) [@twittmin](https://forum.rasa.com/u/twittmin)\
**Post date:** [June 27, 2019, 4:33am UTC](https://forum.rasa.com/t/mapping-same-entity-to-different-slots/1389/9 "2019-06-27T04:33:50Z")

</div>

What about if my custom action is not a form action? Can i still use the slot\_mapping? It tried and it seems not working.

---

<div class="post-metadata">

**Author:** ![jhzape](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@jhzape](https://forum.rasa.com/u/jhzape)\
**Post date:** [May 31, 2021, 9:07am UTC](https://forum.rasa.com/t/mapping-same-entity-to-different-slots/1389/11 "2021-05-31T09:07:46Z")

</div>

How about giving role attribute to each entity? For instance, I want to fly from [New York]{“entity”: “location”, “role”: “from”} to [Los Angeles]{“entity”: “location”, “role”: “to”}.
