-
Notifications
You must be signed in to change notification settings - Fork 1
/
make-test.pl
94 lines (81 loc) · 2.58 KB
/
make-test.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
86
87
88
89
90
91
92
93
use utf8;
use TeX::Hyphen;
binmode(STDOUT, ":utf8");
binmode(STDIN, ":encoding(utf8)");
$file_simple_hyph = $ARGV[0];
$file_new_hyph = $ARGV[1];
my $hyp = new TeX::Hyphen 'file' => $file_simple_hyph, 'style' => 'utf8', leftmin => 1, rightmin => 1;
my $newhyp = new TeX::Hyphen 'file' => $file_new_hyph, 'style' => 'utf8', leftmin => 1, rightmin => 1;
print STDERR "Making hyphenation patterns tests...\n";
my $f1="errors-comuns.txt";
my $f2="errors-excepcions.txt";
my $f3="resum-resultats.txt";
open (FILE1, ">:encoding(utf-8)", "$f1") or die "Could not open file: $! \n";
open (FILE2, ">:encoding(utf-8)", "$f2") or die "Could not open file: $! \n";
open (FILE3, ">:encoding(utf-8)", "$f3") or die "Could not open file: $! \n";
my $wordCorrectHyphen="";
my $word="";
my $hsword="";
my $hcword="";
my $total=0;
my $excep=0;
my $excep_errors=0;
my $excep_correctes=0;
my $excep_errors_new=0;
my $excep_correctes_new=0;
my $comuns=0;
my $comuns_errors=0;
my $comuns_correctes=0;
while (my $line=<STDIN>) {
chomp($line);
if ($line =~ /^([^ #]+) ?(.*)/)
{
$total++;
$word=$1;
$wordCorrectHyphen="";
if ($2) {$wordCorrectHyphen=$2; $wordCorrectHyphen =~ s/-/_/g;}
#simple rules hyphenation
$hsword = $hyp->visualize($word);
$hsword =~ s/·//g;
$hsword =~ s/--/-/;
$hsword =~ s/-/_/g;
#new hyphenation
$hcword = $newhyp->visualize($word);
$hcword =~ s/·//g;
$hcword =~ s/--/-/;
$hcword =~ s/-/_/g;
$hcword =~ s/__/_/g;
if ($wordCorrectHyphen=~ /.+/) {
$excep++;
if ($hsword =~ /^$wordCorrectHyphen$/) {$excep_correctes++;}
if ($hsword !~ /^$wordCorrectHyphen$/) {$excep_errors++;}
if ($hcword =~ /^$wordCorrectHyphen$/) {$excep_correctes_new++;}
if ($hcword !~ /^$wordCorrectHyphen$/) {
$excep_errors_new++;
print FILE2 "$word $wordCorrectHyphen --> $hsword $hcword\n";
}
print "$word $wordCorrectHyphen --> $hsword $hcword\n";
}
else {
$comuns++;
if ($hcword =~ /^$hsword$/) {$comuns_correctes++;}
if ($hcword !~ /^$hsword$/) {
$comuns_errors++;
print FILE1 "$word --> $hsword $hcword\n";
}
print "$word --> $hsword $hcword\n";
}
}
}
print FILE3 "Total=$total\n";
print FILE3 "Excepcions=$excep\n";
print FILE3 "Excepcions correctes=$excep_correctes\n";
print FILE3 "Excepcions errors=$excep_errors\n";
print FILE3 "Excepcions correctes (nou)=$excep_correctes_new\n";
print FILE3 "Excepcions errors (nou)=$excep_errors_new\n";
print FILE3 "Comuns=$comuns\n";
print FILE3 "Comuns correctes=$comuns_correctes\n";
print FILE3 "Comuns errors=$comuns_errors\n";
close (FILE1);
close (FILE2);
print STDERR "Tests done\n";