Hunspy

API to work with Hunspell files.

Requirements

Hunspy only supports Python 3, it does not support Python 2.

Installation

Installing with pip:

pip install chakraversiontracker

Installing from sources:

python setup.py install

Installing from sources for development (if you plan to extend tracked packages):

python setup.py develop

Basic Usage

The munch() function can build a pair of Hunspell files from an iterable of words or multi-word expressions:

>>> from hunspy import munch
>>> with open('a.aff', 'w') as aff:
...     with open('a.dic', 'w') as dic:
...         munch(aff, dic, ('foo', 'bar'))
...
>>> print(open('a.aff').read())
SET UTF-8

>>> print(open('a.dic').read())
2
foo
bar

Documentation

The documentation is available online at ReadTheDocs.

You can also build it from sources:

  1. Install the requirements:

    python3 -m venv venv
    . venv/bin/activate
    pip install -r requirements.txt -r requirements-doc.txt
    
  2. Build the documentation:

    cd doc
    make html
    
  3. Open the documentation:

    xdg-open _build/html/index.html
    

API Reference

hunspy

hunspy.munch(aff, dic, expressions)

Builts into the specified dic and aff files a Hunspell spellchecker that supports only the specified expressions.

dic and aff must be file-like objects open for writing with their write cursor at their initial position.

expressions must be an iterable of words or multi-word expressions.

Note

Hunspell can only spellcheck on a word-per-word basis. Hence, the spelling of multi-word expressions is not really checked, what is checked is the spelling of each word that makes up the multi-word expression.

Words that are only allowed as part of a multi-word expression but not on their own will be accepted by the generated spellchecker. For example, if expressions yields 'foo bar', the resulting spellchecker will not only allow foo bar, it will also allow foo and bar.

You can not work around this limitation in any way. If you need the words of a multi-word expression to be allowed only when they appear together and in the correct order within a text, you need to use a grammar checker (e.g. LanguageTool) instead of a spellchecker like Hunspell.

Contributing

To work on Hunspy, install the packages in requirements-dev.txt:

python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt -r requirements-dev.txt

The source code is at hunspy. Hack away!

After you make any change that you plan to submit upstream, please run the automated tests:

./test.py

Tests will fail if your changes break existing tests or do not provide complete coverage.

Credits and License

Hunspy may be used under the terms of the GNU Affero General Public License version 3 or later (AGPLv3+).

For a list of authors who should be credited, see Authors.