line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::AlignmentEval; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1162
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
my $true = 1; |
6
|
|
|
|
|
|
|
my $false = 0; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
1
|
|
|
1
|
0
|
3
|
my ($pkg,$surePrecision,$sureRecall,$sureFMeasure,$possiblePrecision,$possibleRecall,$possibleFMeasure,$AER) = @_; |
10
|
1
|
|
|
|
|
2
|
my $this = {}; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
|
|
3
|
$this->{surePrecision}=$surePrecision; |
13
|
1
|
|
|
|
|
3
|
$this->{sureRecall}=$sureRecall; |
14
|
1
|
|
|
|
|
3
|
$this->{possiblePrecision}=$possiblePrecision; |
15
|
1
|
|
|
|
|
2
|
$this->{possibleRecall}=$possibleRecall; |
16
|
1
|
|
|
|
|
2
|
$this->{sureFMeasure}=$sureFMeasure; |
17
|
1
|
|
|
|
|
3
|
$this->{possibleFMeasure}=$possibleFMeasure; |
18
|
1
|
|
|
|
|
1
|
$this->{AER}=$AER; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
46
|
return bless $this,$pkg; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub display{ |
24
|
0
|
|
|
0
|
0
|
|
my ($this,$fileHandle,$format)=@_; |
25
|
0
|
|
|
|
|
|
my $output; |
26
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
if (!defined($format)){$format="text"} |
|
0
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
if (!defined($fileHandle)){$fileHandle=*STDOUT} |
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
if ($format eq "text"){ |
31
|
0
|
|
|
|
|
|
printf($fileHandle "\n Word Alignment Evaluation \n"); |
32
|
0
|
|
|
|
|
|
printf($fileHandle "----------------------------------\n"); |
33
|
0
|
|
|
|
|
|
printf($fileHandle " Evaluation of SURE alignments \n"); |
34
|
0
|
|
|
|
|
|
printf($fileHandle " Precision = %5.4f \n", $this->{surePrecision}); |
35
|
0
|
|
|
|
|
|
printf($fileHandle " Recall = %5.4f\n",$this->{sureRecall}); |
36
|
0
|
|
|
|
|
|
printf($fileHandle " F-measure = %5.4f\n",$this->{sureFMeasure}); |
37
|
0
|
|
|
|
|
|
printf($fileHandle "-----------------------------------\n"); |
38
|
0
|
|
|
|
|
|
printf($fileHandle " Evaluation of POSSIBLE alignments\n"); |
39
|
0
|
|
|
|
|
|
printf($fileHandle " Precision = %5.4f\n",$this->{possiblePrecision}); |
40
|
0
|
|
|
|
|
|
printf($fileHandle " Recall = %5.4f\n",$this->{possibleRecall}); |
41
|
0
|
|
|
|
|
|
printf($fileHandle " F-measure = %5.4f\n",$this->{possibleFMeasure}); |
42
|
0
|
|
|
|
|
|
printf($fileHandle "-----------------------------------\n"); |
43
|
0
|
|
|
|
|
|
printf($fileHandle " AER = %5.4f\n",$this->{AER}); |
44
|
|
|
|
|
|
|
}else{ |
45
|
0
|
|
|
|
|
|
print "AlignmentEval::compare: format no supported"; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#input: hash: ("title",$refToResultsRef,"title2",$refToResultsRef2...) |
50
|
|
|
|
|
|
|
#filehandle:where do you print it (default:stdin) |
51
|
|
|
|
|
|
|
#format: text,latex (default:text) |
52
|
|
|
|
|
|
|
sub compare{ |
53
|
0
|
|
|
0
|
0
|
|
my ($results,$title,$fileHandle,$format)=@_; |
54
|
|
|
|
|
|
|
#defaults |
55
|
0
|
0
|
|
|
|
|
if (!defined($format)){$format="text"} |
|
0
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if (!defined($fileHandle)){$fileHandle=*STDOUT} |
|
0
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my ($ref,$expName,$result,$line); |
58
|
0
|
|
|
|
|
|
my $numResults = scalar(@$results); |
59
|
0
|
|
|
|
|
|
my ($titleLine,$rowSep1,$header,$rowSep2); |
60
|
0
|
|
|
|
|
|
my ($colSep1,$colSep2,$rowEnd); |
61
|
0
|
|
|
|
|
|
my @measures; |
62
|
|
|
|
|
|
|
# variables for latex format |
63
|
0
|
|
|
|
|
|
my $latex; |
64
|
|
|
|
|
|
|
# variables for text format |
65
|
0
|
|
|
|
|
|
my $initialSpace=25; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
0
|
|
|
|
if ($format ne "text" && $format ne "latex"){ |
68
|
0
|
|
|
|
|
|
print "AlignmentEval::compare: format no supported"; |
69
|
0
|
|
|
|
|
|
return; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
0
|
|
|
|
|
if ($format eq "latex"){ |
|
|
0
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
$latex = Lingua::Latex->new; |
73
|
0
|
|
|
|
|
|
print $fileHandle $latex->startFile; |
74
|
0
|
|
|
|
|
|
print $fileHandle $latex->setTabcolsep("0.5mm"); |
75
|
0
|
|
|
|
|
|
print $fileHandle '\vspace{5mm}'."\n"; |
76
|
0
|
|
|
|
|
|
$titleLine = "\n".'\begin{tabular}{|p{4cm}|'.'r@{ }|' x (7)."}\n"; |
77
|
0
|
|
|
|
|
|
$titleLine.= "\n".' \multicolumn{8}{p{14cm}}{ '.$latex->fromText($title).'} \\\\ '."\n"; |
78
|
0
|
|
|
|
|
|
$rowSep1 = '\hline'."\n".'\hline'."\n"; |
79
|
0
|
|
|
|
|
|
$header =' Experiment & \parbox{1.3cm}{\centering $P_S\ (\%)$} & \parbox{1.3cm}{\centering $R_S\ (\%)$} & \parbox{1.3cm}{\centering $F_S\ (\%)$}'; |
80
|
0
|
|
|
|
|
|
$header.=' & \parbox{1.3cm}{\centering $P_P\ (\%)$} & \parbox{1.3cm}{\centering $R_P\ (\%)$} & \parbox{1.3cm}{\centering $F_P\ (\%)$}'; |
81
|
0
|
|
|
|
|
|
$header.=' & \parbox{1.5cm}{\centering $AER\ (\%)$}\\\\'."\n"; |
82
|
0
|
|
|
|
|
|
$rowSep2='\hline'."\n"; |
83
|
0
|
|
|
|
|
|
$colSep1=' & '; |
84
|
0
|
|
|
|
|
|
$colSep2=' & '; |
85
|
0
|
|
|
|
|
|
$rowEnd = '\\\\'; |
86
|
|
|
|
|
|
|
}elsif ($format eq "text"){ |
87
|
0
|
|
|
|
|
|
$titleLine = "\n $title \n"; |
88
|
0
|
|
|
|
|
|
$rowSep1 = "----------------------------------\n"; |
89
|
0
|
|
|
|
|
|
$colSep2=' '; |
90
|
0
|
|
|
|
|
|
$header = " Experiment"." " x ($initialSpace-11)." Ps$colSep2 Rs$colSep2 Fs$colSep2 Pp$colSep2 Rp$colSep2 Fp$colSep2 AER \n\n"; |
91
|
0
|
|
|
|
|
|
$rowEnd=''; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
printf $fileHandle $titleLine; |
95
|
0
|
|
|
|
|
|
printf $fileHandle $rowSep1; |
96
|
0
|
|
|
|
|
|
printf $fileHandle $header;#,@titleLine; |
97
|
0
|
|
|
|
|
|
printf $fileHandle $rowSep2; |
98
|
0
|
|
|
|
|
|
foreach $ref (@$results){ |
99
|
0
|
|
|
|
|
|
$result=$ref->[0]; |
100
|
0
|
|
|
|
|
|
$expName=$ref->[1]; |
101
|
0
|
0
|
|
|
|
|
if ($format eq "text"){ |
102
|
0
|
0
|
|
|
|
|
if (length($expName)>=$initialSpace){ |
103
|
0
|
|
|
|
|
|
$expName = substr $expName,0,$initialSpace-1; |
104
|
0
|
|
|
|
|
|
$colSep1=' '; |
105
|
|
|
|
|
|
|
}else{ |
106
|
0
|
|
|
|
|
|
$colSep1=' ' x ($initialSpace-length($expName)); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
}else{ |
109
|
0
|
|
|
|
|
|
$expName = $latex->fromText($expName); |
110
|
|
|
|
|
|
|
} |
111
|
0
|
|
|
|
|
|
@measures = ($result->{surePrecision}*100,$result->{sureRecall}*100,$result->{sureFMeasure}*100, |
112
|
|
|
|
|
|
|
$result->{possiblePrecision}*100,$result->{possibleRecall}*100,$result->{possibleFMeasure}*100, |
113
|
|
|
|
|
|
|
$result->{AER}*100); |
114
|
0
|
|
|
|
|
|
printf $fileHandle $expName.$colSep1."%5.2f"."$colSep2%5.2f" x (6)."$rowEnd\n",@measures; |
115
|
|
|
|
|
|
|
} |
116
|
0
|
0
|
|
|
|
|
if ($format eq "latex"){ |
117
|
0
|
|
|
|
|
|
print $fileHandle '\hline'."\n"; |
118
|
0
|
|
|
|
|
|
print $fileHandle '\end{tabular}'; |
119
|
0
|
|
|
|
|
|
print $fileHandle $latex->endFile; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |