A wrapper on hunspell for use in Python
Project description
CyHunspell
Cython wrapper on Hunspell Dictionary
Description
This repository provides a wrapper on Hunspell to be used natively in Python. The module uses cython to link between the C++ and Python code, with some additional features. There's very little Python overhead as all the heavy lifting is done on the C++ side of the module interface, which gives optimal performance.
The hunspell library will cache any corrections, you can use persistent caching by
adding the use_disk_cache
argument to a Hunspell constructor. Otherwise it uses
in-memory caching.
Installing
For the simplest install simply run:
pip install cyhunspell
This will install the hunspell 1.7.0 C++ bindings on your behalf for your platform.
Dependencies
cacheman -- for (optionally asynchronous) persistent caching
Non-Python Dependencies
hunspell
The library installs hunspell version 1.7.0. As new version of hunspell become available this library will provide new versions to match.
Features
Spell checking & spell suggestions
How to use
Below are some simple examples for how to use the repository.
Creating a Hunspell object
from hunspell import Hunspell
h = Hunspell()
You now have a usable hunspell object that can make basic queries for you.
h.spell('test') # True
Spelling
It's a simple task to ask if a particular word is in the dictionary.
h.spell('correct') # True
h.spell('incorect') # False
This will only ever return True or False, and won't give suggestions about why it might be wrong. It also depends on your choice of dictionary.
Suggestions
If you want to get a suggestion from Hunspell, it can provide a corrected label given a basestring input.
h.suggest('incorect') # ('incorrect', 'correction', corrector', 'correct', 'injector')
The suggestions are in sorted order, where the lower the index the closer to the input string.
Suffix Match
h.suffix_suggest('do') # ('doing', 'doth', 'doer', 'doings', 'doers', 'doest')
Stemming
The module can also stem words, providing the stems for pluralization and other inflections.
h.stem('testers') # ('tester', 'test')
h.stem('saves') # ('save',)
Analyze
Like stemming but return morphological analysis of the input instead.
h.analyze('permanently') # (' st:permanent fl:Y',)
Generate
Generate methods are NOT provided at this time due to the 1.7.0 build not producing any results for any inputs, included the documented one. If this is fixed or someone identifies the issue in the call pattern this will be added to the library in the future.
Bulk Requests
You can also request bulk actions against Hunspell. This will trigger a threaded (without a gil) request to perform the action requested. Currently just 'suggest' and 'stem' are bulk requestable.
h.bulk_suggest(['correct', 'incorect'])
# {'incorect': ('incorrect', 'correction', 'corrector', 'correct', 'injector'), 'correct': ('correct',)}
h.bulk_suffix_suggest(['cat', 'do'])
# {'do': ('doing', 'doth', 'doer', 'doings', 'doers', 'doest'), 'cat': ('cater', 'cats', "cat's", 'caters')}
h.bulk_stem(['stems', 'currencies'])
# {'currencies': ('currency',), 'stems': ('stem',)}
h.bulk_analyze(['dog', 'permanently'])
# {'permanently': (' st:permanent fl:Y',), 'dog': (' st:dog',)}
By default it spawns number of CPUs threads to perform the operation. You can overwrite the concurrency as well.
h.set_concurrency(4) # Four threads will now be used for bulk requests
Dictionaries
You can also specify the language or dictionary you wish to use.
h = Hunspell('en_CA') # Canadian English
By default you have the following dictionaries available
- en_AU
- en_CA
- en_GB
- en_NZ
- en_US
- en_ZA
However you can download your own and point Hunspell to your custom dictionaries.
h = Hunspell('en_GB-large', hunspell_data_dir='/custom/dicts/dir')
Adding Dictionaries
You can also add new dictionaries at runtime by calling the add_dic method.
h.add_dic(os.path.join(PATH_TO, 'special.dic'))
Adding words
You can add individual words to a dictionary at runtime.
h.add('sillly')
Furthermore you can attach an affix to the word when doing this by providing a second argument
h.add('silllies', "is:plural")
Removing words
Much like adding, you can remove words.
h.remove(word)
Asynchronous Caching
If you want to have Hunspell cache suggestions and stems you can pass it a directory to house such caches.
h = Hunspell(disk_cache_dir='/tmp/hunspell/cache/dir')
This will save all suggestion and stem requests periodically and in the background. The cache will fork after a number of new requests over particular time ranges and save the cache contents while the rest of the program continues onward. Yo'll never have to explicitly save your caches to disk, but you can if you so choose.
h.save_cache()
Otherwise the Hunspell object will cache such requests locally in memory and not persist that memory.
Language Preferences
- Google Style Guide
- Object Oriented (with a few exceptions)
Known Workarounds
- On Windows very long file paths, or paths saved in a different encoding than the system require special handling by Hunspell to load dictionary files. To circumvent this on Windows setups, either set
system_encoding='UTF-8'
in theHunspell
constructor or set the environment variableHUNSPELL_PATH_ENCODING=UTF-8
. Then you must re-encode yourhunspell_data_dir
in UTF-8 by passing that argument name to theHunspell
constructor or setting theHUNSPELL_DATA
environment variable. This is a restriction of Hunspell / Windows operations.
Author
Author(s): Tim Rodriguez and Matthew Seal
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file cyhunspell-2.0.2-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d517d1d4cc0717e94507ae47066ba05034904de2e82a62b007d131d4a8c3a7a6 |
|
MD5 | 8730009fc189154ce521b403ebb62920 |
|
BLAKE2b-256 | 3b05cdbea1ab1543dbec2a0ef1c95a6208376172a133d5d752586ccc8e7d4583 |
File details
Details for the file cyhunspell-2.0.2-cp39-cp39-win32.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp39-cp39-win32.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.9, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb2e1e2512dedb48ccb676751d06275bac2a462491bbd8a4826ad726d8bae81e |
|
MD5 | 6cd4a3c97bb8144dc8ace65b07bc8f8d |
|
BLAKE2b-256 | 431ec39e83c4611672afc5f6527ba20838e04c76ade81944eeeba5d8adbc6aae |
File details
Details for the file cyhunspell-2.0.2-cp39-cp39-manylinux2010_x86_64.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp39-cp39-manylinux2010_x86_64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a52e2d49fd51bc0b97db11e95db53e4ae18719998cdb9cd805a0af04de10eab |
|
MD5 | d371c2e9c8024bbf4fa9b1679149415a |
|
BLAKE2b-256 | dd97ad70918a0668e6222ad69a24f6bd65d015018632bed043df11783f8ace84 |
File details
Details for the file cyhunspell-2.0.2-cp39-cp39-manylinux2010_i686.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp39-cp39-manylinux2010_i686.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.9, manylinux: glibc 2.12+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 656162d66921991edd3a4116ffbf75ea3cf9571e070a489a593520051f7a66dc |
|
MD5 | d4621abb3afd9eb550a74a5ce935fefd |
|
BLAKE2b-256 | 8a9fac3f82bc7f3e2601f87b0ec306043c66404e9b2ceba549d2ee1fa975d129 |
File details
Details for the file cyhunspell-2.0.2-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1+
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcc4cce42b40c58ad21ce5566421980e927207efaa8f683ab2ab68b6def35435 |
|
MD5 | ee63a120685768bf6253b6377733e2b1 |
|
BLAKE2b-256 | 5a4e54074722e1accbef651495a204d9e3c103ce776f4f99aeb6ad3ef371f4c8 |
File details
Details for the file cyhunspell-2.0.2-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c7390a072eb7c8674a244f99915606f6fe3485fa5fe71bd590f49b92aefe460 |
|
MD5 | ae3ad08649339760e31252125723008c |
|
BLAKE2b-256 | 2bc2efcbce709fdb7ed215949e9099824e098a61b15e8f9b31ecd1fee72802c6 |
File details
Details for the file cyhunspell-2.0.2-cp38-cp38-win32.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp38-cp38-win32.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.8, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e7862cbf170aff8010ebd5ed3e179712a3ab2ea41ba08da5377570a6b693368 |
|
MD5 | b5e390b7a26c04e6ef9b709174d0c5d1 |
|
BLAKE2b-256 | d12fb3471bfb0a50c60cbd46e853806dfecd312f5068c343b6484da2359ff83d |
File details
Details for the file cyhunspell-2.0.2-cp38-cp38-manylinux2010_x86_64.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp38-cp38-manylinux2010_x86_64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 858226b7c159b398a9a0bcdfa17f8808cb74ed7871b7eff05d1823779dee46c2 |
|
MD5 | 087d0b072ceb88dd6185f6c502354ecb |
|
BLAKE2b-256 | dd3622f3a5452c77f8f8e00ca19cda54700fc80292dae9274c784c36f33873f1 |
File details
Details for the file cyhunspell-2.0.2-cp38-cp38-manylinux2010_i686.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp38-cp38-manylinux2010_i686.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.8, manylinux: glibc 2.12+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04039a880e96cd0c9d8db7dfd21be40bf767560cd35f2bbfb82a3e5c6799c8ae |
|
MD5 | 194019aeda816019dd6e0f16c6cc848c |
|
BLAKE2b-256 | 433873106318fe3d7e5c662018aa4a5b521dc8cfcb3d85a29f6da02b5fe7d744 |
File details
Details for the file cyhunspell-2.0.2-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.8rc1+
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecabf5c71d7b9e727d306e053b908647c7afae5ee88ec1101b5cb34d99208e93 |
|
MD5 | 86325b5c30f34a244ae9ad2d04fab7bf |
|
BLAKE2b-256 | 1dc585bf8c059f6efcf7eb314fcf345ac25c7d280ebf4def912706e785b12b02 |
File details
Details for the file cyhunspell-2.0.2-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 892ae561ce3a6b15751536bef95ca6e70fd0a81732e810c460f126b0d6161a8d |
|
MD5 | 8390bb41564f87be4d27c9749b4ac051 |
|
BLAKE2b-256 | d48ba62b720dbc6b463231841fe80e390b6e6f8b3a44ec861eeb3d1a954f70f5 |
File details
Details for the file cyhunspell-2.0.2-cp37-cp37m-win32.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp37-cp37m-win32.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.7m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7489c28db35b288635cc67984a149f1f223401fca287b02c38e56aa9818abe25 |
|
MD5 | de85f820b3c53da82ff59bc7a59696c4 |
|
BLAKE2b-256 | a03d6004f0da6dd3b7c97a596f53be76564d36738b1f70dd754c8c30096baf0f |
File details
Details for the file cyhunspell-2.0.2-cp37-cp37m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp37-cp37m-manylinux2010_x86_64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ad13ed8392526fa136007e4f829fc73fa1f7d275b1a9db19832d38b6f3e5aa4 |
|
MD5 | 9c23802bfe9662bee48c599928156d80 |
|
BLAKE2b-256 | eb9a6bbbebb202ca9de90efb66b2470fe4b81d47ca5c6bd6494077f960d664ce |
File details
Details for the file cyhunspell-2.0.2-cp37-cp37m-manylinux2010_i686.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp37-cp37m-manylinux2010_i686.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.7m, manylinux: glibc 2.12+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1be7eac0e88949ad877f6855c7a7c004424e2d19537c3874a540930247a6d537 |
|
MD5 | 32c1d3748bdb26c150362a05c576c76e |
|
BLAKE2b-256 | 60d24854d5886fd44fd89ed1bdf2e6354e7efa0299c78074d03d9e8311e94d23 |
File details
Details for the file cyhunspell-2.0.2-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.7.10+
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c197a9075ec14c049c87a8bdcee258456141a2468f17fb94abbff440073b0b3 |
|
MD5 | 7bef8cd5522f5b67e46be87d795d5bb4 |
|
BLAKE2b-256 | 3d98c4f6e3a78e76901e46a9abf63dc3fe3687ba19471136aa7adfdbd301c314 |
File details
Details for the file cyhunspell-2.0.2-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07221f024d2f74900bf976709f7db6926e0a2d362dc5d6ffc5d9ab7a5e7f5fcf |
|
MD5 | 2edc8d84dad7a4505ffabf0ee4eb621a |
|
BLAKE2b-256 | 743aca5c14a4d2226428d6b196108fff2fde5c4fdfa622c4db71475c84ded605 |
File details
Details for the file cyhunspell-2.0.2-cp36-cp36m-win32.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp36-cp36m-win32.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee44db091e7446f5619bf6b011601c78dccc6bc1d1997f86b4618ee845949c05 |
|
MD5 | bded30541e1a2efbfef0e65fa701b6c1 |
|
BLAKE2b-256 | c74e03aa0baecc4f5929ca7e90a9f4bf095fc36f18c13e08a2916e04967c53c3 |
File details
Details for the file cyhunspell-2.0.2-cp36-cp36m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp36-cp36m-manylinux2010_x86_64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9ed4a1acdd97404f6bc0cc7820ab3fe1d506f88e2b0ea2b86b2dc6d99d4e280 |
|
MD5 | e7505ba1cd50ac650afb021f94654c92 |
|
BLAKE2b-256 | 6e4ef6fd66d5a3677482377c1b073578b64201c8b44762af4e90108cf2acb49b |
File details
Details for the file cyhunspell-2.0.2-cp36-cp36m-manylinux2010_i686.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp36-cp36m-manylinux2010_i686.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.6m, manylinux: glibc 2.12+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c64b889c3a07b82efe85da889e3c0d643c3f89ec26ba0f11ab76a479cdab215 |
|
MD5 | 00c946c904e5e080155eda5d2b21e46c |
|
BLAKE2b-256 | 988e1af2d0c2d1ce9990c8529153d801b36739b7bec77c53fb7a12ec7a6a755c |
File details
Details for the file cyhunspell-2.0.2-cp36-cp36m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: cyhunspell-2.0.2-cp36-cp36m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.6m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.6.13+
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec1a4a648104b3ebf3c36f8bb0f3d17d97607df8f49bdfb987d532c5cfb79712 |
|
MD5 | b0e4c1787b93f32792059a832cb37ada |
|
BLAKE2b-256 | 144823a0638335ee6cd09ccfc2d187644c7b3d24987f327d48f7e1e095d5fee9 |