-
Notifications
You must be signed in to change notification settings - Fork 3
/
lang-to-name.pl
executable file
·57 lines (53 loc) · 1.45 KB
/
lang-to-name.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
#!/usr/bin/env perl
# -*- mode: cperl; indent-tabs-mode: nil; tab-width: 3; cperl-indent-level: 3; -*-
# Copyright (C) 2014, Apertium Project Management Committee <[email protected]>
# Licensed under the GNU GPL version 2 or later; see https://www.gnu.org/licenses/
use utf8;
use strict;
use warnings;
BEGIN {
$| = 1;
binmode(STDIN, ':encoding(UTF-8)');
binmode(STDOUT, ':encoding(UTF-8)');
}
use open qw( :encoding(UTF-8) :std );
use FindBin qw($Bin);
use lib "$Bin/";
use Helpers;
my %ns = ();
my $names = file_get_contents('scraped-sil.tsv');
for my $l (split(/\n/, $names)) {
my @ls = split(/\t/, $l);
$ns{$ls[0]} = $ls[1];
}
my $isob = file_get_contents('isobork');
for my $l (split(/\n/, $isob)) {
my @ls = split(/\s+/, $l);
if (exists $ns{$ls[1]}) {
$ns{$ls[0]} = $ns{$ls[1]};
}
}
while (<STDIN>) {
chomp;
if (m@(?:apertium|giella)-(\w+)-(\w+)@) {
my ($iso1,$iso2) = ($1,$2);
if (!exists $ns{$iso1}) {
print "NOT FOUND: 1 $_ $iso1\n";
next;
}
if (!exists $ns{$iso2}) {
print "NOT FOUND: 2 $_ $iso2\n";
next;
}
print `perl -Mutf8 -pe 's/LANG1/$ns{$iso1}/g' -i $_`;
print `perl -Mutf8 -pe 's/LANG2/$ns{$iso2}/g' -i $_`;
}
elsif (m@(?:apertium|giella)-(\w+)@) {
my ($iso1) = ($1);
if (!exists $ns{$iso1}) {
print "NOT FOUND: 1 $_ $iso1\n";
next;
}
print `perl -Mutf8 -pe 's/LANG1/$ns{$iso1}/g' -i $_`;
}
}