-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathscore.py
More file actions
48 lines (33 loc) · 842 Bytes
/
score.py
File metadata and controls
48 lines (33 loc) · 842 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
41
42
43
44
45
46
47
48
import json
import math
import sys
import pytrec_eval
total_recall = 0
n = 0
results_fn = sys.argv[1]
map_fn = sys.argv[2]
qrel_fn = sys.argv[3]
results = open(results_fn, "r")
with open(map_fn, 'r') as file:
remap = json.load(file)
with open(qrel_fn, 'r') as file:
qrel = json.load(file)
run = {}
for line in results:
k, vs = line[:-1].split("\t")
run[k] = {}
result = []
for (i, v) in enumerate(vs.split(",")):
if v:
if remap is not None:
name = remap[v]
else:
name = v
run[k][name] = float(-i)
result.append(name)
evaluator = pytrec_eval.RelevanceEvaluator(qrel, {'ndcg_cut'})
eval = evaluator.evaluate(run)
total = 0
for k in eval.keys():
total += (eval[k]["ndcg_cut_10"])
print (total / len (eval.keys()))