summaryrefslogtreecommitdiff
path: root/wrap-xml.perl
blob: d29065a721f0532d0da0dc9f7b64a5c59787506e (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
#!/usr/bin/perl -w
# original: https://smt.googlecode.com/svn/trunk/moses64/tools/scripts/wrap-xml.perl

use strict;

my $src = $ARGV[0];
my $language = $ARGV[1];
die("syntax: wrap-xml.perl xml-frame language [system-name]")
    unless $src && $language && -e $src;
my $system = "my-system";
$system = $ARGV[2] if defined($ARGV[2]);

open(SRC,$src);
my @OUT = <STDIN>;
chomp(@OUT);
#my @OUT = `cat $decoder_output`;
while(<SRC>) {
    chomp;
    if (/^<srcset/) {
	s/<srcset/<tstset trglang="$language" sysid="$system"/;
    }
    elsif (/^<\/srcset/) {
	s/<\/srcset/<\/tstset/;
    }
    elsif (/^<DOC/) {
	s/<DOC/<DOC sysid="$system"/;
    }
    elsif (/<seg/) {
	my $line = shift(@OUT);
        $line = "" if $line =~ /NO BEST TRANSLATION/;
        if (/<\/seg>/) {
	  s/(<seg[^>]+> *).+(<\/seg>)/$1$line$2/;
        }
        else {
	  s/(<seg[^>]+> *)[^<]+/$1$line/;
        }
    }
    print $_."\n";
}