2010-01-25 20:38:53 +03:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
# $Id: report-experiment-scores.perl 407 2008-11-10 14:43:31Z philipp $
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
my $email;
|
|
|
|
|
|
|
|
my %TYPE;
|
|
|
|
$TYPE{"nist-bleu"} = "BLEU";
|
|
|
|
$TYPE{"multi-bleu"} = "BLEU";
|
|
|
|
$TYPE{"nist-bleu-c"} = "BLEU-c";
|
2011-01-13 07:53:09 +03:00
|
|
|
$TYPE{"multi-bleu-c"}= "BLEU-c";
|
2010-01-25 20:38:53 +03:00
|
|
|
$TYPE{"ibm-bleu"} = "IBM";
|
|
|
|
$TYPE{"ibm-bleu-c"} = "IBM-c";
|
2012-01-12 21:37:02 +04:00
|
|
|
$TYPE{"meteor"} = "METEOR";
|
2012-05-26 03:09:50 +04:00
|
|
|
$TYPE{"bolt-bleu"} = "BLEU";
|
|
|
|
$TYPE{"bolt-bleu-c"} = "BLEU-c";
|
|
|
|
$TYPE{"bolt-ter"} = "TER";
|
|
|
|
$TYPE{"bolt-ter-c"} = "TER-c";
|
2010-01-25 20:38:53 +03:00
|
|
|
|
|
|
|
my %SCORE;
|
|
|
|
my %AVERAGE;
|
|
|
|
foreach (@ARGV) {
|
|
|
|
if (/^email='(\S+)'/) {
|
|
|
|
$email = $1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (@ARGV) {
|
|
|
|
if (/^set=(\S+),type=(\S+),file=(\S+)$/) {
|
|
|
|
&process($1,$2,$3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach my $set (keys %SCORE) {
|
|
|
|
my $score = $SCORE{$set};
|
|
|
|
chop($score);
|
|
|
|
print "$set: $score\n";
|
|
|
|
}
|
|
|
|
if ((scalar keys %SCORE) > 1) {
|
|
|
|
print "avg:";
|
|
|
|
my $first = 1;
|
|
|
|
foreach my $type (keys %AVERAGE) {
|
|
|
|
print " ;" unless $first; $first = 0;
|
|
|
|
printf " %.02f $TYPE{$type}",$AVERAGE{$type}/(scalar keys %SCORE);
|
|
|
|
}
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub process {
|
|
|
|
my ($set,$type,$file) = @_;
|
|
|
|
$SCORE{$set} .= "; " if defined($SCORE{$set});
|
|
|
|
if (! -e $file) {
|
|
|
|
print STDERR "ERROR (score $type for set $set): file '$file' does not exist!\n";
|
|
|
|
}
|
|
|
|
elsif ($type eq 'nist-bleu' || $type eq 'nist-bleu-c') {
|
|
|
|
$SCORE{$set} .= &extract_nist_bleu($file,$type)." ";
|
|
|
|
}
|
|
|
|
elsif ($type eq 'ibm-bleu' || $type eq 'ibm-bleu-c') {
|
|
|
|
$SCORE{$set} .= &extract_ibm_bleu($file,$type)." ";
|
|
|
|
}
|
2011-01-13 07:53:09 +03:00
|
|
|
elsif ($type eq 'multi-bleu' || $type eq 'multi-bleu-c') {
|
|
|
|
$SCORE{$set} .= &extract_multi_bleu($file,$type)." ";
|
2010-01-25 20:38:53 +03:00
|
|
|
}
|
2012-01-12 21:37:02 +04:00
|
|
|
elsif ($type eq 'meteor') {
|
|
|
|
$SCORE{$set} .= &extract_meteor($file,$type)." ";
|
|
|
|
}
|
2012-05-26 03:09:50 +04:00
|
|
|
elsif ($type =~ /^bolt-(.+)$/) {
|
|
|
|
$SCORE{$set} .= &extract_bolt($file,$1)." ";
|
|
|
|
}
|
2010-01-25 20:38:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
sub extract_nist_bleu {
|
|
|
|
my ($file,$type) = @_;
|
|
|
|
my ($bleu,$ratio);
|
|
|
|
foreach (`cat $file`) {
|
|
|
|
$bleu = $1*100 if /BLEU score = (\S+)/;
|
|
|
|
$ratio = int(1000*$1)/1000 if /length ratio: (\S+)/;
|
|
|
|
}
|
2010-10-27 16:42:34 +04:00
|
|
|
if (!defined($bleu)) {
|
2010-01-25 20:38:53 +03:00
|
|
|
print STDERR "ERROR (extract_nist_bleu): could not find BLEU score in file '$file'\n";
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
my $output = sprintf("%.02f ",$bleu);
|
|
|
|
$output .= sprintf("(%.03f) ",$ratio) if $ratio;
|
|
|
|
|
|
|
|
$AVERAGE{$type} += $bleu;
|
|
|
|
|
|
|
|
return $output.$TYPE{$type};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub extract_ibm_bleu {
|
|
|
|
my ($file,$type) = @_;
|
|
|
|
my ($bleu,$ratio);
|
|
|
|
foreach (`cat $file`) {
|
|
|
|
$bleu = $1*100 if /BLEUr\dn4c?,(\S+)/;
|
|
|
|
$ratio = int(1000*(1/$1))/1000 if /Ref2SysLen,(\S+)/;
|
|
|
|
}
|
|
|
|
if (!$bleu) {
|
|
|
|
print STDERR "ERROR (extract_ibm_bleu): could not find BLEU score in file '$file'\n";
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
my $output = sprintf("%.02f ",$bleu);
|
|
|
|
$output .= sprintf("(%.03f) ",$ratio) if $ratio;
|
|
|
|
|
|
|
|
$AVERAGE{$type} += $bleu;
|
|
|
|
|
|
|
|
return $output.$TYPE{$type};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub extract_multi_bleu {
|
2011-01-13 07:53:09 +03:00
|
|
|
my ($file,$type) = @_;
|
2010-01-25 20:38:53 +03:00
|
|
|
my ($bleu,$ratio);
|
|
|
|
foreach (`cat $file`) {
|
|
|
|
$bleu = $1 if /BLEU = (\S+), /;
|
2011-06-17 03:43:29 +04:00
|
|
|
$ratio = $1 if / ration?=(\S+),/;
|
2010-01-25 20:38:53 +03:00
|
|
|
}
|
|
|
|
my $output = sprintf("%.02f ",$bleu);
|
|
|
|
$output .= sprintf("(%.03f) ",$ratio) if $ratio;
|
|
|
|
|
|
|
|
$AVERAGE{"multi-bleu"} += $bleu;
|
|
|
|
|
2011-01-13 07:53:09 +03:00
|
|
|
return $output.$TYPE{$type};
|
2010-01-25 20:38:53 +03:00
|
|
|
}
|
2012-01-12 21:37:02 +04:00
|
|
|
|
2012-05-26 03:09:50 +04:00
|
|
|
sub extract_bolt {
|
|
|
|
my ($file,$type) = @_;
|
|
|
|
my $score;
|
|
|
|
foreach (`cat $file`) {
|
|
|
|
$score = $1 if $type eq 'bleu' && /Lowercase BLEU\s+([\d\.]+)/;
|
|
|
|
$score = $1 if $type eq 'bleu-c' && /Cased BLEU\s+([\d\.]+)/;
|
|
|
|
$score = $1 if $type eq 'ter' && /Lowercase TER\s+([\d\.]+)/;
|
|
|
|
$score = $1 if $type eq 'ter-c' && /Cased TER\s+([\d\.]+)/;
|
|
|
|
}
|
|
|
|
my $output = sprintf("%.02f ",$score*100);
|
|
|
|
$AVERAGE{"bolt-".$type} += $score*100;
|
|
|
|
return $output.$TYPE{"bolt-".$type};
|
|
|
|
}
|
2012-01-12 21:37:02 +04:00
|
|
|
sub extract_meteor {
|
|
|
|
my ($file,$type) = @_;
|
|
|
|
my ($meteor, $precision);
|
|
|
|
foreach (`cat $file`) {
|
|
|
|
$meteor = $1*100 if /Final score:\s*(\S+)/;
|
|
|
|
$precision = $1 if /Precision:\s*(\S+)/;
|
|
|
|
}
|
|
|
|
my $output = sprintf("%.02f ",$meteor);
|
|
|
|
$output .= sprintf("(%.03f) ",$precision) if $precision;
|
|
|
|
$AVERAGE{"meteor"} += $meteor;
|
|
|
|
|
|
|
|
return $output.$TYPE{$type};
|
|
|
|
|
|
|
|
}
|