-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutinfo.pl
66 lines (59 loc) · 1.44 KB
/
mutinfo.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
use strict;
use warnings;
my %ENGLISH;
my %IRISH;
my %ENGFREQ;
my %IRISHFREQ;
my $cutoff = 2;
my $cosinecutoff = 0.3;
my $ratiolower = $cosinecutoff*$cosinecutoff;
my $ratioupper = 1/$ratiolower;
die "Usage: $0 BEARLA GAEILGE\n" unless ($#ARGV == 1);
open (BEARLA, $ARGV[0]) or die "Error opening English: $!\n";
while (<BEARLA>) {
chomp;
my ($word, $hits) = m/^([^:]+): (.*)$/;
my @arr = split / /,$hits;
if (@arr > $cutoff) {
$ENGLISH{$word} = $hits;
$ENGFREQ{$word} = @arr;
}
}
close BEARLA;
open (GAEILGE, $ARGV[1]) or die "Error opening Irish: $!\n";
while (<GAEILGE>) {
chomp;
my ($word, $hits) = m/^([^:]+): (.*)$/;
my @arr = split / /,$hits;
if (@arr > $cutoff) {
$IRISH{$word} = $hits;
$IRISHFREQ{$word} = @arr;
}
}
close GAEILGE;
foreach my $english (sort keys %ENGLISH) {
my $engfreq = $ENGFREQ{$english};
my %seen;
my $best;
my $bestcos = 0;
for (split / /,$ENGLISH{$english}) {
$seen{$_}++;
}
foreach my $irish (keys %IRISH) {
my $irishfreq = $IRISHFREQ{$irish};
my $ratio = $irishfreq/$engfreq;
if ($ratio < $ratioupper and $ratio > $ratiolower) {
my $common = 0;
for (split / /,$IRISH{$irish}) {
$common++ if (exists($seen{$_}));
}
my $cos = $common/(sqrt($engfreq)*sqrt($irishfreq));
if ($cos > $cosinecutoff and $cos > $bestcos) {
$bestcos = $cos;
$best = sprintf "%1.3f|$english|$irish|$common $engfreq $irishfreq", $cos;
}
}
}
print "$best\n" if ($bestcos > 0);
}