43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
import re
|
|
import csv
|
|
|
|
allWer = []
|
|
corrects = 0
|
|
|
|
with open("out.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])
|
|
deletions = int(re.findall('\\d+', line)[2])
|
|
insertions = int(re.findall('\\d+', line)[3])
|
|
|
|
wer = (substitutions + deletions + insertions) / (substitutions + deletions + correct)
|
|
allWer.append(wer)
|
|
|
|
if substitutions == 0 and deletions == 0 and insertions == 0:
|
|
corrects += 1
|
|
|
|
werAvg = sum(allWer) / len(allWer)
|
|
srr = corrects / len(allWer)
|
|
|
|
with open("WerSrrOut.txt", "w") as file:
|
|
file.write("WER average: " + str(werAvg) + '\n' + "Sentence recognition rate: " + str(srr))
|
|
file.close()
|
|
|
|
|
|
x = 0
|
|
|
|
with open("wikiniews_results.tsv", 'r', encoding="utf-8") as insert:
|
|
with open("metrics_results.tsv", 'w', encoding="utf-8") as out:
|
|
file_out = csv.writer(out, delimiter='\t', lineterminator='\n')
|
|
file_in = csv.reader(insert, delimiter='\t')
|
|
|
|
result = []
|
|
|
|
for row in file_in:
|
|
row.append(allWer[x])
|
|
result.append(row)
|
|
x += 1
|
|
|
|
file_out.writerows(result) |