-
Notifications
You must be signed in to change notification settings - Fork 4
/
benchmark.py
executable file
·56 lines (49 loc) · 1.13 KB
/
benchmark.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os,sys
from terminology import read_term, normId
def benchmark(infile, terminology):
dataset = open(infile,'r').read().split("===========================\n")
qa_set = []
no_postive=0
summ = 0
right = 0
Id_dict = read_term(terminology)
for x, data in enumerate(dataset):
if data.strip() == '':
continue
item_set = data.strip().split('\n')
query = ''
pos_set, neg_set = [],[]
repeat_list = []
for y, item in enumerate(item_set):
if item in repeat_list:
continue
else:
repeat_list.append(item)
try:
query , question, query_id, ques_id, sieve, fname, index = item.split('\t')
query_id = normId( query_id, Id_dict)
ques_id = normId( ques_id , Id_dict)
if query_id == ques_id:
label = 1
break
elif query_id in ques_id:
label = 2
break
else:
label = 0
except:
print "Error Parser :" + item
continue
if label == 1:
summ +=1
right += 1
elif label == 2:
summ += 1
right += 0.5
else :
no_postive += 1
summ += 1
print summ, right,no_postive
print float(right)/summ
if __name__ == '__main__':
benchmark(sys.argv[1], sys.argv[2])