The Pspell library contains two main classes and several helper classes. The two main classes are PspellConfig and PspellMaster. The PspellConfig class is used to set initial defaults and to change spell checker specific options. The PspellManager class does most of the real work. It is responsible for managing the dictionaries, checking if a word is in the dictionary, and coming up with suggestions among other things. There are many helper classes the important ones are PspellWordList, PspellMutableWordList, Pspell*Emulation. The PspellWordList classes is used for accessing the suggestion list, as well as the personal and suggestion word list currently in use. The PspellMutableWordList is used to manage the personal, and perhaps other, word lists. The Pspell*Emulation classes are used for iterating through a list.
A C and C++ Interface is provided. I recommend using the C interface, even if your program is in C++, to avoid some of the nasty issues associated with C++ linkage. In general one can only use C++ linkage if both the library and the program were created with the same compiler. I may eventually provide C++ wrapper classes, including a few STL like one, for the C library and remove the existing C++ interface all together.
The mapping between the C and C++ interface is pretty straightforward and from C++ to C goes as follows:
<class name in lowercase with underscores>_<method name>([const] <Class> *, <other parameters if any>)For example ``PspellManager::lang_name() const'' would become ``pspell_manager_lang_name(const PspellManager *)''.
Methods that return a bool will instead return an int in the C interface.
To use pspell your application should include ``pspell/pspell.h''. In order to insure that all the necessary libraries are linked in libtool should be used to perform the linking. When using libtool simply linking with ``-lpspell'' should be all that is necessary. When using shared libraries you might be able to simply link ``-lpspell'', but this is not recommended. This version of Pspell uses the CVS version of libtool (multi-language-branch) however released versions of libtool should also work.
When your application first starts you should get a new configuration class with the command:
When ever a new document is created a new PspellManager class should also be created. There should be one manager class per document. To create a new manager class use the new_pspell_manager and then cast it up using to_pspell_manager like so.
If for some reason you want to use different defaults simply clone spell_config and change the setting like so:
If the word is not correct than the suggest method can be used to come up with likely replacements.
Finally, when the document is closed the PspellManager class should be deleted like so.
Methods that return a bool generally return false on error and true other wise. To find out what went wrong use the error_number and error_message methods. Unless otherwise stated methods that return a const char * will return null on error. The charter string returned is only valid until the next method which returns a const char * is called.
All methods are virtual and abstract, thus these classes are really abstract base classes. Therefore you cannot simply store the object directly. In order to make copies of the objects use the clone and assign methods if they are provided.
For the details of the various classes please see the header files. In the future I will generate class references using some automated tool.
The following options are available to control which word list Pspell selects.
<string> options may be set to anything, including in some cases an empty string. <int> options must be set to a valid integer string. <boolean> options must be set to ``true'' or ``false''. <list> options can not be set directly, you must use the option add-<option> to add an item to the list, rem-<option> to remove an item, or rem-all-<option> to remove all the items. In the case of rem-all-<option> the value should be an empty string. Although the standard retrieve method will work for a string, it should not be used as the format of the string is implementation dependent. Use the retrieve_list method instead.
In order for Pspell to know which word lists to use each word list must have at least one PWLI file in the pspell data directory which is normally /usr/local/share/pspell/, use ``pspell-config pkgdatadir'' to find out what it is on your system.
Each PWLI has the the following name:
<language>[-[<spelling>][-<jargon>]]-<module>.pwliWhere <language> is the two letter language code, <spelling> is the particular spelling your interested in if the languages has multiple spelling in different parts of the world such as English, <jargon> is any extra informations to distinguish the word list from other ones with the same language and spelling, and <module> is the pspell module the main word list is for.
en-aspell.pwliNotice how if the spelling is left out but the jargon is not there needs to be two dashes between the language and the jargon.
Each PWLI file then contains exactly one line which contains the full path of the main word list, white space, then any additional options to pass onto the module.
Two simple examples are included in the examples directory. Pspell must be installed before they will compile and at least one pspell module must be installed before they will run. To build the C example type ``make example-c'' and to build the C++ examples type ``make example-cxx''.
This method is needed because Aspell (http://aspell.sourceforge.net/) is able to learn from users misspellings. For example on the first pass a user misspells beginning as beging so aspell suggests:
begging, begin, being, Beijing, bagging, ....However the user then tries "begning" and aspell suggests
beginning, beaning, begging, ...so the user selects beginning. However than, latter on in the document the user misspelles it as begng (NOT beging). Normally aspell will suggest.
began, begging, begin, begun, ....However becuase it knows the user mispelled beginning as beging it will instead suggest:
beginning, began, begging, begin, begun ...I myself often misspelled beginning (and still do) as something close to begging and two many times wind up writing sentences such as "begging with ....".