Package: cyhunspell
CyHunspellCython wrapper on Hunspell DictionaryDescriptionThis 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 theuse_disk_cacheargument to a Hunspell constructor. Otherwise it uses
in-memory caching.InstallingFor the simplest install simply run:pip install cyhunspellThis will install the hunspell 1.7.0 C++ bindings on your behalf for your platform.Dependenciescacheman -- for (optionally asynchronous) persistent cachingNon-Python DependencieshunspellThe library installshunspellversion 1.7.0. As new version of hunspell become
available this library will provide new versions to match.FeaturesSpell checking & spell suggestionsSeehttp://hunspell.github.io/How to useBelow are some simple examples for how to use the repository.Creating a Hunspell objectfromhunspellimportHunspellh=Hunspell()You now have a usable hunspell object that can make basic queries for you.h.spell('test')# TrueSpellingIt's a simple task to ask if a particular word is in the dictionary.h.spell('correct')# Trueh.spell('incorect')# FalseThis 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.SuggestionsIf 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 Matchh.suffix_suggest('do')# ('doing', 'doth', 'doer', 'doings', 'doers', 'doest')StemmingThe module can also stem words, providing the stems for pluralization and other
inflections.h.stem('testers')# ('tester', 'test')h.stem('saves')# ('save',)AnalyzeLike stemming but return morphological analysis of the input instead.h.analyze('permanently')# (' st:permanent fl:Y',)GenerateGenerate methods areNOTprovided 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 RequestsYou 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 requestsDictionariesYou can also specify the language or dictionary you wish to use.h=Hunspell('en_CA')# Canadian EnglishBy default you have the following dictionaries availableen_AUen_CAen_GBen_NZen_USen_ZAHowever you can download your own and point Hunspell to your custom dictionaries.h=Hunspell('en_GB-large',hunspell_data_dir='/custom/dicts/dir')Adding DictionariesYou can also add new dictionaries at runtime by calling the add_dic method.h.add_dic(os.path.join(PATH_TO,'special.dic'))Adding wordsYou 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 argumenth.add('silllies',"is:plural")Removing wordsMuch like adding, you can remove words.h.remove(word)Asynchronous CachingIf 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 PreferencesGoogle Style GuideObject Oriented (with a few exceptions)Known WorkaroundsOn 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 setsystem_encoding='UTF-8'in theHunspellconstructor or set the environment variableHUNSPELL_PATH_ENCODING=UTF-8. Then you must re-encode yourhunspell_data_dirin UTF-8 by passing that argument name to theHunspellconstructor or setting theHUNSPELL_DATAenvironment variable. This is a restriction of Hunspell / Windows operations.AuthorAuthor(s): Tim Rodriguez and Matthew SealLicenseMIT