in dvd_generation/filters/dialogue_filters.py [0:0]
def is_valid_dialogue(dialogue, scene_struct):
nb_dependencies = {'all': 0, 'temporal': 0, 'object': 0, 'attribute': 0, 'spatial': 0}
nb_contains = 0
nb_amongs = 0
nb_spatial = 0
nb_cutoff = 0
nb_freq_seq_q = 0
#nb_excluding = 0
found_diff_ans_after_cutoff = False
for t_idx, t in enumerate(dialogue):
curr_dependencies = t['turn_dependencies']
if len([d for d in curr_dependencies.values() if d!='none']) > 0:
nb_dependencies['all'] += 1
nb_dependencies['object'] += 1 if (curr_dependencies['object']!='none' or \
'unique' in curr_dependencies['temporal']) else 0
nb_dependencies['temporal'] += 1 if curr_dependencies['temporal']!='none'else 0
nb_dependencies['attribute'] += 1 if 'none' not in curr_dependencies['attribute'] else 0
nb_dependencies['spatial'] += 1 if 'none' not in curr_dependencies['spatial'] else 0
if 'contain' in t['question']:
nb_contains += 1
if 'one_hop' in t['template_filename']:
nb_spatial += 1
if curr_dependencies['temporal'] == 'video_update':
nb_cutoff += 1
curr_ans = t['answer']
prior_ans = dialogue[t_idx-1]['answer']
if curr_ans != prior_ans:
found_diff_ans_after_cutoff = True
if 'among' in t['question']:
nb_amongs += 1
if t['template_filename'] == 'zero_hop_5.json' and t['question_family_index'] in [12,13]:
nb_freq_seq_q += 1
#if curr_dependencies['temporal'] == 'excluding':
# nb_excluding += 1
#print(nb_contains, nb_spatial, nb_cutoff, nb_amongs, found_diff_ans_after_cutoff)
#print(nb_dependencies)
match = 0
if nb_amongs>0: match += 1
#if (not scene_struct['has_contain'] or nb_contains>0): match += 1
if found_diff_ans_after_cutoff: match += 1
#if nb_freq_seq_q>0: match += 1
#if nb_dependencies['object']>5: match += 1
if nb_dependencies['temporal']>=len(dialogue)*0.3: match += 1
#if nb_dependencies['attribute']>0: match += 1
if nb_dependencies['spatial']>0: match += 1
if nb_dependencies['all']>=len(dialogue)-1: match += 1
if match == 5:
return True
return False