Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/marian-nmt/marian.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Junczys-Dowmunt <junczys@amu.edu.pl>2016-04-23 00:05:52 +0300
committerMarcin Junczys-Dowmunt <junczys@amu.edu.pl>2016-04-23 00:05:52 +0300
commit075821b8adc33d34aab5a85615b72afaee54f288 (patch)
tree592d5f15f9a370fd525dd3d519fcf0aeae3db225 /scripts/rescore.pl
parentdb68b3e23f33681d0fe4f863e5f8e9dd9455dd15 (diff)
execute wrapper
Diffstat (limited to 'scripts/rescore.pl')
-rwxr-xr-xscripts/rescore.pl34
1 files changed, 28 insertions, 6 deletions
diff --git a/scripts/rescore.pl b/scripts/rescore.pl
index ad2909f6..c7accf6e 100755
--- a/scripts/rescore.pl
+++ b/scripts/rescore.pl
@@ -4,6 +4,9 @@ use strict;
use Getopt::Long;
use File::Temp qw(tempfile);
+my $PID = $$;
+$SIG{TERM} = $SIG{INT} = $SIG{QUIT} = sub { die; };
+
my $RESCORER;
my $INPUT;
my $NBEST;
@@ -39,8 +42,8 @@ while (<W>) {
}
close(W);
-my $PATTERN1 = join(" ", map { "\\b$_= \\S+" } @FEATURES);
-my $PATTERN2 = "\\b$BEFORE \\S+";
+my $PATTERN1 = quotemeta(join(" ", map { "\\b$_= \\S+" } @FEATURES));
+my $PATTERN2 = quotemeta("\\b$BEFORE \\S+");
print STDERR $PATTERN1, "\n";
print STDERR $PATTERN2, "\n";
@@ -59,7 +62,7 @@ close(NBEST_IN);
close($NBEST_TEMP_HANDLE);
foreach my $i (0 .. $#MODELS) {
- system("$RESCORER -i $INPUT -m $MODELS[$i] -s $VSRC -t $VTRG -f $FEATURES[$i] -n $NBEST_TEMP_FILE1 > $NBEST_TEMP_FILE2");
+ execute("$RESCORER -i $INPUT -m $MODELS[$i] -s $VSRC -t $VTRG -f $FEATURES[$i] -n $NBEST_TEMP_FILE1 > $NBEST_TEMP_FILE2");
rename($NBEST_TEMP_FILE2, $NBEST_TEMP_FILE1);
}
@@ -67,12 +70,31 @@ open($NBEST_TEMP_HANDLE, "<", $NBEST_TEMP_FILE1) or die "Could not open";
while (<$NBEST_TEMP_HANDLE>) {
chomp;
- if (/\Q$PATTERN2/) {
- if(s/(\Q$PATTERN1)//) {
+ if (/$PATTERN2/) {
+ if(s/($PATTERN1)//) {
my $FEAT = $1;
- s/($PATTERN2 )/$1$FEAT lala /;
+ s/($PATTERN2 )/$1$FEAT /;
}
}
print "$_\n";
}
+sub execute {
+ my $command = shift;
+ logMessage("Executing:\t$command");
+ my $ret = system($command);
+ if($ret != 0) {
+ logMessage("Command '$command' finished with return status $ret");
+ logMessage("Aborting and killing parent process");
+ kill(2, $PID);
+ die;
+ }
+}
+
+sub logMessage {
+ my $message = shift;
+ my $time = POSIX::strftime("%m/%d/%Y %H:%M:%S", localtime());
+ my $log_message = $time."\t$message\n";
+ print STDERR $log_message;
+}
+