| 1 |
# About Hunspell |
| 2 |
|
| 3 |
Hunspell is a free spell checker and morphological analyzer library |
| 4 |
and command-line tool, licensed under LGPL/GPL/MPL tri-license. |
| 5 |
|
| 6 |
Hunspell is used by LibreOffice office suite, free browsers, like |
| 7 |
Mozilla Firefox and Google Chrome, and other tools and OSes, like |
| 8 |
Linux distributions and macOS. It is also a command-line tool for |
| 9 |
Linux, Unix-like and other OSes. |
| 10 |
|
| 11 |
It is designed for quick and high quality spell checking and |
| 12 |
correcting for languages with word-level writing system, |
| 13 |
including languages with rich morphology, complex word compounding |
| 14 |
and character encoding. |
| 15 |
|
| 16 |
Hunspell interfaces: Ispell-like terminal interface using Curses |
| 17 |
library, Ispell pipe interface, C++/C APIs and shared library, also |
| 18 |
with existing language bindings for other programming languages. |
| 19 |
|
| 20 |
Hunspell's code base comes from OpenOffice.org's MySpell library, |
| 21 |
developed by Kevin Hendricks (originally a C++ reimplementation of |
| 22 |
spell checking and affixation of Geoff Kuenning's International |
| 23 |
Ispell from scratch, later extended with eg. n-gram suggestions), |
| 24 |
see http://lingucomponent.openoffice.org/MySpell-3.zip, and |
| 25 |
its README, CONTRIBUTORS and license.readme (here: license.myspell) files. |
| 26 |
|
| 27 |
Main features of Hunspell library, developed by László Németh: |
| 28 |
|
| 29 |
- Unicode support |
| 30 |
- Highly customizable suggestions: word-part replacement tables and |
| 31 |
stem-level phonetic and other alternative transcriptions to recognize |
| 32 |
and fix all typical misspellings, don't suggest offensive words etc. |
| 33 |
- Complex morphology: dictionary and affix homonyms; twofold affix |
| 34 |
stripping to handle inflectional and derivational morpheme groups for |
| 35 |
agglutinative languages, like Azeri, Basque, Estonian, Finnish, Hungarian, |
| 36 |
Turkish; 64 thousand affix classes with arbitrary number of affixes; |
| 37 |
conditional affixes, circumfixes, fogemorphemes, zero morphemes, |
| 38 |
virtual dictionary stems, forbidden words to avoid overgeneration etc. |
| 39 |
- Handling complex compounds (for example, for Finno-Ugric, German and |
| 40 |
Indo-Aryan languages): recognizing compounds made of arbitrary |
| 41 |
number of words, handle affixation within compounds etc. |
| 42 |
- Custom dictionaries with affixation |
| 43 |
- Stemming |
| 44 |
- Morphological analysis (in custom item and arrangement style) |
| 45 |
- Morphological generation |
| 46 |
- SPELLML XML API over plain spell() API function for easier integration |
| 47 |
of stemming, morpological generation and custom dictionaries with affixation |
| 48 |
- Language specific algorithms, like special casing of Azeri or Turkish |
| 49 |
dotted i and German sharp s, and special compound rules of Hungarian. |
| 50 |
|
| 51 |
Main features of Hunspell command line tool, developed by László Németh: |
| 52 |
|
| 53 |
- Reimplementation of quick interactive interface of Geoff Kuenning's Ispell |
| 54 |
- Parsing formats: text, OpenDocument, TeX/LaTeX, HTML/SGML/XML, nroff/troff |
| 55 |
- Custom dictionaries with optional affixation, specified by a model word |
| 56 |
- Multiple dictionary usage (for example hunspell -d en_US,de_DE,de_medical) |
| 57 |
- Various filtering options (bad or good words/lines) |
| 58 |
- Morphological analysis (option -m) |
| 59 |
- Stemming (option -s) |
| 60 |
|
| 61 |
See man hunspell, man 3 hunspell, man 5 hunspell for complete manual. |
| 62 |
|
| 63 |
Translations: Hunspell has been translated into several languages already. If your language is missing or incomplete, please use [Weblate](https://hosted.weblate.org/engage/hunspell/) to help translate Hunspell. |
| 64 |
|
| 65 |
<a href="https://hosted.weblate.org/engage/hunspell/"> |
| 66 |
<img src="https://hosted.weblate.org/widgets/hunspell/-/translations/horizontal-auto.svg" alt="Stanje prijevoda" /> |
| 67 |
</a> |
| 68 |
|
| 69 |
# Dependencies |
| 70 |
|
| 71 |
Build only dependencies: |
| 72 |
|
| 73 |
g++ make autoconf automake autopoint libtool |
| 74 |
|
| 75 |
Runtime dependencies: |
| 76 |
|
| 77 |
| | Mandatory | Optional | |
| 78 |
|---------------|------------------|------------------| |
| 79 |
|libhunspell | | | |
| 80 |
|hunspell tool | libiconv gettext | ncurses readline | |
| 81 |
|
| 82 |
# Compiling on GNU/Linux and Unixes |
| 83 |
|
| 84 |
We first need to download the dependencies. On Linux, `gettext` and |
| 85 |
`libiconv` are part of the standard library. On other Unixes we |
| 86 |
need to manually install them. |
| 87 |
|
| 88 |
For Ubuntu: |
| 89 |
|
| 90 |
sudo apt install autoconf automake autopoint libtool |
| 91 |
|
| 92 |
Then run the following commands: |
| 93 |
|
| 94 |
autoreconf -vfi |
| 95 |
./configure |
| 96 |
make |
| 97 |
sudo make install |
| 98 |
sudo ldconfig |
| 99 |
|
| 100 |
For a non-root install, use `DESTDIR` so libtool skips `ldconfig`: |
| 101 |
|
| 102 |
make install DESTDIR="$HOME/hunspell-root" |
| 103 |
|
| 104 |
For dictionary development, use the `--with-warnings` option of |
| 105 |
configure. |
| 106 |
|
| 107 |
For interactive user interface of Hunspell executable, use the |
| 108 |
`--with-ui` option. |
| 109 |
|
| 110 |
Optional developer packages: |
| 111 |
|
| 112 |
- ncurses (need for --with-ui), eg. libncursesw5 for UTF-8 |
| 113 |
- readline (for fancy input line editing, configure parameter: |
| 114 |
--with-readline) |
| 115 |
|
| 116 |
In Ubuntu, the packages are: |
| 117 |
|
| 118 |
libncurses5-dev libreadline-dev |
| 119 |
|
| 120 |
# Compiling on OSX and macOS |
| 121 |
|
| 122 |
On macOS for compiler always use `clang` and not `g++` because Homebrew |
| 123 |
dependencies are build with that. |
| 124 |
|
| 125 |
brew install autoconf automake libtool gettext |
| 126 |
brew link gettext --force |
| 127 |
|
| 128 |
Then run: |
| 129 |
|
| 130 |
autoreconf -vfi |
| 131 |
./configure |
| 132 |
make |
| 133 |
sudo make install |
| 134 |
|
| 135 |
# Compiling on Windows |
| 136 |
|
| 137 |
## Compiling with Mingw64 and MSYS2 |
| 138 |
|
| 139 |
Download Msys2, update everything and install the following |
| 140 |
packages: |
| 141 |
|
| 142 |
pacman -S base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-libtool \ |
| 143 |
mingw-w64-x86_64-libiconv mingw-w64-x86_64-gettext |
| 144 |
|
| 145 |
Open Mingw-w64 Win64 prompt and compile the same way as on Linux, see |
| 146 |
above. Without `mingw-w64-x86_64-libiconv` the build still succeeds but |
| 147 |
the `hunspell` tool cannot convert between dictionary encodings, so any |
| 148 |
test or dictionary that declares a non-UTF-8 `SET` (e.g. ISO8859-1/2/15) |
| 149 |
will fail at runtime. |
| 150 |
|
| 151 |
## Compiling in Cygwin environment |
| 152 |
|
| 153 |
Download and install Cygwin environment for Windows with the following |
| 154 |
extra packages: |
| 155 |
|
| 156 |
- make |
| 157 |
- automake |
| 158 |
- autoconf |
| 159 |
- libtool |
| 160 |
- gcc-g++ development package |
| 161 |
- ncurses, readline (for user interface) |
| 162 |
- iconv (character conversion) |
| 163 |
|
| 164 |
Then compile the same way as on Linux. Cygwin builds depend on |
| 165 |
Cygwin1.dll. |
| 166 |
|
| 167 |
# Debugging |
| 168 |
|
| 169 |
It is recommended to install a debug build of the standard library: |
| 170 |
|
| 171 |
libstdc++6-6-dbg |
| 172 |
|
| 173 |
For debugging we need to create a debug build and then we need to start |
| 174 |
`gdb`. |
| 175 |
|
| 176 |
./configure CXXFLAGS='-g -O0 -Wall -Wextra' |
| 177 |
make |
| 178 |
./libtool --mode=execute gdb src/tools/hunspell |
| 179 |
|
| 180 |
You can also pass the `CXXFLAGS` directly to `make` without calling |
| 181 |
`./configure`, but we don't recommend this way during long development |
| 182 |
sessions. |
| 183 |
|
| 184 |
If you like to develop and debug with an IDE, see documentation at |
| 185 |
https://github.com/hunspell/hunspell/wiki/IDE-Setup |
| 186 |
|
| 187 |
# Testing |
| 188 |
|
| 189 |
Testing Hunspell (see tests in tests/ subdirectory): |
| 190 |
|
| 191 |
make check |
| 192 |
|
| 193 |
or with Valgrind debugger: |
| 194 |
|
| 195 |
make check |
| 196 |
VALGRIND=[Valgrind_tool] make check |
| 197 |
|
| 198 |
For example: |
| 199 |
|
| 200 |
make check |
| 201 |
VALGRIND=memcheck make check |
| 202 |
|
| 203 |
# Documentation |
| 204 |
|
| 205 |
features and dictionary format: |
| 206 |
|
| 207 |
man 5 hunspell |
| 208 |
man hunspell |
| 209 |
hunspell -h |
| 210 |
|
| 211 |
http://hunspell.github.io/ |
| 212 |
|
| 213 |
# Usage |
| 214 |
|
| 215 |
After compiling and installing (see INSTALL) you can run the Hunspell |
| 216 |
spell checker (compiled with user interface) with a Hunspell or Myspell |
| 217 |
dictionary: |
| 218 |
|
| 219 |
hunspell -d en_US text.txt |
| 220 |
|
| 221 |
or without interface: |
| 222 |
|
| 223 |
hunspell |
| 224 |
hunspell -d en_GB -l <text.txt |
| 225 |
|
| 226 |
Dictionaries consist of an affix (.aff) and dictionary (.dic) file, for |
| 227 |
example, download American English dictionary files of LibreOffice |
| 228 |
(older version, but with stemming and morphological generation) with |
| 229 |
|
| 230 |
wget -O en_US.aff https://cgit.freedesktop.org/libreoffice/dictionaries/plain/en/en_US.aff?id=a4473e06b56bfe35187e302754f6baaa8d75e54f |
| 231 |
wget -O en_US.dic https://cgit.freedesktop.org/libreoffice/dictionaries/plain/en/en_US.dic?id=a4473e06b56bfe35187e302754f6baaa8d75e54f |
| 232 |
|
| 233 |
and with command line input and output, it's possible to check its work quickly, |
| 234 |
for example with the input words "example", "examples", "teached" and |
| 235 |
"verybaaaaaaaaaaaaaaaaaaaaaad": |
| 236 |
|
| 237 |
$ hunspell -d en_US |
| 238 |
Hunspell 1.7.0 |
| 239 |
example |
| 240 |
* |
| 241 |
|
| 242 |
examples |
| 243 |
+ example |
| 244 |
|
| 245 |
teached |
| 246 |
& teached 9 0: taught, teased, reached, teaches, teacher, leached, beached |
| 247 |
|
| 248 |
verybaaaaaaaaaaaaaaaaaaaaaad |
| 249 |
# verybaaaaaaaaaaaaaaaaaaaaaad 0 |
| 250 |
|
| 251 |
Where in the output, `*` and `+` mean correct (accepted) words (`*` = dictionary stem, |
| 252 |
`+` = affixed forms of the following dictionary stem), and |
| 253 |
`&` and `#` mean bad (rejected) words (`&` = with suggestions, `#` = without suggestions) |
| 254 |
(see man hunspell). |
| 255 |
|
| 256 |
Example for stemming: |
| 257 |
|
| 258 |
$ hunspell -d en_US -s |
| 259 |
mice |
| 260 |
mice mouse |
| 261 |
|
| 262 |
Example for morphological analysis (very limited with this English dictionary): |
| 263 |
|
| 264 |
$ hunspell -d en_US -m |
| 265 |
mice |
| 266 |
mice st:mouse ts:Ns |
| 267 |
|
| 268 |
cats |
| 269 |
cats st:cat ts:0 is:Ns |
| 270 |
cats st:cat ts:0 is:Vs |
| 271 |
|
| 272 |
# Other executables |
| 273 |
|
| 274 |
The src/tools directory contains the following executables after compiling. |
| 275 |
|
| 276 |
- The main executable: |
| 277 |
- hunspell: main program for spell checking and others (see |
| 278 |
manual) |
| 279 |
- Example tools: |
| 280 |
- analyze: example of spell checking, stemming and morphological |
| 281 |
analysis |
| 282 |
- chmorph: example of automatic morphological generation and |
| 283 |
conversion |
| 284 |
- example: example of spell checking and suggestion |
| 285 |
- Tools for dictionary development: |
| 286 |
- affixcompress: dictionary generation from large (millions of |
| 287 |
words) vocabularies |
| 288 |
- makealias: alias compression (Hunspell only, not back compatible |
| 289 |
with MySpell) |
| 290 |
- wordforms: word generation (Hunspell version of unmunch) |
| 291 |
- hunzip: decompressor of hzip format |
| 292 |
- hzip: compressor of hzip format |
| 293 |
- munch (DEPRECATED, use affixcompress): dictionary generation |
| 294 |
from vocabularies (it needs an affix file, too). |
| 295 |
- unmunch (DEPRECATED, use wordforms): list all recognized words |
| 296 |
of a MySpell dictionary |
| 297 |
|
| 298 |
Example for morphological generation: |
| 299 |
|
| 300 |
$ ~/hunspell/src/tools/analyze en_US.aff en_US.dic /dev/stdin |
| 301 |
cat mice |
| 302 |
generate(cat, mice) = cats |
| 303 |
mouse cats |
| 304 |
generate(mouse, cats) = mice |
| 305 |
generate(mouse, cats) = mouses |
| 306 |
|
| 307 |
Note: morphological generation, stemming and analysis only work with |
| 308 |
dictionaries whose entries carry morphological description fields |
| 309 |
(`po:`, `st:`, `is:`, `ts:`, `al:`, `ds:`, `dp:` etc.; see man hunspell.5). |
| 310 |
The example above relies on the older en_US dictionary linked earlier in |
| 311 |
this README, which still ships these fields. Most current distributions |
| 312 |
of en_US, fr, nl and hu_HU do not, and `analyze`, `stem` and `generate` |
| 313 |
will return empty results for them. This is a dictionary property, not |
| 314 |
a library bug. See `tests/morph.aff` and `tests/morph.dic` for a minimal |
| 315 |
example. |
| 316 |
|
| 317 |
# Using Hunspell library with GCC |
| 318 |
|
| 319 |
Including in your program: |
| 320 |
|
| 321 |
#include <hunspell.hxx> |
| 322 |
|
| 323 |
Linking with Hunspell static library: |
| 324 |
|
| 325 |
g++ -lhunspell-1.7 example.cxx |
| 326 |
# or better, use pkg-config |
| 327 |
g++ $(pkg-config --cflags --libs hunspell) example.cxx |
| 328 |
|
| 329 |
# Installing Hunspell (vcpkg) |
| 330 |
|
| 331 |
Alternatively, you can build and install hunspell using [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager: |
| 332 |
|
| 333 |
git clone https://github.com/Microsoft/vcpkg.git |
| 334 |
cd vcpkg |
| 335 |
./bootstrap-vcpkg.sh |
| 336 |
./vcpkg integrate install |
| 337 |
./vcpkg install hunspell |
| 338 |
|
| 339 |
The hunspell port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository. |
| 340 |
|
| 341 |
## Dictionaries |
| 342 |
|
| 343 |
Hunspell (MySpell) dictionaries: |
| 344 |
|
| 345 |
- https://wiki.documentfoundation.org/Language_support_of_LibreOffice |
| 346 |
- http://cgit.freedesktop.org/libreoffice/dictionaries |
| 347 |
- http://extensions.libreoffice.org |
| 348 |
- https://extensions.openoffice.org |
| 349 |
- https://wiki.openoffice.org/wiki/Dictionaries |
| 350 |
|
| 351 |
Aspell dictionaries (conversion: man 5 hunspell): |
| 352 |
|
| 353 |
- ftp://ftp.gnu.org/gnu/aspell/dict |
| 354 |
|
| 355 |
László Németh, nemeth at numbertext org |
| 356 |
|