lmplz-wrapper.perl: use Getopt::Long's "pass_through" option

This avoids the need to duplicate all of lmplz's options in the wrapper and
it prevents --prune 0 0 1 from being truncated to --prune 0 if the user forgets
to quote the arguments.
This commit is contained in:
Phil Williams 2015-03-30 10:18:51 +01:00
parent c634f6ee5b
commit 6ce3060dd8

View File

@ -3,25 +3,20 @@
use strict;
use Getopt::Long "GetOptions";
my ($TEXT,$ORDER,$PRUNE,$BIN,$LM,$MEMORY,$TMP,$DISCOUNT_FALLBACK);
Getopt::Long::config("pass_through");
my ($TEXT,$ORDER,$BIN,$LM);
&GetOptions('text=s' => \$TEXT,
'lm=s' => \$LM,
'bin=s' => \$BIN,
'prune=s' => \$PRUNE,
'discount_fallback' => \$DISCOUNT_FALLBACK,
'T=s' => \$TMP,
'S=s' => \$MEMORY,
'order=i' => \$ORDER);
die("ERROR: specify at least --text CORPUS --arpa LM and --order N!")
unless defined($TEXT) && defined($LM) && defined($ORDER);
die("ERROR: specify at least --bin BIN --text CORPUS --lm LM and --order N!")
unless defined($BIN) && defined($TEXT) && defined($LM) && defined($ORDER);
my $cmd = "$BIN --text $TEXT --order $ORDER --arpa $LM";
$cmd .= " --prune $PRUNE" if defined($PRUNE);
$cmd .= " -S $MEMORY" if defined($MEMORY);
$cmd .= " -T $TMP" if defined($TMP);
$cmd .= " --discount_fallback" if defined($DISCOUNT_FALLBACK);
$cmd .= " " . join(' ', @ARGV) if scalar(@ARGV); # Pass remaining args through.
print "exec: $cmd\n";
`$cmd`;