View on
Eleonora > text_hunspell > Text::Hunspell



Annotate this POD


New  2
Open  0
View/Report Bugs
Module Version: 1.21   Source  


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


    use Text::Hunspell;
    my $speller = Text::Hunspell->new("/../language.aff","/../language.dic");

    die unless $speller;

   # Set some words
    my $word = "lótól";
    my $word1 = "lóotól";
    my $misspelled = "lóo";

    # check a word
    print $speller->check( $word )
          ? "$word found\n"
          : "$word not found!\n";

    # check a word
    print $speller->check( $word )
          ? "$word found\n"
          : "$word not found!\n";
    print $speller->check( $word1 )
          ? "$word1 found\n"
          : "$word1 not found!\n";

    # lookup up words
    my @suggestions;
    @suggestions = $speller->suggest( $misspelled );
    print Data::Dumper::Dumper( \@suggestions ); 

    @suggestions = $speller->analyze($word);
    print Data::Dumper::Dumper( \@suggestions ); 
    @suggestions = $speller->stem($word);
    print Data::Dumper::Dumper( \@suggestions ); 

    # Test here generator for morphological modification (NOM->ACC)
    @suggestions = $speller->analyze($stem);
    $count = @suggestions;

    # modify analyze output for required class (ACC)
    for($i = 0; $i < $count; $i++){
       $res = @suggestions[$i];
       $res =~ s/NOM/ACC/g;
       @suggestions[$i] = $res;
    # generate ACC class of stem
    @suggestions = $speller->generate2($stem, \@suggestions);
    # end of generator for morphological modification (NOM->ACC) test 

    # test generator for mrphological modification, modify $stem like $word
    @suggestions = $speller->generate($stem, $word);

    # delete speller class


This module provides a Perl interface to the Oo 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


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

hunspell location is:

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.


The following methods are available:

$speller = Text::Hunspell->new(full_path_to_affix, full_path_to_dic);

Creates a new speller object. New takes the parameters full_path_of_affix file and full_path_of_dic file Returns undef if the object could not be created, which is unlikely.

Internally, new() creates the hunspell class.

$speller->check($word); check the word. Passes back 1, if the word found, 0 otherwise.

Passes back the list of suggestions for the misspelled word.


Passes back the analyzis list for the word.


Passes back the stem list for the word.

$speller->generate2($stem, \@suggestions);

Passes back morphologically modified stem as defined in @suggestions (got by analyzis)

$speller->generate($stem, $word);

Passes back morphologically modified stem like $word

$string = $speller->delete($speller);

deletes the speller class.




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


Eleonora eleonora46_at_gmx_dot_net

This module is based on a perl module (Text::Aspell) written by Bill Moseley

Hunspell is written as myspell by Kevin B. Hendricks, hunspell is maintained by Németh László

Please see:
for the dictionaries: for Hungarian dictionary
syntax highlighting: