-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhashbuild.pl
85 lines (72 loc) · 1.9 KB
/
hashbuild.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Storable;
binmode STDIN, ":utf8";
binmode STDOUT, ":utf8";
binmode STDERR, ":utf8";
my $verbose = 0;
my $extension = '';
for my $a (@ARGV) {
$verbose = 1 if ($a eq '-v');
$extension = '-gd' if ($a eq '-d');
$extension = '-gv' if ($a eq '-x');
}
my %spurious;
my %cands;
sub irishlc {
(my $w) = @_;
$w =~ s/^([nt])([AEIOUÁÉÍÓÚ])/$1-$2/;
$w =~ s/ ([nt])([AEIOUÁÉÍÓÚ])/ $1-$2/g;
return lc($w);
}
print "Loading spurious pairs...\n" if $verbose;
open(SPURIOUS, "<:utf8", "spurious$extension.txt") or die "Could not open list of spurious pairs: $!";
while (<SPURIOUS>) {
chomp;
$spurious{$_}++;
}
close SPURIOUS;
print "Loading clean word list...\n" if $verbose;
open(CLEAN, "<:utf8", "clean.txt") or die "Could not open clean wordlist: $!";
while (<CLEAN>) {
chomp;
push @{$cands{$_}}, $_ unless (exists($spurious{"$_ $_"}));
}
close CLEAN;
print "Loading list of pairs...\n" if $verbose;
open(PAIRS, "<:utf8", "pairs$extension.txt") or die "Could not open list of pairs: $!";
while (<PAIRS>) {
chomp;
next if exists($spurious{$_});
m/^([^ ]+) (.+)$/;
push @{$cands{$1}}, $2;
}
close PAIRS;
print "Loading multi-word phrase pairs...\n" if $verbose;
open(MULTI, "<:utf8", "multi$extension.txt") or die "Could not open list of phrases: $!";
while (<MULTI>) {
chomp;
m/^([^ ]+) (.+)$/;
my $source = $1;
my $target = $2;
push @{$cands{$source}}, $target;
if ($source =~ m/\p{Lu}/) {
push @{$cands{lc($source)}}, irishlc($target);
}
}
close MULTI;
print "Loading local pairs...\n" if $verbose;
open(LOCALPAIRS, "<:utf8", "pairs-local$extension.txt") or die "Could not open list of local pairs: $!";
while (<LOCALPAIRS>) {
chomp;
if (exists($spurious{$_})) {
print STDERR "Warning: pair \"$_\" is in pairs-local and spurious\n";
}
m/^([^ ]+) (.+)$/;
push @{$cands{$1}}, $2;
}
close LOCALPAIRS;
store \%cands, "cands$extension.hash";
exit 0;