Print

Print


On Apr 3, 2007, at 12:40 PM, Kevin Kierans wrote:

> Has anyone created their own "dictionaries" for aspell?  We've
> created blank delimited lists of words from our opac.  One for
> title, one for subjects, and one for authors.  (We're thinking of
> a series one as well)


I can answer this one, and this trick was taught to my Bill Moseley
of swish-e fame. Here is my code to create the dictionary:

   #!/usr/bin/perl

   # define a few contants
   my $ASPELL = '/usr/local/bin/aspell --lang=en create master /path/
to/where/your/dictionary/will/live';

   # practice good programming
   use strict;

   # initialize input and output words
   my $words  = undef;

   # create a return-delimited list of words
   my $words = "word01\nword02\nword03...";

   # create a dictionary
   open OUTPUT, "| $ASPELL";
   print OUTPUT $words;
   close OUTPUT;

   # done; too simple!
   exit;

Here is a subroutine to query a dictionary and return suggestions:

  sub suggest_spellings {

    my @words = @_;

    # open the dictionary
    my $dictionary = Text::Aspell->new;
    $dictionary->set_option( 'master', 'musings.dict');

    # loop through the words looking them up in the dictionary and
listing spellings
    my $spellings = '';
    foreach ( @words ) {

      my @suggestions = $dictionary->suggest( $_ );
      foreach my $suggestion ( @suggestions ) {

        $spellings .= $suggestion . "\t" );

      }

    }

    return $spellings ;

   }

--
Eric Lease Morgan
University Libraries of Notre Dame

(574) 631-8604