-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge-output.pl
executable file
·66 lines (60 loc) · 1.72 KB
/
merge-output.pl
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
65
66
#!/usr/bin/perl
#
# Merge segments of different folders into one file:
# - source language folder (containing original and corrected segments)
# - MT-translated target language folder (containing original and corrected segments)
# - folder containing reference translation segments from reference set 1
# - folder containing reference translation segments from reference set 2
#
use warnings;
use FileHandle;
if ($#ARGV <= 2) {
print "$0 <srcfolder> <tgtfolder> <ref1folder> <ref2folder>\n";
exit -1;
}
$srcfolder = $ARGV[0];
$tgtfolder = $ARGV[1];
$ref1folder = $ARGV[2];
$ref2folder = $ARGV[3];
@files = <$srcfolder/*>;
foreach $file (@files) {
next if ($file =~ /\.orig$/);
next unless ($file =~ /^$srcfolder\/(.*)$/);
$basename = $1;
@parts = split(/\./, $basename);
$flagtype = $parts[0] || "";
$rulename = $parts[1] || "";
open ORIGFILE, "$file.orig";
open CORRECTEDFILE, "$file";
open TGTORIGFILE, "$tgtfolder/$basename.orig";
open TGTCORRECTEDFILE, "$tgtfolder/$basename";
open REF1FILE, "$ref1folder/$basename.ref";
open REF2FILE, "$ref2folder/$basename.ref";
while ($orig = <ORIGFILE>) {
$corrected = <CORRECTEDFILE>;
$tgtorig = <TGTORIGFILE>;
$tgtcorrected = <TGTCORRECTEDFILE>;
$ref1 = <REF1FILE>;
$ref2 = <REF2FILE>;
chomp $orig;
chomp $corrected;
chomp $tgtorig;
chomp $tgtcorrected;
chomp $ref1;
chomp $ref2;
print "$flagtype\t$rulename\n";
print "SO\t$orig\n";
print "SC\t$corrected\n";
print "TO\t$tgtorig\n";
print "TC\t$tgtcorrected\n";
print "R1\t$ref1\n";
print "R2\t$ref2\n";
print "\n";
}
close ORIGFILE;
close CORRECTEDFILE;
close TGTORIGFILE;
close TGTCORRECTEDFILE;
close REF1FILE;
close REF2FILE;
}