-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build_translated_list.pl
executable file
·65 lines (55 loc) · 1.47 KB
/
build_translated_list.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
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use FindBin;
my %titles;
my %scores;
my %results;
# Check command line arguments
my $titleFile = $ARGV[0] || "";
my $lang = $ARGV[1] || "";
my $scoreFile = $ARGV[2] || "";
my $langLinks = "${FindBin::Bin}data/tmp/$lang.langlinks.tsv";
if (!$lang) {
print STDERR "Language is not set.\n";
exit 1;
}
for my $file ($titleFile, $langLinks, $scoreFile) {
if (!-f $file) {
print STDERR "File '$file' does not exist, is not a file or is not readable.\n";
exit 1;
}
}
# Open title list
print STDERR "Reading $titleFile...\n";
open(FILE, '<', $titleFile) or die("Unable to open file '$titleFile'\n");
while(<FILE>) {
my $title = $_;
chomp($title);
$titles{$title} = undef;
}
close(FILE);
# Open score list
print STDERR "Reading $scoreFile...\n";
open(FILE, '<', $scoreFile) or die("Unable to open file '$scoreFile'\n");
while(<FILE>) {
my $line = $_;
chomp($line);
my ($title, $score) = split("\t", $line);
$scores{$title} = $score;
}
close(FILE);
# Open langlinks (and find translation)
print STDERR "Reading $langLinks...\n";
open(FILE, '<', $langLinks) or die("Unable to open file '$langLinks'\n");
while(<FILE>) {
my $line = $_;
chomp($line);
my ($s, $l, $t) = split("\t", $line);
$results{$t} = ($scores{$t} || 0)
if ($l eq $lang && exists $titles{$s})
}
close(FILE);
# Print result
print "$_\n" for (sort { $results{$b} <=> $results{$a} } keys %results);