-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscorer.py
46 lines (46 loc) · 1.68 KB
/
scorer.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
from __future__ import division
from __future__ import print_function
import sys;
reload(sys)
sys.setdefaultencoding='utf-8'
if (len(sys.argv)<3):
print("not enough parameters!");
exit();
test_filename = sys.argv[1];
answer_filename = sys.argv[2];
scores = [];
with open(test_filename,'r',) as test:
with open(answer_filename,'r',) as answer:
while (True):
test_word = test.readline().strip();
answer_word = answer.readline().strip();
if (len(test_word)==0 or len(answer_word)==0):
break;
while (test_word != answer_word): #some word not exist in embeddings
answer.readline();
answer_word = answer.readline().strip();
#print(test_word);
#print(answer_word);
test_sememes = test.readline().strip().strip('[]').split(' ');
answer_sememes = answer.readline().strip().strip('[]').split(' ');
point = 0;
length = len(test_sememes);
#for i in range(0,length):
##print(test_sememes[i]);
#test_sememes[i] = test_sememes[i].strip().strip('\'');
##print(i);
if (len(answer_sememes)==0):
continue;
#print(test_sememes);
#print(answer_sememes);
rank = 1;
index = 0;
for item in test_sememes:
if item in answer_sememes:
index += 1
point += float(index) / rank
rank += 1;
point /= len(answer_sememes);
#print(point);
scores.append(point);
print("result:%f" % (sum(scores)/len(scores),));