Tuesday, February 05, 2008

Linux : Checks a file for spelling errors

aspell check [options]filename

aspell list [options] < filename

aspell config

aspell help


The aspell utility checks the spelling of words in a document against a standard dictionary. You can use aspell interactively: It displays each misspelled word in context, together with a menu that gives you the choice of accepting the word as is, choosing one of aspell's suggested replacements for the word, inserting the word into your personal dictionary, or replacing the word with one you enter. You can also use aspell in batch mode so that it reads from standard input and writes to standard output.

tip: aspell is not like other utilities regarding its input

Unlike many other utilities, aspell does not accept input from standard input when you do not specify a filename on the command line. Instead, the action specifies where aspell gets its input.


Action

You must choose one and only one action when you run aspell.

check

–c

Runs aspell as an interactive spelling checker. Input comes from a single file named on the command line. Refer to "Discussion" on page 590.

config

Displays aspell's configuration, both default and current values. Send the output through a pipe to less for easier viewing, or use grep to find the option you are looking for (for example, aspell config | grep backup).

help

–?

Displays an extensive page of help. Send the output through a pipe to less for easier viewing.

list

–l

Runs aspell in batch mode (noninteractively) with input coming from standard input and output going to standard output.


Arguments

The filename is the name of the file you want to check. The aspell utility accepts this argument only when you use the check (–c) action. With the list (–l) action, input must come from standard input.

Options

The aspell utility has many options. A few of the more commonly used ones are listed in this section; see the manual for a complete list. Default values of many options are determined when aspell is compiled (see the config action).

You can specify options on the command line, in value of the ASPELL_CONF shell variable, or in your personal configuration file (~/.aspell.conf). Superuser can create a global configuration file (/etc/aspell.conf). Put one option per line in a configuration file; separate options with a semicolon (;) in ASPELL_CONF. Options on the command line override those in ASPELL_CONF, which override those in your personal configuration file, which override those in the global configuration file.

There are two types of options in the following list: Boolean and value. The Boolean options turn a feature on (enable the feature) or off (disable the feature). Precede a Boolean option with dont– to turn it off. For example, ––ignore-case turns the ignore-case feature on and ––dont-ignore-case turns it off.

Value options assign a value to a feature. Follow the option with an equal sign and a value—for example, ––ignore=4.

For all options in a configuration file or in the ASPELL_CONF variable, drop the leading hyphens (ignore-case or dont-ignore-case).

caution: aspell options and leading hyphens

The way you specify options differs depending on whether you are specifying them on the command line, using the ASPELL_CONF shell variable, or in a configuration file.

On the command line prefix long options with two hyphens (for example, ––ignore-case or ––dont-ignore-case). In ASPELL_CONF and configuration files, drop the leading hyphens (for example, ignore-case or dont-ignore-case).


––dont-backup

Does not create a backup file named filename.bak (default is ––backup when action is check).

––ignore=n

Ignores words with n or fewer characters (default is 1).

––ignore-case

Ignores the case of letters in words being checked (default is ––dont-ignore-case).

––lang=cc

Specifies the two-letter language code (cc). The language code defaults to the value of LC_MESSAGES (page 291).

––mode=mod

Specifies a filter to use. Select mod from url (default), none, sgml, and others. The modes work as follows: url: skips URLs, hostnames, and email addresses; none: turns off all filters; sgml: skips SGML, HTML, XHTML, and XML commands.

––strip-accents

Removes accent marks from all the words in the dictionary before checking words (default is ––dont-strip-accents).


Discussion

The aspell utility has two basic modes of operation: batch and interactive. You specify batch mode by using the list or –l action. In batch mode aspell takes the document you want to check for spelling errors as standard input and sends the list of potentially misspelled words to standard output.

You specify interactive mode by using the check or –c action. In interactive mode aspell displays a screen with the potentially misspelled word in context highlighted in the middle and a menu of choices at the bottom. See "Examples" for an illustation. The menu includes various commands (Table V-3) as well as some suggestions of similar, correctly spelled words. You either enter one of the numbers from the menu to select a suggested word to replace the word in question or enter a letter to give a command.

Table V-3. Commands

Command

Action

SPACE

Takes no action and goes on to next the misspelled word.

n

Replaces the misspelled word with suggested word number n.

a

Adds the "misspelled" word to your personal dictionary.

b

Aborts aspell; does not save changes.

i or I (letter "i")

Ignores the misspelled word. I (uppercase "I") ignores all occurrences of this word; i ignores this occurrence only and is the same as SPACE.

l (lowercase "l")

Shifts the "misspelled" word to lowercase and adds it to your personal dictionary.

r or R

Replaces the misspelled word with the word that you enter at the bottom of the screen. R replaces all occurrences of this word; r replaces this occurrence only.

x

Saves the file as corrected so far and exits from aspell.


Notes

For more information refer to the /usr/share/doc/aspell directory with manuals in the man-html and man-text subdirectories and to the aspell home page located at aspell.sourceforge.net.

The aspell utility is not a foolproof way of finding spelling errors. It also does not check for misused, properly spelled words (such as red instead of read).

Spelling from emacs

You can make it easy to use aspell from emacs by adding the following line to your ~/.emacs file. This line causes emacs' ispell functions to call aspell:

(setq-default ispell-program-name "aspell")


Spelling from vim

Similarly, you can make it easy to use aspell from vim by adding the following line to your ~/.vimrc file:

map ^T :w!:!aspell check %:e! %


When you enter this line in ~/.vimrc using vim, enter the ^T as CONTROL-V CONTROL-T (page 159). With this line in ~/.vimrc, CONTROL-T brings up aspell to spell check the file you are editing with vim.

Examples

The following examples use aspell to correct the spelling in the memo.txt file:

$ cat memo.txt

Here's a document for teh aspell utilitey

to check. It obviosly needs proofing

quiet badly.


The first example uses aspell with the check action and no options. The appearance of the screen for the first misspelled word, teh, is shown. At the bottom of the screen is the menu of commands and suggested words. The numbered words each differ slightly from the misspelled word:

$ aspell check memo.txt





Here's a document for teh aspell utilitey

to check. It obviosly needs proofing

quiet badly.



============================================================

1) the 6) th

2) Te 7) tea

3) tech 8) tee

4) Th 9) Ted

5) eh 0) tel

i) Ignore I) Ignore all

r) Replace R) Replace all

a) Add l) Add Lower

b) Abort x) Exit

============================================================

?


Enter one of the menu choices in response to the preceding display; aspell will do your bidding and move the highlight to the next misspelled word (unless you choose to abort or exit).

The next example uses the list action to display a list of misspelled words. The word quiet is not in the list—it is not properly used but is properly spelled.

$ aspell list <>

teh

aspell

utilitey

obviosly


The last example also uses the uses the list action. It shows a quick way to check the spelling of a word or two with a single command. The user gives the aspell list command and then enters seperate temperature into aspell's standard input (the keyboard). After the user enters RETURN and CONTROL-D (to mark the end of file), aspell writes the misspelled word to standard output (the screen):

$ aspell list

seperate temperatureRETURN

CONTROL-D

seperate

No comments: