Aspell(3pm) | User Contributed Perl Documentation | Aspell(3pm) |
Text::Aspell - Perl interface to the GNU Aspell library
use Text::Aspell; my $speller = Text::Aspell->new; die unless $speller; # Set some options $speller->set_option('lang','en_US'); $speller->set_option('sug-mode','fast'); # check a word print $speller->check( $word ) ? "$word found\n" : "$word not found!\n"; # lookup up words my @suggestions = $speller->suggest( $misspelled ); # lookup config options my $language = $speller->get_option('lang'); print $speller->errstr unless defined $language; # fetch a config item that is a list my @sgml_extensions = $speller->get_option_as_list('sgml-extension'); # fetch the configuration keys and their default settings my $options = $speller->fetch_option_keys; # or dump config settings to STDOUT $speller->print_config || $speller->errstr; # What dictionaries are installed as simple strings my @dicts = $speller->list_dictionaries; # or as an array of hashes @dicts = $speller->dictionary_info; print Data::Dumper::Dumper( \@dicts );
Here's an example how to create and use your own word list
Create a dictionary:
$ aspell --lang=en create master ./dictionary.local < space_separated_word_list
Then in your code:
use Text::Aspell; my $speller = Text::Aspell->new; die unless $speller; $speller->set_option('master','./dictionary.local'); # check a word print $speller->check( $word ) ? "$word found\n" : "$word not found!\n";
This module provides a Perl interface to the GNU Aspell 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 GNU C interface is described at:
http://aspell.net/man-html/Through-the-C-API.html#Through-the-C-API
It's worth looking over the way config and speller (manager) objects are created when using the Aspell C API as some of that is hidden in the Text::Aspell module.
For example, with Text::Aspell you do not have to explicitly create a speller object. The speller (manager) object is created automatically the first time you call suggest() or check().
Note also that once the speller object is created some (all?) config options cannot be changed. For example, setting configuration options such as "lang" are what determine what dictionary Aspell will use. Once the speller object is created that dictionary will be used. I.e. setting "lang" after the speller object is created will have no effect.
You MUST have installed GNU Aspell library version 0.50.1 or higher on your system before installing this Text::Aspell Perl module. If installing Aspell using your operating system's package management system, you may need to install the Aspell development package (for example, on Debian libaspell-dev).
Aspell can source can be downloaded from:
http://aspell.net
There have been a number of bug reports because people failed to install aspell before installing this module. This is an interface to the aspell library installed on your system, not a replacement for aspell.
You must also have the English 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:
Internally, new() creates an object to store Aspell structures (AspellConfig, AspellSpeller, and a space for an error string and then calls new_aspell_config();
You should set configuration options before calling the $speller->create_speller method. See the GNU Aspell documentation for the available configuration settings and how (and when) they may be used.
Returns "undef" on error, and the error message can be printed with $speller->errstr.
Note that this may return different results depending on if it's called before or after $speller->create_speller is called.
Returns "undef" on error, and the error message can be printed with $speller->errstr.
Note that this may return different results depending on if it's called before or after $speller->create_speller is called.
desc : A short description of the option default : The default value for this option type : The data type of option (see aspell.h)
This method is deprecated.
This calls $speller->create_speller if the speller has not been created by an explicit call to $speller->create_speller.
You might want to call this when your program first starts up to make the first access a bit faster, or if you need to read back configuration settings before looking up words.
The creation of the speller builds a configuration profile in the speller structure. Results from calling print_config() and get_option() will change after calling create_speller(). In general, it's best to read config settings back after calling create_speller() or after calling spell() or suggest(). Returns "undef" on error, and the error message can be printed with $speller->errstr.
(July 2005 note: best to ignore any return value for now)
[name]:[code]:[jargon]:[size]:[module]
Name and code will often be the same, but name is the complete name of the dictionary which can be used to directly select a dictionary, and code is the language/region code only.
{ 'module' => 'default', 'code' => 'en_US', 'size' => 60, 'jargon' => 'w-accents', 'name' => 'en_US-w-accents' },
Not all hash keys will be available for every dictionary (e.g. the dictionary may not have a "jargon" key).
Text::Aspell works with GNU Aspell and is a replacement for the module Text::Pspell. Text::Pspell is no longer supported.
Upgrading should be a simple process. Only one method name has changed: "create_manager" is now called "create_speller". Code designed to use the old Text::Pspell module may not even call the "create_manager" method so this may not be an issue.
The "language_tag" configuration setting is now called "lang".
Diffs for code that uses Text::Pspell might look like:
- use Text::Pspell; + use Text::Aspell; - $speller = Text::Pspell->new; + $speller = Text::Aspell->new; - $speller->create_manager || die "Failed to create speller: " . $speller->errstr; + $speller->create_speller || die "Failed to create speller: " . $speller->errstr;
If you used a custom dictionary installed in non-standard location and indexed the dictionary with Aspell/Pspell .pwli files you will need to change how you access your dictionary (e.g. by setting the "master" configuration setting with the path to the dictionary). See the GNU Aspell documentation for details.
Probably.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Bill Moseley moseley@hank.org.
This module is based on a perl module written by Doru Theodor Petrescu <pdoru@kappa.ro>.
Aspell is written and maintained by Kevin Atkinson.
Please see:
http://aspell.net
2020-11-09 | perl v5.32.0 |