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

substitute-filtered-tables.perl « support « ems « scripts - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eee4547286140a9310b9dafd2290bd3fc301bc22 (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
#!/usr/bin/env perl 

# experiment.perl support script
# get filtered rule and reordering tables and place them into a configuration file

if (scalar @ARGV < 1 || ! -e $ARGV[0]) {
  die("ERROR: could not find pseudo-config with filtered tables");
}

# read config sections about filtered tables
my @arr;
open(FILTERED, $ARGV[0]) or die "Cannot open: $!";
my $feature_section = 0;
while(my $line = <FILTERED>) {
  chomp($line);
  if ($line =~ /^\[(.+)\]/) {
    $feature_section = ($1 eq "feature");
  }
  next unless $feature_section;
  if ($line =~ /PhraseDictionary/ || $line =~ /RuleTable/) {
    print STDERR "pt:$line \n";
    push(@arr, $line);
  }
  elsif ($line =~ /LexicalReordering/) {
    print STDERR "ro:$line \n";
    push(@arr, $line);
  }
}
close(FILTERED);

# pass through master config file and replace table sections
my $ind = 0;
$feature_section = 0;
while(my $line = <STDIN>) {
  chomp($line);
  if ($line =~ /^\[(.+)\]/) {
    $feature_section = ($1 eq "feature");
  }
  if ($feature_section && ($line =~ /PhraseDictionary/ || $line =~ /RuleTable/)) {
    print $arr[$ind]."\n";
    ++$ind;
  }
  elsif ($feature_section && $line =~ /LexicalReordering/) {
    print $arr[$ind]."\n";
    ++$ind;
  }  
  else {
    print "$line\n";
  }
}