Пример #1
0
def query_parse(show_name, episode_num, query): # arbitrary name
    # caching of 3 queries for faster retrieval can be done here...
    global shot_timestamps, video_descr, shots_list
    print "Searching through episode number :", episode_num
    episode_name = video_file_names[show_name][episode_num]
    result = preprocessor.similarity_fn1(time_stamps[show_name][episode_name], sub_to_shot[show_name][episode_name], idf[show_name][episode_name], tf_idf[show_name][episode_name], plot_sentences[show_name][episode_name], plot_to_sub[show_name][episode_name], sub_text[show_name][episode_name], raw_sub_text[show_name][episode_name], plot_to_shot[show_name][episode_name], query)
    shot_timestamps = result['shot_timestamps']
    video_descr = result['video_descr']
    shots_list, max_sim1 = result['shots_list'], result['max_sim']
    if (shot_timestamps == -1):
        redirect('/search/'+show_name+'/'+str(episode_num)+'/query/NaQ')
    #print len(shot_timestamps), len(shots_list)
    #raw_input('wait here')
    # max sim sentence is a number
    max_sim2, max_sim_sentence = preprocessor.similarity_fn2(action_stamps[show_name][episode_name], query)
    u = action_stamps[show_name][episode_name][max_sim_sentence]
    a_shot_timestamp, a_video_descr = u[1][0], ' '.join(u[0])
    try:# or if no results
        if max_sim2 >= max_sim1:
            shot_timestamps[0] = a_shot_timestamp
            video_descr[0] = a_video_descr
            print 'replace hua!', max_sim2
    except:
        print 'No replace'
    print "The values are", shot_timestamps, video_descr
    if ((shot_timestamps, video_descr) == (-1, -1)):
        redirect('/search/'+show_name+'/'+str(episode_num)+'/query/NaQ')
    if (len(shot_timestamps) >= 3):
        redirect('/search/'+show_name+'/'+str(episode_num)+'/query/0')
    elif (len(shot_timestamps) != 0):  # lies between 0 and 3
        redirect('/search/'+show_name+'/'+str(episode_num)+'/query/single')
    elif (len(shot_timestamps) == 0):  # replace with else
        redirect('/search/'+show_name+'/'+str(episode_num)+'/query/NaQ')
Пример #2
0
        with open(sub_to_shot_path, "w") as fp1:
            sub_to_shot[index] = sub_shot_assigner(sub_stamps[index], scene_stamps[index])
            json.dump(sub_to_shot[index], fp1)

plot_to_shot = [None for i in range(no_episodes)]
for index, vid_file in enumerate(file_names):
    # storing the processed part in json
    plot_to_shot_path = DIR_PLOTSHOT + "/" + vid_file + "_proc_plotshot.json"
    try:
        with open(plot_to_shot_path, "r") as fp1:
            plot_to_shot[index] = json.load(fp1)
    except IOError:
        with open(plot_to_shot_path, "w") as fp1:
            plot_to_shot[index] = plot_shot_assigner(plot_to_sub[index], sub_to_shot[index])
            json.dump(plot_to_shot[index], fp1)

shot_timestamps, video_descr, shots_list = None, None, None
episode_num, query = 1, "jimmy"
shot_timestamps, video_descr, shots_list = similarity_fn1(
    time_stamps[episode_num - 1],
    sub_to_shot[episode_num - 1],
    idf[episode_num - 1],
    tf_idf[episode_num - 1],
    plot_sentences[episode_num - 1],
    plot_to_sub[episode_num - 1],
    sub_text[episode_num - 1],
    untouched_sub_text[episode_num - 1],
    plot_to_shot[episode_num - 1],
    query,
)