-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker.py
56 lines (44 loc) · 1.23 KB
/
checker.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
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 9 16:58:36 2016
@author: anant
code checker
"""
def precision(tp, fp):
return tp/(tp+fp)
def recall(tp, fn):
return tp/(tp+fn)
def fscore( tp, fp, fn):
p = precision(tp, fp)
r = recall(tp, fn)
print("Precision: ", p, "\n")
print("Recall: ", r, "\n")
if(p or r):
return 2*p*r/(p+r)
else:
return 0
def sentence_score( truth, gen_file ):
truth_handle = open(truth,"r")
i = 0
for line in truth_handle:
if( i ):
line_split = line.split(",")
truth_sentence_nums = line_split[1].strip().split(" ")
i+=1;
truth_set = set( truth_sentence_nums )
gen_file_handle = open(gen_file,"r")
i = 0
for line in gen_file_handle:
if( i ):
line_split = line.split(",")
gen_file_sentence_nums = (line_split[1]).strip().split(" ")
i+=1;
gen_set = set(gen_file_sentence_nums)
tp = len(gen_set.intersection(truth_set))
fp = len(gen_set.difference(truth_set))
fn = len(truth_set.difference(gen_set))
score = fscore(tp, fp, fn)
print( score )
return(score)
def word_score( truth, gen_file ):
return( sentence_score( truth, gen_file ) )