Home Command line utilities GNU Aspell – A Free, Open Source And Independent Spell Checker

GNU Aspell – A Free, Open Source And Independent Spell Checker

By sk
Published: Updated: 3.6K views

Today, we are going to talk about GNU Aspell, a free, open source and independent spell checker. You can use it either as a library or an independent spell checker on your Unix-like operating systems. Aspell will suggest the possible replacement for your misspelled words in a word/document. Unlike other spell checkers like Ispell, Aspell can also easily check documents in UTF-8 without having to use a special dictionary. It also has support for using multiple dictionaries at once. In this brief tutorial, we will see how to install Aspell and how to use it to check spelling mistakes in a given word and/or document.

Install GNU Aspell spell checker in Linux

GNU Aspell is available in the default repositories of most Linux distributions, so installation won't be a big deal.

On Arch Linux and derivatives like Antergos, Manjaro Linux, run:

$ sudo pacman -S aspell

On Fedora:

$ sudo dnf install aspell

On RHEL, CentOS:

$ sudo yum install epel-release
$ sudo yum install aspell

On Debian, Ubuntu:

$ sudo apt-get install aspell

Adding dictionaries

By default, Aspell won't have any dictionaries. To add a dictionary, for example English, just install this package - aspell-en. Similarly, to add Spanish dictionary, install aspell-es package.

This can also be found in the default repositories. For instance, to add English dictionary on Arch linux, run:

$ sudo pacman -S aspell-en

On Debian, Ubuntu:

$ sudo apt-get install aspell-en

On Fedora:

$ sudo dnf install aspell-en

On RHEL/CentOS:

$ sudo yum install aspell-en

To add Spanish dictionary, use the following commands:

Arch linux:

$ sudo pacman -S aspell-es

Debian/Ubuntu:

$ sudo apt-get install aspell-es

Fedora:

$ sudo dnf install aspell-es

RHEL/CentOS:

$ sudo yum install aspell-es

Once you installed all dictionaries, you can ensure whether the required dictionaries are available or not using command:

$ aspell dicts
en
en-variant_0
en-variant_1
en-variant_2
en-w_accents
en-wo_accents
en_CA
en_CA-variant_0
en_CA-variant_1
en_CA-w_accents
en_CA-wo_accents
en_GB
en_GB-ise
en_GB-ise-w_accents
en_GB-ise-wo_accents
en_GB-ize
en_GB-ize-w_accents
en_GB-ize-wo_accents
en_GB-variant_0
en_GB-variant_1
en_GB-w_accents
en_GB-wo_accents
en_US
en_US-variant_0
en_US-variant_1
en_US-w_accents
en_US-wo_accents
es

Well, I have two dictionaries installed in my system, English (including its variants) and Spanish. Now let us see how to spell check a word or a document using Aspell.

Check spelling mistakes using GNU Aspell spell checker in words or documents

Spell Check single words

By default, Aspell uses English language to check spelling.

Let us check the spelling of a word. To do so, type:

$ aspell -a

Now type any misspelled word. Aspell will compare the given word with dictionaries ad will display the possible suggestions for the correct spelling.

@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.6.1)
englsh
& englsh 7 0: English, Englisher, Engels, English's, Englishes, Engels's, encl

If you type the correct spelled word, it will display an asterisk.

$ aspell -a
@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.6.1)
English
*

To use different language, for example Spanish, just use '-l' flag with language code as shown below:

$ aspell -a -l es
@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.6.1)
Holla 
& Holla 30 0: Hola, Halla, Holea, Hollé, Holló, Hulla, Hila, Hollad, Hollar, Hiela, Huella, Olla, Hala, Bolla, Folla, Molla, Polla, Rolla, Solla, Tolla, Halle, Hallo, Hallé, Halló, Helea, Holee, Holeo, Holeé, Holeó, Huela

Here, "es" is the language code for Spanish language.

We can also check spelling mistakes in different variant of a language. For example, to check spelling errors in Canadian English dictionary, use -d and the language format (you can view the available English variants using "aspell dicts" command).

$ aspell -a -d en_CA

To exit spell checking, type CTRL+c.

You can also use 'echo' command in conjunction with aspell to check for spelling mistakes of a word. Take a look at the following example.

$ echo englsh | aspell -a

Sample output would be:

@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.6.1)
& englsh 7 0: English, Englisher, Engels, English's, Englishes, Engels's, encl

As you can see, Aspell suggest the possible replacements for the misspelled word 'englsh'.

If you want to check spelling in another language, for example Spanish, use "-l" flag along with the language code like below.

$ echo englsh | aspell -a -l es

To check spelling of a misspelled word in Canadian English dictionary, run:

$ echo englsh | aspell -a -d en_CA

Alternatively, you can spell check a word as below.

$ aspell -a <<< englsh

Or, use this instead if you wanted to check spelling in another language.

$ aspell -a -l es <<< englsh

Spell check a file

I have a file ostechnix.txt with few lines in it. Here is the contents of this file.

$ cat ostechnix.txt
welcom
englsh
Tamil
Linux
securty

Now, let me check this file for any possible spelling errors.

$ cat ostechnix.txt | aspell list

Sample output:

welcom
englsh
securty

As you can see, Aspell lists the misspelled words from the given file. To use another language, use "-l" flag as shown below.

$ cat ostechnix.txt | aspell list -l es

To interactively check a file for possible spelling mistakes, we can use:

$ aspell check ostechnix.txt

Here is the output of the above command. Aspell suggests the possible replacements for the misspelled word. Just choose the correct words by entering the relevant number from the suggested words.

I type 1 (number one):

Once you selected the correct spelling, aspell will update the file with correct word and automatically move to another word and display the suggestions and so on.

If you think the spelling is correct for the selected words, type 'i' to ignore or type 'a' to add the word to the dictionary. This can be useful for Linux commands or any technical words which are not listed in the dictionaries.

You can also type 'r' to replace the selected word with your own spelling and press ENTER to update the changes.

To add the lower case for the selected word, type 'l'. Once you corrected all words, you will see nothing in the output.

Again, If you wanted to check spelling with different language, just use 'l' as I mentioned in the previous examples.


Recommended Read:


Manually adding dictionaries

Some dictionaries might not be available in your distribution's default repositories. For example, Tamil language dictionary is not available in Arch Linux default repositories. So, I had no choice but to compile and install it from source as described below.

Download the dictionary of your choice from here.

$ wget https://ftp.gnu.org/gnu/aspell/dict/ta/aspell6-ta-20040424-1.tar.bz2

Extract the downloaded archive:

$ tar xvf aspell6-ta-20040424-1.tar.bz2

Go to the directory aspell:

$ cd aspell6-ta-20040424-1/

Compile and install like below:

$ ./configure
$ make
$ sudo make install

Once you successfully installed the dictionary, you will see the newly installed dictionary:

$ aspell dicts
[...]
en_US
en_US-variant_0
en_US-variant_1
en_US-w_accents
en_US-wo_accents
es
ta

Here, ta is the language code for Tamil language.

Now, you can check the spelling with your new dictionary as shown below.

$ echo வணக்கம் | aspell -a -l ta

To install other dictionaries, just refer the README file of the downloaded Dictionary.

For more details, check the official website given below.

You May Also Like

1 comment

TheOuterLinux January 10, 2018 - 2:03 am

If you’re a nano user, the package you are looking for is “spell” if you want its spellchecker to work.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More