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

filter-nbest.pl « phrase.sparse-features « tests - github.com/moses-smt/moses-regression-tests.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e63c083a3684f2fefaac4fc86590aea75fb72b93 (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
#!/usr/bin/env perl

use strict;

sub SortScores($);

my $x=0;
my $oldcode = "";
while (<>) {
  chomp;
  my ($code,$trans,$featscores,$globscores) = split(/[\s]*\|\|\|[\s]*/,$_);
  $x = 0 if $oldcode ne $code;
  $x++;
  chomp($code);

  my $featscoresSorted = SortScores($featscores);

  print "TRANSLATION_${code}_NBEST_${x}=$trans ||| $featscoresSorted\n";
  $oldcode = $code;
}


sub SortScores($)
{
  my $featscores = shift;
  my @toks = split(/ /, $featscores);  
  my @toks2;

  my $currInd = -1;
  for (my $i = 0; $i < scalar(@toks); ++$i) {
    my $tok = $toks[$i];
    my $lastChar = substr($tok, -1, 1);
    if ($lastChar eq '=') {
      push(@toks2, $tok);
      ++$currInd;
    }
    else {
      $toks2[$currInd] .= " " . $tok;
    }
  }

  @toks2 = sort(@toks2);
  
  return join(' ', @toks2);
}