How can I extract entity role, entity group from slot - Getting Started with Rasa / Tutorials, Resources & Videos - Rasa Community Forum
How can I extract entity role, entity group from slot
post by kksbell on May 10, 2020
as learning data of nlu.md file,
Give me a [small]{“entity”: “size”, “group”: “1”} pizza with [mushrooms]{“entity”: “topping”, “group”: “1”} and a [large]{“entity”: “size”, “group”: “2”} [pepperoni]{“entity”: “topping”, “group”: “2”}
How can I extract entity role, entity group from tracker slot in knowledge_base?
post by edubrigham on May 31, 2020
Anyone knows a solution for this? Facing same problem.
post by MuraliChandran14 on May 31, 2020
Hi [@edubrigham](https://forum.rasa.com/u/edubrigham)
Eg: Give me a [small]{“entity”: “size”, “group”: “1”} pizza with [mushrooms]{“entity”: “topping”, “group”: “1”} and a [large]{“entity”: “size”, “group”: “2”} [pepperoni]{“entity”: “topping”, “group”: “2”}
use
next(tracker.get_latest_entity_values(entity_type=“size”, entity_group=“1”))
For entity_role
Just the change the entity_group to entity_role
Eg: I am from [USA]{“entity”:“Country”, “role”:“currentlocation”} and want to go to [UK]{“entity”:“Country”, “role”:“destination”}
next(tracker.get_latest_entity_values(entity_type=“Country”, entity_role=“destination”))
post by edubrigham on May 31, 2020
Hi Thank you for the help I’m sorry, but i’m still new to Rasa and i dont know where to adapt the actions to reflect what you wrote. in my nlu.md file i’m declaring training data in the following fashion:
- how much for [4]{“entity”: “itemQty”, “group”: “1”, “role”: “orderItem1”} [beers]{“entity”: “itemName”, “group”: “1”, “role”: “orderItem1”, “value”: “beer”} and [1]{“entity”: “itemQty”, “group”: “2”, “role”: “orderItem2”} [perrier]{“entity”: “itemName”, “group”: “2”, “role”: “orderItem2”, “value”: “spa red”}
- what does it cost for [1]{“entity”: “itemQty”, “group”: “1”, “role”: “orderItem1”} [carlsberg]{“entity”: “itemName”, “group”: “1”, “role”: “orderItem1”} + [2]{“entity”: “itemQty”, “group”: “2”, “role”: “orderItem2”} [latte]{“entity”: “itemName”, “group”: “2”, “role”: “orderItem2”} + [2]{“entity”: “itemQty”, “group”: “3”, “role”: “orderItem3”} [pils]{“entity”: “itemName”, “group”: “3”, “role”: “orderItem3”, “value”: “beer”}
To make the link between entities “itemQty” to “itemType”, i declared the same “group” and “role” to differentiate between multiple orders (order1 , order2 , order3 , etc.) I would like to extract the role value of each entity pair (itemQty+itemName from role=orderItem1), and programmatically print out the value pairs.: ex.
I want 1 coke and 2 Fanta
should print out:
> order1: \[1\]{“entity”: “itemQty”, “group”: “1”, “role”: “orderItem1”} \[coke\]{“entity”: “itemName”, “group”: “1”, “role”: “orderItem1”}
> order2: \[2\]{“entity”: “itemQty”, “group”: “2”, “role”: “orderItem2”} \[Fanta\]{“entity”: “itemName”, “group”: “2”, “role”: “orderItem2”}
My actions.py is based on the original formsbot actions.py file, but i adjusted the names of the entities to reflect the entities i am trying to extract.
post by MuraliChandran14 on May 31, 2020
Hi [@edubrigham](https://forum.rasa.com/u/edubrigham),
Define this in your submit method
a = next(tracker.get_latest_entity_values(entity_type="itemQty",
entity_group = "1", entity_role="orderItem1"))
b = next(tracker.get_latest_entity_values(entity_type="itemName",
entity_group = "1", entity_role="orderItem1"))
dispatcher.utter_message(text=a+b)
a = next(tracker.get_latest_entity_values(entity_type="itemQty",
entity_group = "2", entity_role="orderItem2"))
b = next(tracker.get_latest_entity_values(entity_type="itemName",
entity_group = "2", entity_role="orderItem2"))
dispatcher.utter_message(text=a+b)
post by edubrigham on May 31, 2020
I’m pretty sure I’m doing something wrong! I have followed your instructions and adapted the actions.py (4.7 KB) accordingly:
def submit(
self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict]:
"""Define what the form has to do
after all required slots are filled"""
a = next(tracker.get_latest_entity_values(entity_type="itemQty", entity_group = "1", entity_role="orderItem1"))
b = next(tracker.get_latest_entity_values(entity_type="itemName", entity_group = "1", entity_role="orderItem1"))
print("Order1", a + b)
dispatcher.utter_message(text=a+b)
a = next(tracker.get_latest_entity_values(entity_type="itemQty", entity_group = "2", entity_role="orderItem2"))
b = next(tracker.get_latest_entity_values(entity_type="itemName", entity_group = "2", entity_role="orderItem2"))
print("Order2", a + b)
dispatcher.utter_message(text=a+b)
post by MuraliChandran14 on May 31, 2020
Define this in your submit method
entities = tracker.latest_message['entities']
for e in entities:
if 'itemQty' in e['entity']:
a = next(tracker.get_latest_entity_values(
entity_type=e['entity'], entity_group=e['group'], entity_role=e['role']))
dispatcher.utter_message(a)
if 'itemName' in e['entity']:
b = next(tracker.get_latest_entity_values(
entity_type=e['entity'], entity_group=e['group'], entity_role=e['role']))
dispatcher.utter_message(b)
post by edubrigham on Jun 1, 2020
I really appreciate your help Murali. listen, would you be interested in doing some (paid) dev work? it’s not much, and it is quite simple i’m sure, but those very simple tasks take me an enormous amount of time to find out how to do it. I’m sure you can do all that i need in a couple of hours. What do you think
post by MuraliChandran14 on Jun 1, 2020
Sure. But its hourly basis. If you are okay with it.