49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
![]() |
|
||
|
def collect_csdi(file):
|
||
|
with open(file, encoding="utf-8") as f:
|
||
|
# print(f)
|
||
|
scores = None
|
||
|
id = None
|
||
|
res = {}
|
||
|
for line in f:
|
||
|
if line.find("Scores: ") == 0:
|
||
|
#correct line, lets collect results:
|
||
|
scores = list(map(int, line[22:].split()))
|
||
|
# print(scores)
|
||
|
res[id] = scores
|
||
|
|
||
|
if line.find("id: ") == 0:
|
||
|
id = line[4:]
|
||
|
# print(id)
|
||
|
|
||
|
return res
|
||
|
|
||
|
def print_WRR_for_sentences(csdi_dict):
|
||
|
for key, val in csdi_dict.items():
|
||
|
#( # C #S #D #I)
|
||
|
C = val[0]
|
||
|
S = val[1]
|
||
|
D = val[2]
|
||
|
I = val[3]
|
||
|
WRR = (S+D+I) / (S+D+C)
|
||
|
#print(C,S,D,I)
|
||
|
print(key,WRR,sep="\t")
|
||
|
|
||
|
|
||
|
def print_SRR_for_ASR(csdi_dict):
|
||
|
correct = 0
|
||
|
all = 0
|
||
|
for key, val in csdi_dict.items():
|
||
|
#( # C #S #D #I)
|
||
|
C = int(val[0])
|
||
|
S = int(val[1])
|
||
|
D = int(val[2])
|
||
|
I = int(val[3])
|
||
|
all+=1
|
||
|
if C > 0 and S == 0 and D == 0 and I == 0:
|
||
|
correct += 1
|
||
|
print(correct / all)
|
||
|
if __name__ == "__main__":
|
||
|
csdi_dict = collect_csdi("hypothesis.trn.pra")
|
||
|
print_WRR_for_sentences(csdi_dict)
|
||
|
print_SRR_for_ASR(csdi_dict)
|