plot_to_sub[show] = {} idf[show] = {} tf_idf[show] = {} for show in list_of_shows: for episode_name in video_file_names[show]: plot_to_sub_path = DIR_PLTSUB[show]+'/'+episode_name+'_proc_pltsub.json' idf_path = DIR_PLTSUB[show]+'/'+episode_name+'_idf.json' tf_idf_path = DIR_PLTSUB[show]+'/'+episode_name+'_tf_idf.json' try: with open(plot_to_sub_path, 'r') as fp1, open(idf_path, 'r') as fp2, open(tf_idf_path, 'r') as fp3: plot_to_sub[show][episode_name] = json.load(fp1) idf[show][episode_name] = json.load(fp2) tf_idf[show][episode_name] = {int(k):v for k,v in json.load(fp3).items()} except IOError: result = preprocessor.plot_sub_assigner(plot_sentences[show][episode_name], sub_text[show][episode_name]) plot_to_sub[show][episode_name] = result['plot_to_sub'] idf[show][episode_name] = result['idf'] tf_idf[show][episode_name] = result['tf_idf'] with open(plot_to_sub_path, 'w') as fp1, open(idf_path, 'w') as fp2, open(tf_idf_path, 'w') as fp3: json.dump(plot_to_sub[show][episode_name], fp1) json.dump(idf[show][episode_name], fp2) json.dump(tf_idf[show][episode_name], fp3) # subtitle to shot mapping sub_to_shot = {} for show in list_of_shows: sub_to_shot[show] = {} for show in list_of_shows: for episode_name in video_file_names[show]:
# will work for the first time plot_to_sub = [None for i in range(no_episodes)] idf = [None for i in range(no_episodes)] tf_idf = [None for i in range(no_episodes)] for index, vid_file in enumerate(file_names): plot_to_sub_path = DIR_PLTSUB + "/" + vid_file + "_proc_pltsub.json" idf_path = DIR_PLTSUB + "/" + vid_file + "_idf.json" tf_idf_path = DIR_PLTSUB + "/" + vid_file + "_tf_idf.json" try: with open(plot_to_sub_path, "r") as fp1, open(idf_path, "r") as fp2, open(tf_idf_path, "r") as fp3: plot_to_sub[index] = json.load(fp1) idf[index] = json.load(fp2) tf_idf[index] = {int(k): v for k, v in json.load(fp3).items()} except IOError: with open(plot_to_sub_path, "w") as fp1, open(idf_path, "w") as fp2, open(tf_idf_path, "w") as fp3: t1, t2, t3 = plot_sub_assigner(plot_sentences[index], sub_text[index]) plot_to_sub[index], idf[index], tf_idf[index] = t1, t2, t3 json.dump(plot_to_sub[index], fp1) json.dump(idf[index], fp2) json.dump(tf_idf[index], fp3) sub_to_shot = [None for i in range(no_episodes)] for index, vid_file in enumerate(file_names): # storing the processed part in json sub_to_shot_path = DIR_SUBSHOT + "/" + vid_file + "_proc_subshot.json" try: with open(sub_to_shot_path, "r") as fp1: sub_to_shot[index] = json.load(fp1) except IOError: with open(sub_to_shot_path, "w") as fp1: sub_to_shot[index] = sub_shot_assigner(sub_stamps[index], scene_stamps[index])