2006-08-08 19:54:30 +04:00
|
|
|
package MosesRegressionTesting;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
# if your tests need a new version of the test data, increment this
|
|
|
|
# and make sure that a moses-regression-tests-vX.Y is available for
|
|
|
|
# download from statmt.org (redpony AT umd dot edu for more info)
|
|
|
|
|
|
|
|
# find the data directory in a few likely locations and make sure
|
|
|
|
# that it is the correct version
|
|
|
|
sub find_data_directory
|
|
|
|
{
|
|
|
|
my ($test_script_root, $data_dir) = @_;
|
|
|
|
my @ds = ();
|
2012-06-26 00:03:11 +04:00
|
|
|
my $mrtp = "moses-reg-test-data";
|
2006-08-08 19:54:30 +04:00
|
|
|
push @ds, $data_dir if defined $data_dir;
|
|
|
|
push @ds, "$test_script_root/$mrtp";
|
|
|
|
push @ds, "/export/ws06osmt/regression-testing/$mrtp";
|
|
|
|
push @ds, "/tmp/$mrtp";
|
|
|
|
push @ds, "/var/tmp/$mrtp";
|
|
|
|
foreach my $d (@ds) {
|
|
|
|
next unless (-d $d);
|
|
|
|
if (!-d "$d/models") {
|
|
|
|
print STDERR "Found $d but it is malformed: missing subdir models/\n";
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if (!-d "$d/lm") {
|
|
|
|
print STDERR "Found $d but it is malformed: missing subdir lm/\n";
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
return $d;
|
|
|
|
}
|
|
|
|
print STDERR<<EOT;
|
|
|
|
|
|
|
|
You do not appear to have the regression testing data installed. You may
|
|
|
|
either specify a non-standard location when running the test suite with
|
|
|
|
the --data-dir option, or, you may install it in any one of the following
|
|
|
|
standard locations: $test_script_root, /tmp, or /var/tmp with these
|
|
|
|
commands:
|
|
|
|
|
|
|
|
cd <DESIRED_INSTALLATION_DIRECTORY>
|
2012-06-26 00:03:11 +04:00
|
|
|
git clone https://github.com/hieuhoang/moses-reg-test-data.git
|
2006-08-08 19:54:30 +04:00
|
|
|
|
|
|
|
EOT
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub get_localized_moses_ini
|
|
|
|
{
|
|
|
|
use File::Temp;
|
2012-11-20 20:14:20 +04:00
|
|
|
my ($moses_ini, $data_dir, $results_dir) = @_;
|
2006-08-08 19:54:30 +04:00
|
|
|
my $LM_PATH = "$data_dir/lm";
|
2006-11-20 16:27:24 +03:00
|
|
|
my $MODEL_PATH = "$data_dir/models";
|
2007-09-14 11:31:56 +04:00
|
|
|
use Cwd qw/ abs_path /; use File::Basename; my $TEST_PATH = dirname(abs_path($moses_ini));
|
2006-11-20 16:27:24 +03:00
|
|
|
my $local_moses_ini = new File::Temp( UNLINK => 0, SUFFIX => '.ini' );
|
2006-08-08 19:54:30 +04:00
|
|
|
|
|
|
|
open MI, "<$moses_ini" or die "Couldn't read $moses_ini";
|
2006-11-20 16:27:24 +03:00
|
|
|
open MO, ">$local_moses_ini" or die "Couldn't open $local_moses_ini for writing";
|
2006-08-08 19:54:30 +04:00
|
|
|
while (my $l = <MI>) {
|
2006-11-20 16:27:24 +03:00
|
|
|
$l =~ s/\$\{LM_PATH\}/$LM_PATH/g;
|
|
|
|
$l =~ s/\$\{MODEL_PATH\}/$MODEL_PATH/g;
|
2007-09-14 11:31:56 +04:00
|
|
|
$l =~ s/\$\{TEST_PATH\}/$TEST_PATH/g;
|
2012-11-20 20:14:20 +04:00
|
|
|
$l =~ s/\$\{RESULTS_PATH\}/$results_dir/g;
|
2006-11-20 16:27:24 +03:00
|
|
|
print $local_moses_ini $l;
|
|
|
|
}
|
|
|
|
close MO;
|
|
|
|
close MI;
|
2006-08-08 19:54:30 +04:00
|
|
|
|
|
|
|
return $local_moses_ini->filename;
|
|
|
|
}
|
|
|
|
|
2006-11-20 16:27:24 +03:00
|
|
|
sub get_nbestlist
|
|
|
|
{
|
|
|
|
my ($moses_ini) = @_;
|
|
|
|
my $nbestfile = undef;
|
|
|
|
my $nbestsize = undef;
|
|
|
|
|
|
|
|
open MI, "<$moses_ini" or die "Couldn't read $moses_ini";
|
|
|
|
while (my $l = <MI>) {
|
|
|
|
if ($l =~ /\[n-best-list\]/i){
|
|
|
|
chomp($nbestfile = <MI>);
|
|
|
|
chomp($nbestsize = <MI>);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close MI;
|
|
|
|
|
|
|
|
return ($nbestfile,$nbestsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-08 19:54:30 +04:00
|
|
|
1;
|
|
|
|
|