-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathevaluate.py
More file actions
41 lines (37 loc) · 912 Bytes
/
evaluate.py
File metadata and controls
41 lines (37 loc) · 912 Bytes
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
from __future__ import division
import os
import sys
import linecache
if __name__ == "__main__":
if len(sys.argv) != 3:
print "Usage: python evaluate.py inputfile goldfile"
exit(0)
infile = sys.argv[1]
goldfile = sys.argv[2]
count = 1
count_right = 0
count_split = 0
count_gold = 0
f = file(infile)
for line in f:
inlist = line.strip().decode('utf-8').split(' ')
goldlist = linecache.getline(goldfile, count).strip().decode('utf-8').split(' ')
count += 1
count_split += len(inlist)
count_gold += len(goldlist)
tmp_in = inlist
tmp_gold = goldlist
for key in tmp_in:
if key in tmp_gold:
count_right += 1
tmp_gold.remove(key)
f.close()
print "count_right", count_right
print "count_gold", count_gold
print "count_split", count_split
p = count_right / count_split
r = count_right / count_gold
F = 2 * p * r /(p + r)
print "p:", p
print "r:", r
print "F:", F