| 1 | package Lingua::AlignmentEval; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | my $true = 1; | |||||||||||||||||||||||||||
| 6 | 1 | my $false = 0; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | 1 | my ($pkg,$surePrecision,$sureRecall,$sureFMeasure,$possiblePrecision,$possibleRecall,$possibleFMeasure,$AER) = @_; | |||||||||||||||||||||||||||
| 10 | 1 | my $this = {}; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | $this->{surePrecision}=$surePrecision; | |||||||||||||||||||||||||||
| 13 | 1 | $this->{sureRecall}=$sureRecall; | |||||||||||||||||||||||||||
| 14 | 1 | $this->{possiblePrecision}=$possiblePrecision; | |||||||||||||||||||||||||||
| 15 | 1 | $this->{possibleRecall}=$possibleRecall; | |||||||||||||||||||||||||||
| 16 | 1 | $this->{sureFMeasure}=$sureFMeasure; | |||||||||||||||||||||||||||
| 17 | 1 | $this->{possibleFMeasure}=$possibleFMeasure; | |||||||||||||||||||||||||||
| 18 | 1 | $this->{AER}=$AER; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | return bless $this,$pkg; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub display{ | ||||||||||||||||||||||||||
|
Subroutine
display: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 0 | my ($this,$fileHandle,$format)=@_; | |||||||||||||||||||||||||||
| 25 | 0 | my $output; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if (!defined($format)){$format="text"} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if (!defined($fileHandle)){$fileHandle=*STDOUT} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ($format eq "text"){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub compare{ | ||||||||||||||||||||||||||
|
Subroutine
compare: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 0 | my ($results,$title,$fileHandle,$format)=@_; | |||||||||||||||||||||||||||
| 54 | #defaults | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if (!defined($format)){$format="text"} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if (!defined($fileHandle)){$fileHandle=*STDOUT} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | if ($format ne "text" && $format ne "latex"){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$format ne "text" and $format ne "latex"
MC/DC0%0/2
$format ne "text" and $format ne "latex"
$format ne "text"
$format ne "latex"
Truth table0%0/3
A and B
A= $format ne "text"B= $format ne "latex"
| |||||||||||||||||||||||||||||
| 68 | 0 | print "AlignmentEval::compare: format no supported"; | |||||||||||||||||||||||||||
| 69 | 0 | return; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ($format eq "latex"){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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 | ▶ | if ($format eq "text"){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if (length($expName)>=$initialSpace){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | @measures = ($result->{surePrecision}*100,$result->{sureRecall}*100,$result->{sureFMeasure}*100, | ||||||||||||||||||||||||||||
| 112 | $result->{possiblePrecision}*100,$result->{possibleRecall}*100,$result->{possibleFMeasure}*100, | ||||||||||||||||||||||||||||
| 113 | 0 | $result->{AER}*100); | |||||||||||||||||||||||||||
| 114 | 0 | printf $fileHandle $expName.$colSep1."%5.2f"."$colSep2%5.2f" x (6)."$rowEnd\n",@measures; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ($format eq "latex"){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | print $fileHandle '\hline'."\n"; | |||||||||||||||||||||||||||
| 118 | 0 | print $fileHandle '\end{tabular}'; | |||||||||||||||||||||||||||
| 119 | 0 | print $fileHandle $latex->endFile; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 1 | 1; | |||||||||||||||||||||||||||