Lingua::Ispell(3pm)
๐ Lingua::Ispell(3pm) ๐
okay bestie, gather round, because this is Lingua::Ispell.pm โ a module that wraps up access to the Ispell program. that's the whole vibe. it's a Perl module, it's for spelling, it's giving helper-energy. ๐ฆ
๐จ lore drop: this module used to be calledText::Ispell. if you've gotText::Ispellinstalled on your system, bestie it is obsolete and you should replace it withLingua::Ispell. no cap.
๐ธ NOTA BENE ๐ธ
okay so here's the situation, and it's a little chaotic. when ispell reports a misspelled word, it tells you the string it couldn't verify and its starting offset in the input line. but for words it thinks are spelled correctly? it tells you nothing. like, zero info. for example, in a line like "Can't buy a thrill", ispell will just be like "yeah that line had four correctly spelled words" and move on. ๐
Lingua::Ispell wants to know which substrings of the input line are words โ correctly spelled or not. it used to try splitting the input line into words using the exact same rules ispell uses, but bestie that turned out to be so difficult, and the result was code that was slow and error-prone. it's giving "we tried our best". ๐ญ
โจ Consequences โจ
Lingua::Ispellnow operates only in"terse"mode. in this mode, only misspelled words get reported. words that ispell verifies as correctly spelled are just silently accepted. ๐ค- in the report structures returned by
spellcheck(), the'term'member is now always identical to the'original'member. of the two, you should probably use the'term'member. (also consider the'offset'member.) ispell doesn't report this info for correctly spelled words, and if at some point in the future that capability gets added to ispell,Lingua::Ispellwill be updated to take advantage of it. ๐ - use of the
$word_charsvariable has been removed. setting it no longer has any effect. it's giving ghost. ๐ป terse_mode()now does nothing.
๐ SYNOPSIS ๐
# Brief:
use Lingua::Ispell;
Lingua::Ispell::spellcheck( $string );
# or
use Lingua::Ispell qw( spellcheck ); # import the function
spellcheck( $string );
# Useful:
use Lingua::Ispell qw( :all ); # import all symbols
for my $r ( spellcheck( "hello hacking perl shrdlu 42" ) ) {
print "$r->{'type'}: $r->{'term'}\n";
}
๐ DESCRIPTION ๐
Lingua::Ispell::spellcheck() takes one argument. it must be a string, and it should contain only printable characters. one allowable exception is a terminal newline, which will be chomped off anyway. the line gets fed to a coprocess running ispell for analysis, and ispell parses the line into "terms" according to the language-specific rules in effect. โจ
the result of ispell's analysis of each term is a categorization of that term into one of six types: ok, compound, root, miss, none, and guess. some of these carry extra info. the first three types are the "correctly" spelled terms, and the last three are for the "incorrectly" spelled terms. ๐
Lingua::Ispell::spellcheck returns a list of objects, each one corresponding to a term in the spellchecked string. each object is a hash (hash-ref) with at least two entries: 'term' and 'type'. the former contains the term ispell is reporting on, and the latter is ispell's determination of that term's type (see above). for types 'ok' and 'none', that is all the information there is. for the type 'root', an additional hash entry is present: 'root' โ its value is the word which ispell identified in the dictionary as being the likely root of the current term. for the type 'miss', an additional hash entry is present: 'misses' โ its value is a ref to an array of words which ispell identified as being "near-misses" of the current term, when scanning the dictionary. ๐ซถ
๐ NOTE ๐
as mentioned above, "Lingua::Ispell::spellcheck()" currently only reports on misspelled terms. periodt.
โญ EXAMPLE โญ
use Lingua::Ispell qw( spellcheck );
Lingua::Ispell::allow_compounds(1);
for my $r ( spellcheck( "hello hacking perl salmoning fruithammer shrdlu 42" ) ) {
if ( $r->{'type'} eq 'ok' ) {
# as in the case of 'hello'
print "'$r->{'term'}' was found in the dictionary.\n";
}
elsif ( $r->{'type'} eq 'root' ) {
# as in the case of 'hacking'
print "'$r->{'term'}' can be formed from root '$r->{'root'}'\n";
}
elsif ( $r->{'type'} eq 'miss' ) {
# as in the case of 'perl'
print "'$r->{'term'}' was not found in the dictionary;\n";
print "Near misses: @{$r->{'misses'}}\n";
}
elsif ( $r->{'type'} eq 'guess' ) {
# as in the case of 'salmoning'
print "'$r->{'term'}' was not found in the dictionary;\n";
print "Root/affix Guesses: @{$r->{'guesses'}}\n";
}
elsif ( $r->{'type'} eq 'compound' ) {
# as in the case of 'fruithammer'
print "'$r->{'term'}' is a valid compound word.\n";
}
elsif ( $r->{'type'} eq 'none' ) {
# as in the case of 'shrdlu'
print "No match for term '$r->{'term'}'\n";
}
# and numbers are skipped entirely, as in the case of 42.
}
๐ ERRORS ๐
"Lingua::Ispell::spellcheck()" starts the ispell coprocess if the coprocess seems not to exist. ordinarily this is simply the first time it's called. ๐
ispell is spawned via the "Open2::open2()" function, which throws an exception (i.e. dies) if the spawn fails. the caller should be prepared to catch this exception โ unless, of course, the default behavior of die is acceptable. no judgement either way, bestie. ๐ซถ
๐ง Nota Bene ๐ง
the full location of the ispell executable is stored in the variable $Lingua::Ispell::path. the default value is /usr/bin/ispell. if your ispell executable has some name other than this, then you must set $Lingua::Ispell::path accordingly before you call "Lingua::Ispell::spellcheck()" (or any other function in the module) for the first time! this is a real one, don't skip it. โ ๏ธ
๐ AUX FUNCTIONS ๐
๐ธ add_word(word)
adds a word to the personal dictionary. be careful of capitalization, bestie. if you want the word added "case-insensitively", you should call "add_word_lc()" instead. ๐
๐ธ add_word_lc(word)
adds a word to the personal dictionary, in lower-case form. this allows ispell to match it in a case-insensitive manner. slay. โจ
๐ธ accept_word(word)
similar to adding a word to the dictionary, in that it causes ispell to accept the word as valid โ but it does not actually add it to the dictionary. presumably the effects of this only last for the current ispell session, which will mysteriously end if any of the coprocess-restarting functions are called... ๐ฎ
๐ธ parse_according_to(formatter)
causes ispell to parse subsequent input lines according to the specified formatter. as of ispell v. 3.1.20, only 'tex' and 'nroff' are supported. ๐
๐ธ set_params_by_language(language)
causes ispell to set its internal operational parameters according to the given language. legal arguments to this function, and its effects, are currently unknown by the author of Lingua::Ispell. iconic honesty tbh. ๐คท
๐ธ save_dictionary()
causes ispell to save the current state of the dictionary to its disk file. presumably ispell would ordinarily only do this upon exit. ๐พ
๐ธ terse_mode(bool:terse)
NOTE: This function has been disabled! Lingua::Ispell now always operates in terse mode.
in terse mode, ispell will not produce reports for "correct" words. this means that the calling program will not receive results of the types 'ok', 'root', and 'compound'. ๐
๐ฅ FUNCTIONS THAT RESTART ISPELL ๐ฅ
the following functions cause the current ispell coprocess, if any, to terminate. this means that all the changes to the state of ispell made by the above functions will be lost, and their respective values reset to their defaults. the only function above whose effect is persistent is "save_dictionary()". ๐ค
perhaps in the future we will figure out a good way to make this state information carry over from one instantiation of the coprocess to the next. manifesting it. ๐ฏ๏ธโจ
๐ allow_compounds(bool)
when this value is set to True, compound words are accepted as legal โ as long as both words are found in the dictionary; more than two words are always illegal. when this value is set to False, run-together words are considered spelling errors. ๐ซ
the default value of this setting is dictionary-dependent, so the caller should set it explicitly if it really matters. fr fr.
๐ make_wild_guesses(bool)
this setting controls when ispell makes "wild" guesses.
- if False, ispell only makes "sane" guesses, i.e. possible root/affix combinations that match the current dictionary; only if it can find none will it make "wild" guesses, which don't match the dictionary, and might in fact be illegal words. ๐
- if True, wild guesses are always made, along with any "sane" guesses. this feature can be useful if the dictionary has a limited word list, or a word list with few suffixes. ๐ฅ
the default value of this setting is dictionary-dependent, so the caller should set it explicitly if it really matters. yes, again. it's giving consistent.
๐ use_dictionary([dictionary])
specifies what dictionary to use instead of the default. dictionary names are actually file names, and are searched for according to the following rule: if the name does not contain a slash, it is looked for in the directory containing the default dictionary, typically /usr/lib. otherwise, it is used as is: if it does not begin with a slash, it is construed from the current directory. ๐
if no argument is given, the default dictionary will be used.
๐ use_personal_dictionary([dictionary])
specifies what personal dictionary to use instead of the default.
dictionary names are actually file names, and are searched for according to the following rule: if the name begins with a slash, it is used as is (i.e. it is an absolute path name). otherwise, it is construed as relative to the user's home directory ($HOME). ๐
if no argument is given, the default personal dictionary will be used.
๐ฆ FUTURE ENHANCEMENTS ๐ฆ
ispell options:
-w chars
Specify additional characters that can be part of a word.
๐ DEPENDENCIES ๐
Lingua::Ispell uses the external program ispell, which is the "International Ispell", available at
http://fmg-www.cs.ucla.edu/geoff/ispell.html
as well as various archives and mirrors, such as
ftp://ftp.math.orst.edu/pub/ispell-3.1/
this is a very popular program, and may already be installed on your system. ๐
Lingua::Ispell also uses the standard perl modules FileHandle, IPC::Open2, and Carp. ๐ซถ
๐ AUTHOR ๐
jdporter@min.net (John Porter)
๐ COPYRIGHT ๐
this module is free software; you may redistribute it and/or modify it under the same terms as Perl itself. ๐
and that's the whole page bestie, โจ perl v5.36.0 โจ dated โจ 2022-10-13 โจ โ go forth and spellcheck responsibly, mwah ๐
๐
๐ฆ where this page comes from
- ubuntu noble: liblingua-ispell-perl 0.07-8
- ubuntu resolute: liblingua-ispell-perl 0.07-8
- ubuntu stonking: liblingua-ispell-perl 0.07-8
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms