Add python script
This commit is contained in:
parent
bceebd3fd6
commit
a8b0be7939
49
count.py
49
count.py
@ -0,0 +1,49 @@
|
||||
import re
|
||||
import fileinput
|
||||
import csv
|
||||
|
||||
wars = []
|
||||
|
||||
corrects=0
|
||||
|
||||
|
||||
with open("results.txt", "r", encoding='utf-8') as results:
|
||||
for line in results:
|
||||
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 / len(wars)
|
||||
|
||||
war_avg = sum(wars) / len(wars)
|
||||
|
||||
with open("wer_avg.txt", "w+") as wer_avg_file:
|
||||
wer_avg_file.write("WER avg: %s", str(war_avg))
|
||||
|
||||
with open("srr.txt", "w+") as srr_file:
|
||||
srr_file.write("SRR: %s", str(srr))
|
||||
|
||||
with open("wer_srr.txt", "w+") as wer_srr:
|
||||
wer_srr.write("SRR: %s \n WER avg: %s", str(srr), 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:
|
||||
row.append(wars[counter])
|
||||
result.append(row)
|
||||
counter=counter+1
|
||||
|
||||
writer.writerows(result)
|
Loading…
Reference in New Issue
Block a user