in dvd_generation/filters/dialogue_filters.py [0:0]
def find_all_unique_objects(dialogue, template, scene_struct, used_objects):
template['sampled_ans_object'] = -1
if len(dialogue)==0:
template['used_objects'] = {}
template['ans_objects'] = []
return
last_turn = dialogue[-1]
last_turn_dependencies = last_turn['turn_dependencies']
prior_state = last_turn['state']
last_template = last_turn['template']
prior_objs = last_template['all_unique_objs']
prior_ans_obj = last_template['answer_obj']
last_period = last_template['used_periods'][-1]
curr_turn_pos = len(dialogue)
template['ans_objects'] = []
found_unique_ans = False
# Case 1: previous dialogue turn is an exist (e.g. Is there...) or count (e.g. How many...)
if prior_ans_obj is not None and (last_turn['answer']):
obj_id, obj_attr, obj_ids = find_unique_answer_obj(last_turn, prior_state, prior_ans_obj)
if obj_id!=-1:
update_unique_object(obj_id, obj_attr, used_objects, curr_turn_pos)
found_unique_ans = True
template['ans_objects'] = obj_ids
#find_answer_objs(last_turn, prior_state, prior_ans_obj)
# Case 2: the unique object came from temporal dependency
if last_template['interval_type']!='none' and 'none' in last_turn_dependencies['temporal'] \
and last_turn_dependencies['spatial']=='none':
e1, e2 = last_period
if e1 is not None or e2 != last_template['cutoff']:
if last_template['temporal_obj_attr'] is not None:
update_unique_object(last_template['temporal_obj_id'],
last_template['temporal_obj_attr'], used_objects, curr_turn_pos)
#if last_template['temporal_obj_attr_2'] is not None:
# update_unique_object(last_template['temporal_obj_id_2'],
# last_template['temporal_obj_attr_2'], used_objects, curr_turn_pos)
'''
e1, e2 = last_period
found_unique = False
if e1 is not None:
obj_id = e1[0]
found_unique = True
elif e2 != template['cutoff']:
obj_id = e2[0]
found_unique = True
if found_unique:
if 'temporal_obj_attr' not in last_template:
pdb.set_trace()
update_unique_object(obj_id, last_template['temporal_obj_attr'], used_objects)
'''
# Case 3: all other unique objects from the last turn
if last_turn_dependencies['attribute'] != 'none':
obj_id = prior_state['nodes'][0]['_output']
attr_type = node_type_to_attribute[last_turn_dependencies['attribute']]
attr = prior_state['nodes'][1]['_output']
obj_attr = {}
obj_attr[attr_type] = attr
update_unique_object(obj_id, obj_attr, used_objects, curr_turn_pos)
else:
for o in prior_objs:
obj_id, obj_attr = find_unique_obj(last_turn, prior_state, o)
update_unique_object(obj_id, obj_attr, used_objects, curr_turn_pos)
# Case 4: sample an object from a count (e.g. How many...) where result > 1 (among them, there is a...)
if prior_ans_obj is not None and not found_unique_ans:
obj_ids, obj_id, obj_attr, sampled_obj_attr = sample_unique_answer_obj(last_turn, prior_state, prior_ans_obj, used_objects, scene_struct)
if obj_id != -1:
#update_unique_object(obj_id, obj_attr, used_objects)
template['sampled_ans_object_attr_ref'] = obj_attr
template['prior_ans_object_group'] = obj_ids
template['sampled_ans_object'] = obj_id
template['sampled_ans_object_attr'] = sampled_obj_attr
template['used_objects'] = copy.deepcopy(used_objects)
return