s421818-mlworkshops/createWERandSRRFiles.py
2020-04-03 15:42:01 +02:00

58 lines
1.3 KiB
Python

import re
import csv
wer = open("wer.txt","w")
ssr = open("ssr.txt","w")
lastId = ""
globalPercent = 0
counter = 0
ssrCounter = 0
inputLines = ""
werArray = []
with open("helper.txt", "r") as f:
for line in f:
if re.match(r'^id:.*', line):
lastId = line.replace("\n", "")
elif re.match(r'^Scores:.*', line):
helper = line.replace("Scores: (#C #S #D #I) ", "").split()
sum = int(helper[0]) + int(helper[1]) + int(helper[2]) + int(helper[3])
sum = ((float(helper[0]))/(float(sum))) * 100
if (sum == 100):
ssrCounter += 1
globalPercent += sum
counter += 1
werArray.append(sum)
wer.write(lastId + " = " + str(sum) + "%\n")
wer.write("AVG: " + str(float((globalPercent) / (float(counter) * 100)*100)) + "%")
ssr.write(str(float(ssrCounter)/float(counter) * 100) + "%")
wer.close()
ssr.close()
with open('wikiniews_results.tsv','r') as f_in:
with open('wikiniews_resultsWithAdditionalColumn.tsv', 'w') as f_out:
writer = csv.writer(f_out, delimiter=' ', lineterminator='\n')
reader = csv.reader(f_in, delimiter=' ')
result = []
# read headers
row = next(reader)
# add new header to list of headers
row.append('Col5')
result.append(row)
cc = 0
for row in reader:
# add new column values
row.append(werArray[cc])
cc += 1
result.append(row)
writer.writerows(result)