def instantiate_last_unique_obj_dependency()

in dvd_generation/simulators/question_generator.py [0:0]


def instantiate_last_unique_obj_dependency(text, state, template, synonyms, scene_struct, turn_dependencies):
    last_obj_program = []
    if turn_dependencies['object'] == 'last_unique': 
        if template['sampled_ans_object']!=-1:
            ans_obj_attr = template['sampled_ans_object_attr']
            attr_str = []
            last_obj_program.append({'type': 'refer_object', 'inputs': [],
                                    'side_inputs': ['them'], 
                                    '_output': template['prior_ans_object_group']})
            for name, val in ans_obj_attr.items():
                if val not in ['', 'thing']:
                    node_type = 'filter_{}'.format(attribute_to_text[name])
                    program_node = {'type': node_type, 'inputs': [len(last_obj_program)-1], 'side_inputs': [val]}
                    last_obj_program.append(program_node)
                if val in synonyms: 
                    val = random.choice(synonyms[val])
                attr_str.append(val)
            if '<S>' not in ans_obj_attr:
                attr_str.append('thing')
            modifier_text = 'Among them , there is a {} . '.format(' '.join(attr_str))
            
            last_obj_program.append({'type': 'unique', 'inputs': [len(last_obj_program)-1]})
            last_obj_program = answer_scene_obj_program(last_obj_program, scene_struct)
            assert last_obj_program[-1]['_output'] == template['sampled_ans_object']
            
        elif template['interval_type'] != 'none':
            modifier_text = '{} {} {} , '.format(random.choice(synonyms['<link>']),
                                                 random.choice(synonyms['<given>']), 
                                                 random.choice(synonyms['<it>']))
        else:
            modifier_text = '{} '.format(random.choice(synonyms['<link>']))
        text = modifier_text + text 

        if template['interval_type'] != 'none':
            replace_text = 'it'
        else:
            replace_text = random.choice(synonyms['<it>'])
        unique_text = ' '.join(template['unique_obj'][1]['side_inputs'])
        text = text.replace('the ' + unique_text, replace_text)
        text = text.replace('The ' + unique_text, replace_text)
        # update program parameters with reference phrase
        for n_idx, n in enumerate(state['nodes']):
            if n['type'] == 'unique_obj_ref':
                n['side_inputs'] = [replace_text]
                unique_obj_n_idx = n_idx 
                break
        '''
        # among objects  
        if template['sampled_ans_object']!=-1:
            prior_obj_group = template['prior_ans_object_group']
            new_nodes = []
            new_nodes.append({'type': 'earlier_obj_ref', 'inputs': [unique_obj_n_idx-1], 
                        '_output': prior_obj_group, 'side_inputs': ['them']})
            for atrr in identifier_attrs:
                if attr in template['sampled_ans_object_attr']:
                    param_val = template['sampled_ans_object_attr'][attr]
                    node_type = attribute_to_node_type[attr]
                    pdb.set_trace()
        '''
    return text, last_obj_program