Hunspell(3)

NAME
Text::Hunspell - Perl interface to the Hunspell library

SYNOPSIS
    use Text::Hunspell;

    # You can use relative or absolute paths.
    my $speller = Text::Hunspell->new(
        "/usr/share/hunspell/en_US.aff",    # Hunspell affix file
        "/usr/share/hunspell/en_US.dic"     # Hunspell dictionary file
    );

    die unless $speller;

    # Check a word against the dictionary
    my $word = 'opera';
    print $speller->check($word)
          ? "'$word' found in the dictionary\n"
          : "'$word' not found in the dictionary!\n";

    # Spell check suggestions
    my $misspelled = 'programmng';
    my @suggestions = $speller->suggest($misspelled);
    print "\n", "You typed '$misspelled'. Did you mean?\n";
    for (@suggestions) {
        print "  - $_\n";
    }

    # Add dictionaries later
    $speller->add_dic('dictionary_file.dic');

DESCRIPTION
This module provides a Perl interface to the Hunspell library. This module is to meet the need of looking up many words, one at a time, in a single session, such as spell-checking a document in memory.

The example code describes the interface on http://hunspell.sf.net

DEPENDENCIES
You MUST have installed the Hunspell library version 1.0 or higher on your system before installing this "Text::Hunspell" Perl module.

Hunspell location is:

    http://hunspell.sf.net

There have been a number of bug reports because people failed to install hunspell before installing this module.

This is an interface to the hunspell library installed on your system, not a replacement for hunspell.

You must also have one hunspell dictionary installed when running the module's test suite.

Also, please see the README and Changes files. README may have specific information about your platform.

METHODS
The following methods are available:

  Text::Hunspell->new($full_path_to_affix, $full_path_to_dic)
Creates a new speller object. Parameters are:

full path of affix (.aff) file
full path of dictionary (.dic) file

Returns "undef" if the object could not be created, which is unlikely.

  add_dic($path_to_dic)
Adds a new dictionary to the current "Text::Hunspell" object. This dictionary will use the same affix file as the original dictionary, so this is like using a personal word list in a given language. To check spellings in several different languages, use multiple "Text::Hunspell" objects.

  check($word)
Check the word. Returns 1 if the word is found, 0 otherwise.

  suggest($misspelled_word)
Returns the list of suggestions for the misspelled word.

The following methods are used for morphological analysis, which is looking at the structure of words; parts of speech, inflectional suffixes and so on. However, most of the dictionaries that Hunspell can use are missing this information and only contain affix flags which allow, for example, 'cat' to turn into 'cats' but not 'catability'. (Users of the French and Hungarian dictionaries will find that they have more information available.)

  analyze($word)
Returns the analysis list for the word. This will be a list of strings that contain a stem word and the morphological information about the changes that have taken place from the stem. This will most likely be 'fl:X' strings that indicate that affix flag 'X' was applied to the stem. Words may have more than one stem, and each one will be returned as a different item in the list.

However, with a French dictionary loaded, analyze('chanson') will return

  st:chanson po:nom is:fem is:sg

to tell you that "chanson" is a feminine singular noun, and analyze('chansons') will return

  st:chanson po:nom is:fem is:pl

to tell you that you've analyzed the plural of the same noun.

  stem($word)
Returns the stem list for the word. This is a simpler version of the results from analyze().

  generate2($stem, \@suggestions)
Returns a morphologically modified stem as defined in @suggestions (got by analysis).

With a French dictionary:

  $feminine_form = 'chanteuse';
  @ana = $speller->analyze($feminine_form);
  $ana[0] =~ s/is:fem/is:mas/;
  print $speller->generate2($feminine_form, \@ana)

will print 'chanteur'.

  generate($stem, $word)
Returns morphologically modified stem like $word.

  $french_speller->generate('danseuse', 'chanteur');

tells us that the masculine form of 'danseuse' is 'danseur'.

ENCODING
Note that Hunspell dictionaries often come in non-UTF-8 encodings. If your code uses UTF-8, you need to encode the strings into the needed encoding. For example Czech (files "cs_CZ.dic" and "cs_CZ.aff") uses ISO-8859-2:

  use utf8;
  use Encode;

  print $speller->check(encode('ISO-8859-2', "žluťoučký"))
        ? "found.\n"
        : "not found.\n";
}

BUGS
Probably. Yes, definitely.

LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHORS
Originally written by Eleonora, <eleonora46_at_gmx_dot_net>.

The current maintainer is Cosimo Streppone, <cosimo@cpan.org>

This module is based on Text::Aspell written by Bill Moseley moseley at hank dot org.

Hunspell is written as myspell by Kevin B. Hendricks.

Hunspell is maintained by Németh László.

Please see:

    http://hunspell.sf.net

For the dictionaries:

   https://wiki.openoffice.org/wiki/Dictionaries
   http://magyarispell.sf.net for Hungarian dictionary