summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-22 21:31:54 +0000
committerredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-22 21:31:54 +0000
commit909af90621f2e6bf66e23955cc8b893896919b99 (patch)
tree3e159e0ed3d12dc85f07335efe3419fb172ade00
parentff387b9f7413b5f1a324474da7cb8bb36be5bee0 (diff)
forgotten
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@371 ec762483-ff6d-05da-a07a-a48fb63a330f
-rwxr-xr-xgi/pipeline/scripts/filter-by-f.pl53
1 files changed, 53 insertions, 0 deletions
diff --git a/gi/pipeline/scripts/filter-by-f.pl b/gi/pipeline/scripts/filter-by-f.pl
new file mode 100755
index 00000000..3dd03bdd
--- /dev/null
+++ b/gi/pipeline/scripts/filter-by-f.pl
@@ -0,0 +1,53 @@
+#!/usr/bin/perl -w
+use strict;
+
+my $SCRIPT_DIR; BEGIN { use Cwd qw/ abs_path /; use File::Basename; $SCRIPT_DIR = dirname(abs_path($0)); push @INC, $SCRIPT_DIR; }
+
+my $REKEY="$SCRIPT_DIR/rekey.pl";
+my $REFILTER="$SCRIPT_DIR/refilter.pl";
+my $SORT="$SCRIPT_DIR/sort-by-key.sh";
+assert_exec($REKEY, $REFILTER, $SORT);
+
+die "Usage: $0 ingrammar.gz outgrammar.gz\n" unless scalar @ARGV == 2;
+die unless $ARGV[0] =~ /\.gz$/;
+die unless $ARGV[1] =~ /\.gz$/;
+die if $ARGV[0] eq $ARGV[1];
+die "Can't find $ARGV[0]" unless -f $ARGV[0];
+
+my $cmd = "gunzip -c $ARGV[0] | $REKEY | $SORT | $REFILTER | gzip > $ARGV[1]";
+safesystem($ARGV[1], $cmd) or die "Filtering failed";
+exit 0;
+
+sub assert_exec {
+ my @files = @_;
+ for my $file (@files) {
+ die "Can't find $file - did you run make?\n" unless -e $file;
+ die "Can't execute $file" unless -e $file;
+ }
+};
+
+sub safesystem {
+ my $output = shift @_;
+ print STDERR "Executing: @_\n";
+ system(@_);
+ if ($? == -1) {
+ print STDERR "ERROR: Failed to execute: @_\n $!\n";
+ if (defined $output && -e $output) { printf STDERR "Removing $output\n"; `rm -rf $output`; }
+ exit(1);
+ }
+ elsif ($? & 127) {
+ printf STDERR "ERROR: Execution of: @_\n died with signal %d, %s coredump\n",
+ ($? & 127), ($? & 128) ? 'with' : 'without';
+ if (defined $output && -e $output) { printf STDERR "Removing $output\n"; `rm -rf $output`; }
+ exit(1);
+ }
+ else {
+ my $exitcode = $? >> 8;
+ if ($exitcode) {
+ print STDERR "Exit code: $exitcode\n";
+ if (defined $output && -e $output) { printf STDERR "Removing $output\n"; `rm -rf $output`; }
+ }
+ return ! $exitcode;
+ }
+}
+