in dvd_generation/simulators/question_generator.py [0:0]
def instantiate_attributes(text, state, template, synonyms, scene_struct, turn_dependencies):
earlier_obj_program = []
if turn_dependencies['object'] == 'earlier_unique':
earlier_obj_program.append({'type': 'track_object', 'inputs': [],
'_output': list(template['used_objects'].keys())})
for name, val in state['vals'].items():
#if val == 'inside' or val == 'covered by':
# pdb.set_trace
if val is None: pdb.set_trace()
if name not in text: continue
original_val = val
if val in synonyms: val = random.choice(synonyms[val])
#if '<A' in name: pdb.set_trace()
if '<A' in name and 'action_remark' in template:
if name not in template['action_remark']: pdb.set_trace()
rm = template['action_remark'][name]
if rm == 'action_verb':
if val == '':
pdb.set_trace()
else:
val = action_to_verb_map[val]
if rm == 'action_verb_singular':
if val == '':
pdb.set_trace()
text = text.replace('that {} at least once'.format(name),'')
else:
val = action_to_verb_singular_map[val]
elif '<A' in name and 'remark' in template:
pdb.set_trace()
# earlier object references
if turn_dependencies['object'] == 'earlier_unique':
if name == template['earlier_unique_obj_node']['side_inputs'][0]:
#ref_phrase = []
val = random.choice(synonyms['<earlier>']) + ' ' + val
if name in template['earlier_unique_obj_node']['side_inputs']:
#ref_phrase.append(val)
if original_val not in ['', 'thing']:
node_type = 'filter_{}'.format(attribute_to_text[strip_attr_key(name)])
program_node = {'type': node_type, 'inputs': [len(earlier_obj_program)-1], 'side_inputs': [original_val]}
earlier_obj_program.append(program_node)
text = text.replace(name, val)
text = ' '.join(text.split())
# update program parameters with reference phrase
if turn_dependencies['object'] == 'earlier_unique':
earlier_obj_program.append({'type': 'unique', 'inputs': [len(earlier_obj_program)-1]})
#ref_phrase = ' '.join(' '.join(ref_phrase).split())
earlier_obj_program = answer_earlier_obj_program(template, earlier_obj_program)
assert earlier_obj_program[-1]['_output'] == template['earlier_unique_obj']
#for n in state['nodes']:
# if n['type'] == 'earlier_obj_ref':
# n['side_inputs'] = [ref_phrase]
# break
return text, earlier_obj_program