Skip to main content

Spell checkers builder using hunspell.

Project description

hunspellcheck

PyPI Python versions License Tests

This library is a helper for writing spell checkers using hunspell.

If you want to standarize the execution and writing of several spell checkers for different file types, performing the spell checking against ortographic dictionaries, this library is for you. It will allow you to reuse some patterns repeated using hunspell for spell checking.

Features

  • Graceful handling of missing dictionaries.
  • Custom dictionaries by filepath.
  • Personal dictionaries by filepath.
  • Argument parsers building.
  • Well tested system calls to hunspell.

Install

pip install hunspellcheck

Example

Let's write a .txt files spellchecker. It's really easy:

CLI interface

"""__main__.py"""

import argparse
import sys

from hunspellcheck import (
    extend_argument_parser,
    render_error,
    SpellChecker,
)


def build_parser():
    parser = argparse.ArgumentParser(description="TXT files spellchecker.")
    extend_argument_parser(
        parser,
        version=True,
        version_number="1.0.0",
    )
    return parser


def main():
    opts = build_parser().parse_args()
    
    # Is your mission to extract the contents of the files.
    # By default are passed as globs in positional arguments and stored in
    # the 'files' property of the namespace
    filenames_contents = {}
    for filename in opts.files:
        with open(filename, "r") as f:
            filenames_contents[filename] = f.read()
    
    spellchecker = SpellChecker(
        filenames_contents=filenames_contents,
        languages=opts.languages,
        personal_dict=opts.personal_dict,
    )
    for error in spellchecker.check():
        print(render_error(error), file=sys.stderr)

    return 0 if not spellchecker.errors else 1


if __name__ == "__main__":
    sys.exit(main())

You can see the usage passing --help to this script:

$ python3 __main__.py --help
usage: __main__.py [-h] [--version] -l LANGUAGE [-p PERSONAL_DICTIONARY] [FILES [FILES ...]]

positional arguments:
  FILES                 Files and/or globs to check.

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -l LANGUAGE, --languages LANGUAGE
                        Language to check, you'll have to install the corresponding hunspell dictionary.
  -p PERSONAL_DICTIONARY, --personal-dict PERSONAL_DICTIONARY
                        Additional dictionary to extend the words to exclude.

To use it, just create a .txt file and pass its filename as positional argument, selecting the language with --language option:

Texto en español y word
$ python3 __main__.py --language es_ES foo.txt
foo.txt:word:1:19

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hunspellcheck-0.0.1.linux-x86_64.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

hunspellcheck-0.0.1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file hunspellcheck-0.0.1.linux-x86_64.tar.gz.

File metadata

  • Download URL: hunspellcheck-0.0.1.linux-x86_64.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for hunspellcheck-0.0.1.linux-x86_64.tar.gz
Algorithm Hash digest
SHA256 7f3d5b6f0b0fa7dc77c6de4dde7f593302e9b3788000eeb2bbca90fcd782722e
MD5 ab941fac7f44f95d232ddc4eab31a7ae
BLAKE2b-256 5239a48de38d3c14036fe80acf6709deb208e12404e82c03a464509cedef1018

See more details on using hashes here.

File details

Details for the file hunspellcheck-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: hunspellcheck-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for hunspellcheck-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b64322454c8123668b79b9d70135362dfd82c9f295b1fb6d06c30c810b441379
MD5 2896b6614fb0bee9347b5fa58d347d74
BLAKE2b-256 4f3075087e39f3713cdee6a5496e6ad13566f17f2380916675808b7e997a811b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page