forked from shibing624/python-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluate.py
More file actions
49 lines (38 loc) · 1.35 KB
/
evaluate.py
File metadata and controls
49 lines (38 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from config import test_result_path
from config import test_gold_path
class Evaluate():
def __init__(self):
pass
def evaluate(self):
test_result_file = open(test_result_path, encoding='utf-8')
test_gold_file = open(test_gold_path, encoding='utf-8')
result_cnt = 0.0
gold_cnt = 0.0
right_cnt = 0.0
for line1, line2 in zip(test_result_file, test_gold_file):
result_list = line1.strip().split(' ')
gold_list = line2.strip().split(' ')
for words in gold_list:
if words != '':
gold_list.remove(words)
for words in gold_list:
if words != '':
result_list.remove(words)
result_cnt += len(result_list)
gold_cnt += len(gold_list)
for words in result_list:
if words in gold_list:
right_cnt += 1.0
gold_list.remove(words)
p = right_cnt / result_cnt
r = right_cnt / gold_cnt
F = 2.0 * p * r / (p + r + 1)
print('right_cnt: \t\t', right_cnt)
print('result_cnt: \t', result_cnt)
print('gold_cnt: \t\t', gold_cnt)
print('P: \t\t', p)
print('R: \t\t', r)
print('F: \t\t', F)
if __name__ == '__main__':
E = Evaluate()
E.evaluate()