petite-difference-challenge2/eval.py
2022-04-23 09:58:35 +02:00

34 lines
986 B
Python

import csv
def flatten(t):
return [item for sublist in t for item in sublist]
with open('./result.txt', mode='r', encoding='utf-8') as result:
with open('./train/expected.tsv', 'r', encoding="utf8") as expected:
result_vector = []
expected_vector = []
tsv_result = csv.reader(result, delimiter="\t")
for line in tsv_result:
result_vector.append(line)
tsv_expected = csv.reader(expected, delimiter="\t")
for line in tsv_expected:
expected_vector.append(line)
expected_vector = flatten(expected_vector)
result_vector = flatten(result_vector)
resultZip = zip(result_vector, expected_vector)
matchNumber = 0.0
for x,y in resultZip:
if x == y:
matchNumber += 1.0
print(matchNumber/len(expected_vector))