in mm_action_prediction/tools/extract_actions.py [0:0]
def gen_addtocart_from_annotation(round_datum, reversed_dialog_coref_map):
""" Generate ADD_TO_CART_ACTIONs inferred based on NLU/NGL annotation.
Args:
round_datum: user-assistant turn-pair, including annotations
reversed_dialog_coref_map: maps per dialog object ids to furniture ids
Returns:
list of inferred ADD_TO_CART_ACTIONs for this turn.
"""
intents = data_support.get_intents(data_support.ASSISTANT, round_datum)
for intent in intents:
if (
"DA:CONFIRM:ADD_TO_CART" in intent
or "DA:INFORM:ADD_TO_CART" in intent
):
system_action_refs = data_support.get_object_references(
round_datum['system_turn_label'],
reversed_dialog_coref_map
)
user_action_refs = data_support.get_object_references(
round_datum['turn_label'],
reversed_dialog_coref_map
)
furniture_id = []
# check for object reference(s) that accompanies the assistant action
for act, refs in system_action_refs.items():
if 'ADD_TO_CART' in act and refs:
furniture_id = [r[1] for r in refs]
break
# if object reference missing for assistant action, check if
# preceding user action mentions ADD_TO_CART and has object refs
if not furniture_id:
for act, refs in user_action_refs.items():
if 'ADD_TO_CART' in act and refs:
furniture_id = [r[1] for r in refs]
new_action = {
API: ADD_TO_CART_ACTION,
PREVIOUS_STATE: None,
NEXT_STATE: None,
ARGS: {
FURNITURE_ID: furniture_id
}
}
# only expect one add-to-cart per turn
return [new_action]
return []