55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
import re
|
|
import fileinput
|
|
import csv
|
|
wars = []
|
|
corrects=0
|
|
with open("results.txt", "r", encoding='utf-8') as ins:
|
|
for line in ins:
|
|
if line.startswith('Scores'):
|
|
correct = int(re.findall('\d+', line)[0])
|
|
substitutions = int(re.findall('\d+', line)[1])
|
|
deletes = int(re.findall('\d+', line)[2])
|
|
inserts = int(re.findall('\d+', line)[3])
|
|
war = (substitutions+deletes+inserts)/(substitutions+deletes+correct)
|
|
wars.append(war)
|
|
if substitutions==0 and deletes==0 and inserts==0:
|
|
corrects = corrects + 1
|
|
|
|
srr = corrects / sum(wars)
|
|
print(srr)
|
|
|
|
war_avg = sum(wars) / len(wars)
|
|
print(war_avg)
|
|
with open("wer_avg.txt", "w") as wer_avg_file:
|
|
wer_avg_file.write("WER avg: ")
|
|
wer_avg_file.write(str(war_avg))
|
|
with open("srr.txt", "w") as srr_file:
|
|
srr_file.write("SRR: ")
|
|
srr_file.write(str(srr))
|
|
|
|
with open("wer_srr.txt", "w") as wer_srr:
|
|
wer_srr.write("SRR: ")
|
|
wer_srr.write(str(srr))
|
|
wer_srr.write("\n")
|
|
wer_srr.write("WER avg: ")
|
|
wer_srr.write(str(war_avg))
|
|
|
|
|
|
counter = 0;
|
|
with open("wikiniews_results.tsv",'r', encoding="utf-8") as wik_in:
|
|
with open("result.tsv",'w', encoding="utf-8") as f_out:
|
|
writer = csv.writer(f_out, delimiter='\t', lineterminator='\n')
|
|
reader = csv.reader(wik_in, delimiter='\t')
|
|
|
|
result = []
|
|
|
|
for row in reader:
|
|
# add new column values
|
|
row.append(wars[counter])
|
|
result.append(row)
|
|
counter=counter+1
|
|
|
|
writer.writerows(result)
|
|
|
|
|