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.
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.
13 # For now expected the input to be in ASCII or iso-8859-1.
24 print STDERR "$0: [munch|expand] AFFIX_FILE < INPUT\n";
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];
36 open F, $affix_fn or die "Unable to open: $affix_fn\n";
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.
45 $affix_file =~ s/^SET UTF-8$/SET ISO8859-1/m;
47 my $datadir = File::Temp->newdir();
49 open F, ">$datadir/eng_affix.dat";
52 open F, ">$datadir/eng.dat";
54 print F "charset iso8859-1\n";
55 print F "special ' -*-\n";
56 print F "affix eng\n";
58 if ($action eq 'munch') {
59 open F, '-|', $ASPELL, '--local-data-dir', $datadir, '--lang', 'eng', 'munch-list';
61 next if /^(XXX\|>>>)/;
64 } elsif ($action eq 'expand') {
65 open F, '-|', $ASPELL, '--local-data-dir', $datadir, '--lang', 'eng', 'expand';