forked from bennokr/wdps
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscore.py
34 lines (29 loc) · 923 Bytes
/
score.py
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
import sys
gold_file = sys.argv[1]
pred_file = sys.argv[2]
# Load the gold standard
gold = {}
for line in open(gold_file):
record, string, entity = line.strip().split('\t', 2)
gold[string] = entity
# gold[(record, string)] = entity
n_gold = len(gold)
print('gold: %s' % n_gold)
# Load the predictions
pred = {}
for line in open(pred_file):
record, string, entity = line.strip().split('\t', 2)
pred[string] = entity
# pred[(record, string)] = entity
n_predicted = len(pred)
print('predicted: %s' % n_predicted)
# Evaluate predictions
n_correct = sum( int(pred[i]==gold[i]) for i in set(gold) & set(pred) )
print('correct: %s' % n_correct)
# Calculate scores
precision = float(n_correct) / float(n_predicted)
print('precision: %s' % precision )
recall = float(n_correct) / float(n_gold)
print('recall: %s' % recall )
f1 = 2 * ( (precision * recall) / (precision + recall) )
print('f1: %s' % f1 )