I followed this tutorial to write a simple script using Wit.ai.
So, there is a code snippet which retrieves the entity from the first message:
def first_entity_value(entities, entity):
if entity not in entities:
return None
val = entities[entity][0]['value']
if not val:
return None
return val['value'] if isinstance(val, dict) else val
I have two questions:
- How can I get entities from the other messages? So, when user type something (not as a first message)?
I have multiple entities in the message (e.g: I'm gonna visit London this weekend), how can I get, for example, the second entity (weekend)? Now I tried to write something like the following but got an error:
def first_entity_value(entities, entity): if entity not in entities: return None val = entities[entity][0][1]['value'] # to get the second entity if not val: return None return val['value'] if isinstance(val, dict) else val