def sample_unique_answer_action()

in dvd_generation/utils/dialogue_utils.py [0:0]


def sample_unique_answer_action(dialogue, scene_struct, prior_period, cutoff): 
    tag = ''
    if dialogue[-1]['program'][-1]['type']=='query_action_order' and dialogue[-1]['answer']!='no action':
        obj_idx = dialogue[-1]['program'][dialogue[-1]['program'][-1]['inputs'][0]]['_output']
        movements = scene_struct['movements'][scene_struct['objects'][obj_idx]['instance']]
        action = dialogue[-1]['answer']
        action_order = dialogue[-1]['program'][-1]['side_inputs'][0] 
        if action_order != 'last':
            action_order = reverse_ordinal_map[action_order]
        count = 0 
        all_counts = {}
        found = False 
        for movement in movements:
            a, _, s, e = movement
            if a == '_no_op': continue 
            mapped_a = action_map[a]
            if mapped_a not in all_counts: all_counts[mapped_a] = 0
            all_counts[mapped_a] += 1 
            
            prior_s = prior_period[0][-1] if prior_period[0] is not None else 0
            prior_e = prior_period[1][-1] if prior_period[1] is not None else len(scene_struct['objects'][0]['locations'])-1
            if is_overlap(s,e, prior_s, prior_e, return_overlap=True)>overlap_threshold:
                count += 1 
                e1 = (obj_idx, 'start_'+ mapped_a, all_counts[mapped_a], movement[2])
                e2 = (obj_idx, 'end_'+ mapped_a, all_counts[mapped_a], movement[3])
                found = True 
                
            if action_order!='last' and count == action_order:
                if cutoff is None or (cutoff is not None and e2[-1]<=cutoff[-1]): 
                    prior_period = (e1, e2) 
                    tag = 'prior_{}_'.format(action)
                break        
                
        if action_order == 'last':
            if not found: pdb.set_trace()
            if cutoff is None or (cutoff is not None and e2[-1]<=cutoff[-1]): 
                prior_period = (e1, e2) 
                tag = 'prior_{}_'.format(action)
    return tag, prior_period