def top_x_meteor(query_dic, mark, x=1):
    """
    Calculate METEOR score of the top result
    :param query_dic: dict, key is qid, value is (item, meteor) tuple list, which will be ranked by 'item' as key
    :param mark: string, which indicates which method is evaluated, also used as output file name here.
    :param x: int, define top x
    :return: average meteor score
    """
    all_total = 0.0
    with open(top_meteor_path + mark, 'w') as writer:
        for k in query_dic:
            candidate_lst = query_dic[k]
            top_x = sorted(candidate_lst, key=lambda a: a[0], reverse=True)[:x]
            total = 0
            for t in top_x:
                total += t[1]
            ave_value = total / x
            writer.write('%s\tAverageBleu:%f\tTop%d:%s\n' % (k, ave_value, x, str(top_x)))

            all_total += ave_value

            # for debug below here
            if k in contrast_dic:
                contrast_dic[k].append(str(ave_value))
            else:
                contrast_dic[k] = []
                contrast_dic[k].append(str(ave_value))
    result_string = '%s\ttop%d_METEOR:\t%f' % (mark, x, all_total / len(query_dic))
    print result_string
    # eval_result_dict['METEOR'].append(result_string)
    return ['METEOR', result_string]
def top_x_meteor ( query_dic , mark , x = 1 ) : all_total = 0.0 with open ( top_meteor_path + mark , 'w' ) as writer : for k in query_dic : candidate_lst = query_dic [ k ] top_x = sorted ( candidate_lst , key = lambda a : a [ 0 ] , reverse = True ) [ : x ] total = 0 for t in top_x : total += t [ 1 ] ave_value = total / x writer . write ( '%s\tAverageBleu:%f\tTop%d:%s\n' % ( k , ave_value , x , str ( top_x ) ) ) all_total += ave_value if k in contrast_dic : contrast_dic [ k ] . append ( str ( ave_value ) ) else : contrast_dic [ k ] = [ ] contrast_dic [ k ] . append ( str ( ave_value ) ) result_string = '%s\ttop%d_METEOR:\t%f' % ( mark , x , all_total / len ( query_dic ) ) print result_string return [ 'METEOR' , result_string ]
Calculate METEOR score of the top result
    :param query_dic: dict, key is qid, value is (item, meteor) tuple list, which will be ranked by 'item' as key
    :param mark: string, which indicates which method is evaluated, also used as output file name here.
    :param x: int, define top x
    :return: average meteor score