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

delete-scores.perl « other « scripts - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 08316c95b15ac167c2670a0c9698f53fe2fd4fd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env perl 

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;
}