Adding Special Characters in Aspell Dictionary for PHP

Aspell is a spell check extension for PHP. If you are using aspell, you may require to add special characters for some words like good-morning. Although good and morning are correct words but ‘good-morning’ is shown as wrong because of  ‘-‘ character. Even if you add ‘good-morning’ in your custom dictionary, aspell will still show the spelling error because ‘-‘ is not a valid character. So we need to add special characters explicitly in aspell configuration.

Also see: Implementing Spell Check in PHP using Pspell

Here is how to do that:
Suppose your dictionary language is English (“en”) then find the en.dat file in aspell installation. en.dat is the language data file and each language has its own data file named as <lang>.dat. The data file should be present at following location:
/usr/lib64/aspell/en.dat
Now open this file for editing:

vi /usr/lib64/aspell/en.dat

At the end of this file add the following line:

special ' -*-

special is the keyword that tell aspell that following characters are to be treated as special characters. The format for adding special characters is:

<char> <begin><middle><end>

char is the non-letter character in question. begin, middle, end are either a ‘-‘ or a ‘*‘. A star for begin means that the character can begin a word, a ‘-‘ means it can’t. The same is true for middle and end.
For example

special - -*-
# good-morning is correct
# -good is incorrect
# good- is incorrect

special - *--
# good-morning is incorrect
# -good is correct
# good- is incorrect

special - --*
# good-morning is incorrect
# -good is incorrect
# good- is correct

special - ***
# good-morning is correct
# -good is correct
# good- is correct

To include more than one middle character just list them one after another on the same line. For example, to make both the ‘'‘ and the ‘-‘ a middle character, use the following line in the language data file:

special ' -*- - -*-

Written by Arvind Bhardwaj

Arvind is a Magento and WordPress expert with more than 6 years of industry wide experience.

Website: http://www.webspeaks.in/

One thought on “Adding Special Characters in Aspell Dictionary for PHP

Comments are closed.