mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 05:14:36 +03:00
ef028446f3
This is not pleasant to read (and much, much less pleasant to write!) but sort of necessary in an open project. Right now it's quite hard to figure out what is licensed how, which doesn't matter much to most people but can suddenly become very important when people want to know what they're being allowed to do. I kept the notices as short as I could. As far as I could see, everything without a clear license notice is LGPL v2.1 or later.
68 lines
1.2 KiB
Perl
Executable File
68 lines
1.2 KiB
Perl
Executable File
#!/usr/bin/env perl
|
|
#
|
|
# This file is part of moses. Its use is licensed under the GNU Lesser General
|
|
# Public License version 2.1 or, at your option, any later version.
|
|
|
|
use warnings;
|
|
use strict;
|
|
use Getopt::Long "GetOptions";
|
|
|
|
binmode(STDIN, ":utf8");
|
|
binmode(STDOUT, ":utf8");
|
|
|
|
sub trim($);
|
|
sub DeleteScore;
|
|
|
|
my $keepScoresStr;
|
|
GetOptions(
|
|
"keep-scores=s" => \$keepScoresStr
|
|
) or exit(1);
|
|
|
|
my @keepScores = split(/,/, $keepScoresStr);
|
|
|
|
#MAIN LOOP
|
|
while (my $line = <STDIN>) {
|
|
chomp($line);
|
|
#print STDERR "line=$line\n";
|
|
|
|
my @toks = split(/\|/, $line);
|
|
my @scores = split(/ /, $toks[6]);
|
|
|
|
$toks[6] = DeleteScore($toks[6], \@keepScores);
|
|
|
|
# output
|
|
print $toks[0];
|
|
for (my $i = 1; $i < scalar(@toks); ++$i) {
|
|
print "|" .$toks[$i];
|
|
}
|
|
print "\n";
|
|
}
|
|
|
|
######################
|
|
# Perl trim function to remove whitespace from the start and end of the string
|
|
sub trim($) {
|
|
my $string = shift;
|
|
$string =~ s/^\s+//;
|
|
$string =~ s/\s+$//;
|
|
return $string;
|
|
}
|
|
|
|
sub DeleteScore
|
|
{
|
|
my $string = $_[0];
|
|
my @keepScores = @{$_[1]};
|
|
|
|
$string = trim($string);
|
|
my @toks = split(/ /, $string);
|
|
|
|
$string = "";
|
|
for (my $i = 0; $i < scalar(@keepScores); ++$i) {
|
|
$string .= $toks[ $keepScores[$i] ] ." ";
|
|
}
|
|
$string = " " .$string;
|
|
|
|
return $string;
|
|
}
|
|
|
|
|