in dvd_generation/filters/scene_filters.py [0:0]
def find_relate_filter_options(object_idx,
scene_struct, metadata, template,
unique=False, include_zero=False, with_action=False,
period_idx=-1, trivial_frac=0.1):
options = {}
# TODO: Why object_idx? always int in this case?
#if with_action:
# if '_action_filter_options' not in scene_struct:
# precompute_action_filter_options(scene_struct, metadata, period_idx)
#else:
# if '_filter_options' not in scene_struct:
# precompute_filter_options(scene_struct, metadata)
# TODO: Right now this is only looking for nontrivial combinations; in some
# cases I may want to add trivial combinations, either where the intersection
# is empty or where the intersection is equal to the filtering output.
if with_action:
if template['interval_type'] == 'atomic':
new_period_idx = convert_to_compositional_period_idx(scene_struct, period_idx)
filter_options = scene_struct['_actions_filter_options'][new_period_idx]['during']
else:
filter_options = scene_struct['_filter_options']
trivial_options = {}
for relationship in scene_struct['relationships'][period_idx]:
if relationship in ['above', 'below']:
continue #and not args.above_below_relate: continue
if relationship in ['containing', 'contained']:
continue
related = set(scene_struct['relationships'][period_idx][relationship][object_idx])
for filters, filtered in filter_options.items():
intersection = related & filtered
trivial = (intersection == filtered)
if unique and len(intersection) != 1: continue
if not include_zero and len(intersection) == 0: continue
if trivial:
trivial_options[(relationship, filters)] = sorted(
list(intersection))
else:
options[(relationship, filters)] = sorted(list(intersection))
#pdb.set_trace()
N, f = len(options), trivial_frac
num_trivial = int(round(N * f / (1 - f)))
trivial_options = list(trivial_options.items())
random.shuffle(trivial_options)
for k, v in trivial_options[:num_trivial]:
options[k] = v
return options