mosesdecoder/scripts/ems/support/wrap-xml.perl

49 lines
1023 B
Plaintext
Raw Normal View History

#!/usr/bin/env perl
2015-04-13 19:42:33 +03:00
use warnings;
use strict;
my ($language,$src,$system) = @ARGV;
die("wrapping frame not found ($src)") unless -e $src;
$system = "Edinburgh" unless $system;
2012-03-22 16:51:00 +04:00
open(SRC,$src) or die "Cannot open: $!";
my @OUT = <STDIN>;
chomp(@OUT);
#my @OUT = `cat $decoder_output`;
2014-06-06 00:30:29 +04:00
my $missing_end_seg = 0;
while(<SRC>) {
chomp;
if (/^<srcset/) {
s/<srcset/<tstset trglang="$language"/i;
}
elsif (/^<\/srcset/) {
s/<\/srcset/<\/tstset/i;
}
elsif (/^<doc/i) {
s/ *sysid="[^\"]+"//;
s/<doc/<doc sysid="$system"/i;
}
elsif (/<seg/) {
my $line = shift(@OUT);
$line = "" if $line =~ /NO BEST TRANSLATION/;
if (/<\/seg>/) {
s/(<seg[^>]+> *).*(<\/seg>)/$1$line$2/i;
2014-06-06 00:30:29 +04:00
$missing_end_seg = 0;
}
else {
2014-06-06 00:30:29 +04:00
s/(<seg[^>]+> *)[^<]*/$1$line<\/seg>/i;
$missing_end_seg = 1;
}
}
2014-06-06 00:30:29 +04:00
elsif ($missing_end_seg) {
if (/<\/doc>/) {
$missing_end_seg = 0;
}
else {
next;
}
}
print $_."\n";
}