Rasa: Extracting duckling additional_information from tracker

Created on 2 May 2018  路  7Comments  路  Source: RasaHQ/rasa

Rasa Core version: 0.8.5

Python version: 3.6

Operating system (windows, osx, ...): OSX

Issue:

How can we retrieve additional_information extracting by duckling?

Example, we have this sentence:

I want to book vacation for the whole next week

Which rasa transform with duckling to

{'entities': [{'additional_info': {'grain': 'week',
                                   'others': [{'grain': 'week',
                                               'value': '2018-05-07T00:00:00.000Z'}],
                                   'value': '2018-05-07T00:00:00.000Z'},
               'end': 47,
               'entity': 'time',
               'extractor': 'ner_duckling',
               'start': 38,
               'text': 'next week',
               'value': '2018-05-07T00:00:00.000Z'}],
....

We have defined an entity named time with type unfeaturized, which works when using tracker.get_slot('time') however, we would like to have access to grain value to understand if user meant the whole week or just one day.

Thank you,

Most helpful comment

@akelad
I want to extract the entities from given sentence in my custom action, the code you mentioned above is showing error.
can you help me with that.

 time_entity = next((e for e in tracker.latest_message.entities if
                                 e['entity'] == 'time'), None)
AttributeError: 'dict' object has no attribute 'entities'

time_entity = next((e for e in tracker.latest_message.entities if e['entity'] == 'time'), None)

Getting same issue. @azizullah2017 did you create new issue which already have answer for this problem?

Problem is solved, you can use any of the these, to extract the entities. no need to open new issue.

ent = next(tracker.get_latest_entity_values("entity_name"), None) 
ent = tracker.latest_message['entities'][0]['value']
ent = tracker.latest_message['entities']

All 7 comments

You would do this in a custom action, with something like:

time_entity = next((e for e in tracker.latest_message.entities if
                                 e['entity'] == 'time'), None)

this should give you all the information above and then you can extract what you want, and set the slot accordingly by returning [SlotSet('slot_name','slot_value')]

that should work, will try and let you know.

Worked like a charm, thanks, closing the issue.

@akelad
I want to extract the entities from given sentence in my custom action, the code you mentioned above is showing error.
can you help me with that.

 time_entity = next((e for e in tracker.latest_message.entities if
                                 e['entity'] == 'time'), None)
AttributeError: 'dict' object has no attribute 'entities'

time_entity = next((e for e in tracker.latest_message.entities if e['entity'] == 'time'), None)

Please create a new issue

@akelad
I want to extract the entities from given sentence in my custom action, the code you mentioned above is showing error.
can you help me with that.

 time_entity = next((e for e in tracker.latest_message.entities if
                                 e['entity'] == 'time'), None)
AttributeError: 'dict' object has no attribute 'entities'

time_entity = next((e for e in tracker.latest_message.entities if e['entity'] == 'time'), None)

Getting same issue. @azizullah2017 did you create new issue which already have answer for this problem?

@akelad
I want to extract the entities from given sentence in my custom action, the code you mentioned above is showing error.
can you help me with that.

 time_entity = next((e for e in tracker.latest_message.entities if
                                 e['entity'] == 'time'), None)
AttributeError: 'dict' object has no attribute 'entities'

time_entity = next((e for e in tracker.latest_message.entities if e['entity'] == 'time'), None)

Getting same issue. @azizullah2017 did you create new issue which already have answer for this problem?

Problem is solved, you can use any of the these, to extract the entities. no need to open new issue.

ent = next(tracker.get_latest_entity_values("entity_name"), None) 
ent = tracker.latest_message['entities'][0]['value']
ent = tracker.latest_message['entities']
Was this page helpful?
0 / 5 - 0 ratings

Related issues

anishrav picture anishrav  路  3Comments

connorbrinton picture connorbrinton  路  3Comments

lomarceau picture lomarceau  路  3Comments

karnigili picture karnigili  路  3Comments

nicolasfarina picture nicolasfarina  路  3Comments