poprawki do obliczania metryk 1

This commit is contained in:
alicja.m.musial 2020-04-03 16:03:30 +02:00
parent 1e91f2142b
commit 30505a960f
2 changed files with 28 additions and 15 deletions

View File

@ -1,18 +1,30 @@
import sys
if __name__ == '__main__':
wer = 0
sentenceNumber = 0
correctSentence = 0
with open(sys.argv[1],'r') as x, \
open(wer.txt,'a+') as werOut, \
open(srr.txt,'a+') as srrOut:
x = open(werWIP.txt,"r")
y = open(wer.txt,"w")
lines = x.readlines()
for line in lines:
line = lines.split(" ")
c = line[0]
s = line[1]
d = line[2]
i = line[3]
countWER(c,s,d,i)
y.write(countWER)
for line in x:
done = False
lines = line.split(" ")
sentenceNumber += 1
float(c) = line[0]
float(s) = line[1]
float(d) = line[2]
float(i) = line[3]
wer = (s + d + i)/(s + d + c)
done = True
if done:
werOut.write(f'{wer:.5f}\n')
if wer == 0:
correctSentence +=1
def countWER(c,s,d,i):
wer = (s + d + i)/(s + d + c)
return wer
srr = correctSentence / sentenceNumber
srrOut.write(f'{srr:.5f}\n')

View File

@ -8,4 +8,5 @@ awk 'BEGIN{FS=OFS="\t"}{print $0,"(sp1_"NR")"}' < hypothesis.txt > hypothesis.tr
sclite -f 0 -r reference.trn trn -h hypothesis.trn trn -e utf-8 -i rm -o all stdout | grep "Scores:" | sed 's/Scores: (#C #S #D #I) //' > werWIP.txt
python ./WERcreator.py
python3 metrics.py werWIP.txt
paste werWIP.txt wer.txt > tmp.txt && mv tmp.txt results.txt