import sys

score = []
bundary = 20000000
for i in range(8):
    score.append(open("id_score%d.txt"%i, 'r', encoding="utf-8"))
zh = open("../yatrans_zh2en/data_zh2en.zh.ratio.bpe.dul",'r',encoding="utf-8")
en = open("../yatrans_zh2en/data_zh2en.en.ratio.bpe.dul",'r',encoding="utf-8")
fw = open("data2score.txt",'w',encoding="utf-8")
index2score = {}
for i in range(8):
    for line in score[i].readlines():
        line = line.strip().replace('\n', '').split('\t')
        index2score[i*bundary+int(line[0])] = float(line[1])

sorted_list = sorted(index2score.items(),key=lambda x:x[1],reverse=True)

zh_list = zh.readlines()
en_list = en.readlines()

for item in sorted_list:
    fw.write(zh_list[item[0]].replace('\n','').replace('@@ ','')+'\t'+en_list[item[0]].replace('\n','').replace('@@ ','')+'\t'+str(item[1])+'\n')






