]> git.donarmstrong.com Git - deb_pkgs/scowl.git/blob - speller/munch-list
New upstream version 2018.04.16
[deb_pkgs/scowl.git] / speller / munch-list
1 #!/usr/bin/perl
2
3 #
4 # Quick and dirty script to use aspell to munch and expand a hunspell
5 # list.  For munching using Aspell gives much better results than the
6 # hunspell scripts for expanding hunspell could theoretical be used
7 # but it just as easy to use Aspell.
8 #
9 # Note. this script is only intended to work with english.  Other
10 # languages might work but the hunspell Affix file needs to be
11 # compatible with Aspell.
12 #
13 # For now expected the input to be in ASCII or iso-8859-1.
14 #
15
16 my $ASPELL="aspell";
17
18 use strict;
19 use warnings;
20
21 use File::Temp;
22
23 sub usage() {
24     print STDERR "$0: [munch|expand] AFFIX_FILE < INPUT\n";
25     exit 1;
26 }
27
28 usage() unless @ARGV == 2;
29 my $action = $ARGV[0];
30 usage() unless $action eq 'munch' or $action eq 'expand';
31 my $affix_fn = $ARGV[1];
32 my $affix_file;
33
34 {
35     local $/ = undef;
36     open F, $affix_fn or die "Unable to open: $affix_fn\n";
37     $affix_file = <F>;
38 }
39
40 # Aspell expects the dictionary to be in iso8859-1 so fake it for now.
41 # The fact that there may be some Hunspell specific entries in UTF-8
42 # (such as the ICONV entry) should not be a problem as Aspell ignores
43 # it.  The words them self are already in iso8859-1.
44  
45 $affix_file =~ s/^SET UTF-8$/SET ISO8859-1/m;
46
47 my $datadir = File::Temp->newdir();
48
49 open F, ">$datadir/eng_affix.dat";
50 print F $affix_file;
51
52 open F, ">$datadir/eng.dat";
53 print F "name eng\n";
54 print F "charset iso8859-1\n";
55 print F "special ' -*-\n";
56 print F "affix eng\n";
57
58 if ($action eq 'munch') {
59     open F, '-|', $ASPELL, '--local-data-dir', $datadir, '--lang', 'eng', 'munch-list';
60     while (<F>) {
61         next if /^(XXX\|>>>)/;
62         print;
63     }
64 } elsif ($action eq 'expand') {
65     open F, '-|', $ASPELL, '--local-data-dir', $datadir, '--lang', 'eng', 'expand';
66     while (<F>) {
67         foreach (split ' ') {
68             print "$_\n";
69         }
70     }
71 }