### Install pyspellchecker using pip Source: https://github.com/barrust/pyspellchecker/blob/master/README.rst Install the pyspellchecker library using pip. This is the recommended method for most users. ```bash pip install pyspellchecker ``` -------------------------------- ### Basic Spell Checking Usage Source: https://github.com/barrust/pyspellchecker/blob/master/README.rst Demonstrates how to initialize SpellChecker, find misspelled words in a list, and get correction suggestions. ```python from spellchecker import SpellChecker spell = SpellChecker() # find those words that may be misspelled misspelled = spell.unknown(['something', 'is', 'hapenning', 'here']) for word in misspelled: # Get the one `most likely` answer print(spell.correction(word)) # Get a list of `likely` options print(spell.candidates(word)) ``` -------------------------------- ### Install pyspellchecker with pipenv Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Use pipenv to install pyspellchecker, which combines pip and virtual environments for dependency management. ```bash pipenv install pyspellchecker ``` -------------------------------- ### PyInstaller Configuration (Windows) Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Example of how to use PyInstaller to include PySpellChecker dictionaries in your executable on Windows. Note the use of a semicolon instead of a colon for the binary path separator. ```bash pyinstaller --add-binary="spellchecker/resources/en.json.gz;spellchecker/resources" my_prog.py ``` -------------------------------- ### Install pyspellchecker for Python 2.7 Source: https://github.com/barrust/pyspellchecker/blob/master/README.rst Install a specific older release (v0.5.6) of pyspellchecker for Python 2.7 compatibility. Note that future updates do not support Python 2. ```bash pip install pyspellchecker==0.5.6 ``` -------------------------------- ### Initialize SpellChecker with a specific language Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Load a dictionary for a specific language during initialization by setting the 'language' parameter. For example, 'es' for Spanish. ```python from spellchecker import SpellChecker spell = SpellChecker(language='es') # Spanish dictionary print(spell['mañana']) ``` -------------------------------- ### PyInstaller Configuration (Linux/macOS) Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Example of how to use PyInstaller to include PySpellChecker dictionaries in your executable on Linux or macOS. The dictionaries are placed in the 'spellchecker/resources' folder within the executable. ```bash pyinstaller --add-binary="spellchecker/resources/en.json.gz:spellchecker/resources" my_prog.py ``` -------------------------------- ### Get candidate corrections for a misspelled word Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Retrieve a list of possible corrections for a misspelled word when the primary correction might not be accurate. This provides multiple suggestions. ```python from spellchecker import SpellChecker spell = SpellChecker() misspelled = spell.unknown(['morning', 'hapenning']) # {'hapenning'} for word in misspelled: spell.correction(word) # {'penning', 'happening', 'henning'} ``` -------------------------------- ### distance property Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Gets or sets the maximum edit distance for calculations. Valid values are 1 or 2. ```APIDOC ## distance ### Description The maximum edit distance to calculate. ### NOTE Valid values are 1 or 2; if an invalid value is passed, defaults to 2 ### Type int ``` -------------------------------- ### Get the correction for a misspelled word Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Find the most likely correction for a word identified as misspelled. This method returns a single best guess. ```python from spellchecker import SpellChecker spell = SpellChecker() misspelled = spell.unknown(['morning', 'hapenning']) # {'hapenning'} for word in misspelled: spell.correction(word) # 'happening' ``` -------------------------------- ### Load Custom Dictionary and Export Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Demonstrates loading a custom dictionary from a JSON file or text file and exporting it for later use. Ensure the dictionary file path is correct. ```python spell = SpellChecker(language=None, case_sensitive=True) # if you have a dictionary... spell.word_frequency.load_dictionary('./path-to-my-json-dictionary.json') # or... if you have text spell.word_frequency.load_text_file('./path-to-my-text-doc.txt') # export it out for later use! spell.export('my_custom_dictionary.gz', gzipped=True) ``` -------------------------------- ### Build pyspellchecker from source Source: https://github.com/barrust/pyspellchecker/blob/master/README.rst Clone the repository and build the package from source. This is useful for development or if you need the latest unreleased changes. ```bash git clone https://github.com/barrust/pyspellchecker.git cd pyspellchecker python -m build ``` -------------------------------- ### Using Non-English Dictionaries Source: https://github.com/barrust/pyspellchecker/blob/master/README.rst Demonstrates how to initialize SpellChecker with dictionaries for different languages like Spanish, Russian, and Arabic. ```python from spellchecker import SpellChecker english = SpellChecker() # the default is English (language='en') spanish = SpellChecker(language='es') # use the Spanish Dictionary russian = SpellChecker(language='ru') # use the Russian Dictionary arabic = SpellChecker(language='ar') # use the Arabic Dictionary ``` -------------------------------- ### Initialize SpellChecker Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Import and initialize the SpellChecker class to begin using its spell-checking functionalities. ```python from spellchecker import SpellChecker spell = SpellChecker() ``` -------------------------------- ### Build Command-Line Spell Checker Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Sets up an interactive command-line spell checker. Pressing Enter without input will exit the program. Input words are converted to lowercase. ```python from spellchecker import SpellChecker # could add command line arguments to set the parameters of the spell # check class; setup what type of information to present back, etc. spe ll = SpellChecker() print("To exit, hit return without input!") while True: word = input('Input a word to spell check: ') if word == '': # not sure, but need a way to kill the program... break word = word.lower() if word in spell: print("'{}' is spelled correctly!".format(word)) else: cor = spell.correction(word) print("The best spelling for '{}' is '{}'".format(word, cor)) print("If that is not enough; here are all possible candidate words:") print(spell.candidates(word)) ``` -------------------------------- ### load_dictionary Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Load a pre-built word frequency list from a file. ```APIDOC ## load_dictionary(filename: Path | str, encoding: str = 'utf-8') -> None Load in a pre-built word frequency list * **Parameters:** * **filename** (*str*) – The filepath to the json (optionally gzipped) file to be loaded * **encoding** (*str*) – The encoding of the dictionary ``` -------------------------------- ### load_json Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Load a pre-built word frequency list from a dictionary. ```APIDOC ## load_json(data: dict[str, int]) -> None Load in a pre-built word frequency list * **Parameters:** **data** (*dict*) – The dictionary to be loaded ``` -------------------------------- ### load_text_file Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Load a text file to generate a word frequency list. ```APIDOC ## load_text_file(filename: Path | str, encoding: str = 'utf-8', tokenizer: Callable[[str], Iterable[str]] | None = None) -> None Load in a text file from which to generate a word frequency list * **Parameters:** * **filename** (*str*) – The filepath to the text file to be loaded * **encoding** (*str*) – The encoding of the text file * **tokenizer** (*function*) – The function to use to tokenize a string ``` -------------------------------- ### SpellChecker Class Initialization Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Initializes a SpellChecker object with specified language, local dictionary, edit distance, tokenizer, and case sensitivity. ```APIDOC ## spellchecker.SpellChecker ### Description The SpellChecker class encapsulates the basics needed to accomplish a simple spell checking algorithm. ### Parameters * **language** (*str*) – The language of the dictionary to load or None for no dictionary. Supported languages are en, es, it, de, fr, pt, ru, lv, eu, nl and fa. Defaults to en. A list of languages may be provided and all languages will be loaded. * **local_dictionary** (*str*) – The path to a locally stored word frequency dictionary; if provided, no language will be loaded. * **distance** (*int*) – The edit distance to use. Defaults to 2. * **case_sensitive** (*bool*) – Flag to use a case sensitive dictionary or not, only available when not using a language dictionary. ### Raises **ValueError** – If the provided language dictionary does not exist, if case_sensitive is True with a language dictionary, or if both language and local_dictionary are specified. ``` -------------------------------- ### export(filepath: Path | str, encoding: str = 'utf-8', gzipped: bool = True) Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Exports the word frequency list to a specified file path for future import. ```APIDOC ## export ### Description Export the word frequency list for import in the future. ### Parameters * **filepath** (*str*) – The filepath to the exported dictionary * **encoding** (*str*) – The encoding of the resulting output * **gzipped** (*bool*) – Whether to gzip the dictionary or not ### Returns None ``` -------------------------------- ### Load dictionary from a JSON file Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Add terms to the spell checker's word frequency list by loading a pre-defined dictionary from a JSON or gzipped JSON file. ```python from spellchecker import SpellChecker spell = SpellChecker() spell.word_frequency.load_dictionary('./path-to-my-word-frequency.json') ``` -------------------------------- ### load_words Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Load a list of words to generate a word frequency list. ```APIDOC ## load_words(words: Iterable[str | bytes]) -> None Load a list of words from which to generate a word frequency list * **Parameters:** **words** (*list*) – The list of words to be loaded ``` -------------------------------- ### add Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Add a word to the word frequency list. ```APIDOC ## add(word: str | bytes, val: int = 1) -> None Add a word to the word frequency list * **Parameters:** * **word** (*str*) – The word to add * **val** (*int*) – The number of times to insert the word ``` -------------------------------- ### languages() Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Class method to retrieve a list of all official languages supported by the library. ```APIDOC ## languages ### Description list: A list of all official languages supported by the library. ### Returns An iterable of supported language strings. ``` -------------------------------- ### Customizing Word Frequency List Source: https://github.com/barrust/pyspellchecker/blob/master/README.rst Shows how to load custom text files or specific words to enhance the spell checker's word frequency list for better accuracy. ```python from spellchecker import SpellChecker spell = SpellChecker() # loads default word frequency list spell.word_frequency.load_text_file('./my_free_text_doc.txt') # if I just want to make sure some words are not flagged as misspelled spell.word_frequency.load_words(['microsoft', 'apple', 'google']) spell.known(['microsoft', 'google']) # will return both now! ``` -------------------------------- ### load_text Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Load text from which to generate a word frequency list. ```APIDOC ## load_text(text: str | bytes, tokenizer: Callable[[str], Iterable[str]] | None = None) -> None Load text from which to generate a word frequency list * **Parameters:** * **text** (*str*) – The text to be loaded * **tokenizer** (*function*) – The function to use to tokenize a string ``` -------------------------------- ### Load text from a file to update dictionary Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Parse words from a text file and add them to the spell checker's frequency list. This is useful for incorporating custom vocabulary. ```python from spellchecker import SpellChecker spell = SpellChecker() spell.word_frequency.load_text_file('./path-to-my-text-doc.txt') ``` -------------------------------- ### tokenize Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Tokenize a given string into individual words. ```APIDOC ## tokenize(text: str | bytes) -> Iterator[str] Tokenize the provided string object into individual words * **Parameters:** **text** (*str*) – The string object to tokenize * **Yields:** *str* – The next word in the tokenized string #### NOTE This is the same as the spellchecker.split_words() unless a tokenizer function was provided. ``` -------------------------------- ### keys Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Provides an iterator over the keys (words) in the dictionary. ```APIDOC ## keys() -> Iterator[str] Iterator over the key of the dictionary * **Yields:** *str* – The next key in the dictionary #### NOTE This is the same as spellchecker.words() ``` -------------------------------- ### WordFrequency Class Methods Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/index.md Methods for managing and accessing word frequency data. ```APIDOC ## WordFrequency.add() ### Description Adds a word to the frequency dictionary. ### Method `add(word)` ### Parameters - **word** (str) - The word to add. ### Response #### Success Response (None) - Adds the word without returning a value. ``` ```APIDOC ## WordFrequency.dictionary ### Description Attribute representing the internal dictionary of word frequencies. ### Method `dictionary` ### Response #### Success Response (dict) - Returns the dictionary mapping words to their frequencies. ``` ```APIDOC ## WordFrequency.items() ### Description Returns a view of the dictionary's items (word, frequency pairs). ### Method `items()` ### Response #### Success Response (dict_items) - Returns an iterable of (word, frequency) tuples. ``` ```APIDOC ## WordFrequency.keys() ### Description Returns a view of the dictionary's keys (words). ### Method `keys()` ### Response #### Success Response (dict_keys) - Returns an iterable of words. ``` ```APIDOC ## WordFrequency.letters ### Description Attribute representing the set of letters used in the dictionary. ### Method `letters` ### Response #### Success Response (set) - Returns a set of characters. ``` ```APIDOC ## WordFrequency.load_dictionary() ### Description Loads word frequencies from a dictionary file. ### Method `load_dictionary(path)` ### Parameters - **path** (str) - The path to the dictionary file. ### Response #### Success Response (None) - Loads the dictionary without returning a value. ``` ```APIDOC ## WordFrequency.load_json() ### Description Loads word frequencies from a JSON file. ### Method `load_json(path)` ### Parameters - **path** (str) - The path to the JSON file. ### Response #### Success Response (None) - Loads the frequencies without returning a value. ``` ```APIDOC ## WordFrequency.load_text() ### Description Loads word frequencies from a string of text. ### Method `load_text(text)` ### Parameters - **text** (str) - The text to load frequencies from. ### Response #### Success Response (None) - Loads frequencies without returning a value. ``` ```APIDOC ## WordFrequency.load_text_file() ### Description Loads word frequencies from a text file. ### Method `load_text_file(path)` ### Parameters - **path** (str) - The path to the text file. ### Response #### Success Response (None) - Loads frequencies without returning a value. ``` ```APIDOC ## WordFrequency.load_words() ### Description Loads word frequencies from an iterable of words. ### Method `load_words(words)` ### Parameters - **words** (iterable) - An iterable of words. ### Response #### Success Response (None) - Loads frequencies without returning a value. ``` ```APIDOC ## WordFrequency.longest_word_length ### Description Attribute representing the length of the longest word in the dictionary. ### Method `longest_word_length` ### Response #### Success Response (int) - Returns the length of the longest word. ``` ```APIDOC ## WordFrequency.pop() ### Description Removes and returns a word and its frequency from the dictionary. ### Method `pop(word)` ### Parameters - **word** (str) - The word to remove. ### Response #### Success Response (int) - Returns the frequency of the removed word. ``` ```APIDOC ## WordFrequency.remove() ### Description Removes a word from the frequency dictionary. ### Method `remove(word)` ### Parameters - **word** (str) - The word to remove. ### Response #### Success Response (None) - Removes the word without returning a value. ``` ```APIDOC ## WordFrequency.remove_by_threshold() ### Description Removes words with a frequency below a given threshold. ### Method `remove_by_threshold(threshold)` ### Parameters - **threshold** (int) - The minimum frequency for words to be kept. ### Response #### Success Response (None) - Removes words without returning a value. ``` ```APIDOC ## WordFrequency.remove_words() ### Description Removes multiple words from the frequency dictionary. ### Method `remove_words(words)` ### Parameters - **words** (iterable) - An iterable of words to remove. ### Response #### Success Response (None) - Removes words without returning a value. ``` ```APIDOC ## WordFrequency.tokenize() ### Description Tokenizes a text into words based on the dictionary's rules. ### Method `tokenize(text)` ### Parameters - **text** (str) - The text to tokenize. ### Response #### Success Response (list) - Returns a list of tokens (words). ``` ```APIDOC ## WordFrequency.total_words ### Description Attribute representing the total number of words in the dictionary. ### Method `total_words` ### Response #### Success Response (int) - Returns the total word count. ``` ```APIDOC ## WordFrequency.unique_words ### Description Attribute representing the number of unique words in the dictionary. ### Method `unique_words` ### Response #### Success Response (int) - Returns the count of unique words. ``` ```APIDOC ## WordFrequency.words() ### Description Returns a view of the dictionary's keys (words). ### Method `words()` ### Response #### Success Response (dict_keys) - Returns an iterable of words. ``` -------------------------------- ### candidates(word) Source: https://github.com/barrust/pyspellchecker/blob/master/README.rst Generates a set of possible candidate words that could be the intended word for a given input. ```APIDOC ## candidates(word) ### Description Returns a set of possible candidates for the misspelled word. ### Parameters #### Path Parameters - **word** (string) - Required - The word for which to find candidates. ``` -------------------------------- ### items Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Provides an iterator over the words in the dictionary along with their counts. ```APIDOC ## items() -> Generator[tuple[str, int], None, None] Iterator over the words in the dictionary * **Yields:** *str* – The next word in the dictionary int: The number of instances in the dictionary #### NOTE This is the same as dict.items() ``` -------------------------------- ### Load plain text to update dictionary Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Add words from a string of plain text to the spell checker's frequency list. The text will be parsed into individual words. ```python from spellchecker import SpellChecker spell = SpellChecker() spell.word_frequency.load_text('Text to be parsed and added to the system') ``` -------------------------------- ### word_probability(word) Source: https://github.com/barrust/pyspellchecker/blob/master/README.rst Calculates the probability of a given word based on its frequency in the dictionary. ```APIDOC ## word_probability(word) ### Description The frequency of the given word out of all words in the frequency list. ### Parameters #### Path Parameters - **word** (string) - Required - The word to get the probability for. ``` -------------------------------- ### pop Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Remove a key (word) from the dictionary and return its associated value, or a default if not found. ```APIDOC ## pop(key: str | bytes, default: int | None = None) -> int | None Remove the key and return the associated value or default if not found * **Parameters:** * **key** (*str*) – The key to remove * **default** (*obj*) – The value to return if key is not present * **Returns:** Returns the number of instances of key, or None if not in the dictionary * **Return type:** int | None ``` -------------------------------- ### split_words(text: str | bytes) Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Splits input text into individual words using a regex or a provided tokenizer. ```APIDOC ## split_words ### Description Split text into individual words using either a simple whitespace regex or the passed in tokenizer. ### Parameters * **text** (*str*) – The text to split into individual words ### Returns A listing of all words in the provided text ### Return type list(str) ``` -------------------------------- ### dictionary property Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md A counting dictionary of all words in the corpus and the number of times each has been seen. ```APIDOC ## *property* dictionary *: dict[str, int]* A counting dictionary of all words in the corpus and the number of times each has been seen #### NOTE Not settable * **Type:** Counter ``` -------------------------------- ### Adjusting Levenshtein Distance Source: https://github.com/barrust/pyspellchecker/blob/master/README.rst Illustrates how to set the Levenshtein distance for spell checking, reducing it to 1 for longer words or resetting it. ```python from spellchecker import SpellChecker spell = SpellChecker(distance=1) # set at initialization # do some work on longer words spell.distance = 2 # set the distance parameter back to the default ``` -------------------------------- ### words Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Provides an iterator over all the unique words stored in the dictionary. ```APIDOC ## words() -> Iterator[str] Iterator over the words in the dictionary * **Yields:** *str* – The next word in the dictionary #### NOTE This is the same as spellchecker.keys() ``` -------------------------------- ### Load words from a list to update dictionary Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Add multiple words to the spell checker's frequency list by providing a Python list of strings. ```python from spellchecker import SpellChecker spell = SpellChecker() spell.word_frequency.load_words(['Text', 'to', 'be','added', 'to', 'the', 'system']) ``` -------------------------------- ### Iterate over the dictionary Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Loop through all words in the spell checker's dictionary. Each iteration yields a word, and its frequency can be accessed via lookup. ```python from spellchecker import SpellChecker spell = SpellChecker() for word in spell: print("{}: {}".format(word, spell[word])) ``` -------------------------------- ### word_frequency property Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Provides access to the encapsulated word frequency dictionary. ```APIDOC ## word_frequency ### Description An encapsulation of the word frequency dictionary. ### NOTE Not settable ### Type [WordFrequency](#spellchecker.WordFrequency) ``` -------------------------------- ### candidates(word: str | bytes) Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Generates possible spelling corrections for a given word up to an edit distance of two. ```APIDOC ## candidates ### Description Generate possible spelling corrections for the provided word up to an edit distance of two, if and only if needed. ### Parameters * **word** (*str*) – The word for which to calculate candidate spellings ### Returns The set of words that are possible candidates or None if there are no candidates ### Return type set ``` -------------------------------- ### word_usage_frequency Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Calculate the frequency of a given word across the entire dictionary. ```APIDOC ## word_usage_frequency(word: str | bytes, total_words: int | None = None) -> float Calculate the frequency to the word provided as seen across the entire dictionary * **Parameters:** * **word** (*str*) – The word for which the word probability is calculated * **total_words** (*int*) – The total number of words to use in the calculation; use the default for using the whole word frequency * **Returns:** The probability that the word is the correct word * **Return type:** float ``` -------------------------------- ### total_words property Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md The sum of occurrences of all words in the word frequency dictionary. ```APIDOC ## *property* total_words *: int* The sum of all word occurrences in the word frequency dictionary #### NOTE Not settable * **Type:** int ``` -------------------------------- ### Find known and unknown words Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Identify words from a list that are present or absent in the spell checker's dictionary. ```python from spellchecker import SpellChecker spell = SpellChecker() # find those words from a list of words that are found in the dictionary spell.known(['morning', 'hapenning']) # {'morning'} # find those words from a list of words that are not found in the dictionary spell.unknown(['morning', 'hapenning']) # {'hapenning'} ``` -------------------------------- ### WordFrequency Class Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md The WordFrequency class stores the dictionary as a word frequency list, allowing for various methods to load data and update word counts. ```APIDOC ## class spellchecker.WordFrequency(tokenizer: Callable[[str], Iterable[str]] | None = None, case_sensitive: bool = False) Store the dictionary as a word frequency list while allowing for different methods to load the data and update over time ``` -------------------------------- ### edit_distance_1(word) Source: https://github.com/barrust/pyspellchecker/blob/master/README.rst Returns a set of all possible words that are one edit (Levenshtein distance) away from the input word, considering the language's alphabet. ```APIDOC ## edit_distance_1(word) ### Description Returns a set of all strings at a Levenshtein Distance of one based on the alphabet of the selected language. ### Parameters #### Path Parameters - **word** (string) - Required - The word to find edit distance 1 variations for. ``` -------------------------------- ### edit_distance_1(word: str | bytes) Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Computes all strings that are one edit away from the given word using letters from the corpus. ```APIDOC ## edit_distance_1 ### Description Compute all strings that are one edit away from word using only the letters in the corpus. ### Parameters * **word** (*str*) – The word for which to calculate the edit distance ### Returns The set of strings that are edit distance one from the provided word ### Return type set ``` -------------------------------- ### Add a single word to the dictionary Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Add an individual word to the spell checker's frequency list. This is useful for custom terms or corrections. ```python from spellchecker import SpellChecker spell = SpellChecker() spell.word_frequency.add('Text') ``` -------------------------------- ### edit_distance_2(word) Source: https://github.com/barrust/pyspellchecker/blob/master/README.rst Returns a set of all possible words that are two edits (Levenshtein distance) away from the input word, considering the language's alphabet. ```APIDOC ## edit_distance_2(word) ### Description Returns a set of all strings at a Levenshtein Distance of two based on the alphabet of the selected language. ### Parameters #### Path Parameters - **word** (string) - Required - The word to find edit distance 2 variations for. ``` -------------------------------- ### unknown(words: Iterable[str | bytes]) Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Identifies which words from an iterable are not present in the spellchecker's dictionary. ```APIDOC ## unknown ### Description The subset of words that do not appear in the dictionary. ### Parameters * **words** (*list*) – List of words to determine which are not in the corpus ### Returns The set of those words from the input that are not in the corpus ### Return type set ``` -------------------------------- ### remove Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Remove a specific word from the word frequency list. ```APIDOC ## remove(word: str | bytes) -> None Remove a word from the word frequency list * **Parameters:** **word** (*str*) – The word to remove ``` -------------------------------- ### edit_distance_2(word: str | bytes) Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Computes all strings that are two edits away from the given word using letters from the corpus. ```APIDOC ## edit_distance_2 ### Description Compute all strings that are two edits away from word using only the letters in the corpus. ### Parameters * **word** (*str*) – The word for which to calculate the edit distance ### Returns The set of strings that are edit distance two from the provided word ### Return type set ``` -------------------------------- ### remove_by_threshold Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Remove all words that appear at or below a specified frequency threshold. ```APIDOC ## remove_by_threshold(threshold: int = 5) -> None Remove all words at, or below, the provided threshold * **Parameters:** **threshold** (*int*) – The threshold at which a word is to be removed ``` -------------------------------- ### known(words: Iterable[str | bytes]) Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Identifies which words from an iterable are present in the spellchecker's dictionary. ```APIDOC ## known ### Description The subset of words that appear in the dictionary of words. ### Parameters * **words** (*list*) – List of words to determine which are in the corpus ### Returns The set of those words from the input that are in the corpus ### Return type set ``` -------------------------------- ### correction(word) Source: https://github.com/barrust/pyspellchecker/blob/master/README.rst Returns the most probable correction for a given misspelled word based on the dictionary's word frequency list. ```APIDOC ## correction(word) ### Description Returns the most probable result for the misspelled word. ### Parameters #### Path Parameters - **word** (string) - Required - The word to correct. ``` -------------------------------- ### SpellChecker Class Methods Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/index.md Methods available for the SpellChecker class to perform spell checking operations. ```APIDOC ## SpellChecker.candidates() ### Description Returns a set of suggested corrections for a given word. ### Method `candidates(word)` ### Parameters - **word** (str) - The word to find candidates for. ### Response #### Success Response (set) - Returns a set of strings representing possible corrections. ``` ```APIDOC ## SpellChecker.correction() ### Description Returns the most likely correction for a given word. ### Method `correction(word)` ### Parameters - **word** (str) - The word to correct. ### Response #### Success Response (str) - Returns the corrected word as a string. ``` ```APIDOC ## SpellChecker.distance ### Description Attribute representing the edit distance algorithm used. ### Method `distance` ### Response #### Success Response (callable) - Returns the distance function. ``` ```APIDOC ## SpellChecker.edit_distance_1() ### Description Generates all possible words with an edit distance of 1 from the given word. ### Method `edit_distance_1(word)` ### Parameters - **word** (str) - The word to generate variations for. ### Response #### Success Response (set) - Returns a set of strings with an edit distance of 1. ``` ```APIDOC ## SpellChecker.edit_distance_2() ### Description Generates all possible words with an edit distance of 2 from the given word. ### Method `edit_distance_2(word)` ### Parameters - **word** (str) - The word to generate variations for. ### Response #### Success Response (set) - Returns a set of strings with an edit distance of 2. ``` ```APIDOC ## SpellChecker.export() ### Description Exports the current word frequency dictionary to a JSON file. ### Method `export(path)` ### Parameters - **path** (str) - The path to the JSON file where the dictionary will be saved. ### Response #### Success Response (None) - Exports the dictionary without returning a value. ``` ```APIDOC ## SpellChecker.known() ### Description Returns a set of words from the input that are present in the dictionary. ### Method `known(words)` ### Parameters - **words** (iterable) - An iterable of words to check. ### Response #### Success Response (set) - Returns a set of known words. ``` ```APIDOC ## SpellChecker.languages() ### Description Returns a list of languages available in the spell checker. ### Method `languages()` ### Response #### Success Response (list) - Returns a list of strings, where each string is a language code. ``` ```APIDOC ## SpellChecker.split_words() ### Description Splits a text into a list of words. ### Method `split_words(text)` ### Parameters - **text** (str) - The text to split. ### Response #### Success Response (list) - Returns a list of words. ``` ```APIDOC ## SpellChecker.unknown() ### Description Returns a set of words from the input that are not present in the dictionary. ### Method `unknown(words)` ### Parameters - **words** (iterable) - An iterable of words to check. ### Response #### Success Response (set) - Returns a set of unknown words. ``` ```APIDOC ## SpellChecker.word_frequency ### Description Attribute representing the word frequency data structure. ### Method `word_frequency` ### Response #### Success Response (WordFrequency) - Returns an instance of the WordFrequency class. ``` ```APIDOC ## SpellChecker.word_usage_frequency() ### Description Returns the frequency of a given word. ### Method `word_usage_frequency(word)` ### Parameters - **word** (str) - The word to get the frequency for. ### Response #### Success Response (int) - Returns the frequency count of the word. ``` -------------------------------- ### correction(word: str | bytes) Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Returns the most probable correct spelling for a given word. ```APIDOC ## correction ### Description The most probable correct spelling for the word. ### Parameters * **word** (*str*) – The word to correct ### Returns The most likely candidate or None if no correction is present ### Return type str ``` -------------------------------- ### unknown([words]) Source: https://github.com/barrust/pyspellchecker/blob/master/README.rst Identifies words from a given list that are not found in the spellchecker's word frequency list. ```APIDOC ## unknown([words]) ### Description Returns those words that are not in the frequency list. ### Parameters #### Path Parameters - **words** (list of strings) - Optional - A list of words to check. ``` -------------------------------- ### known([words]) Source: https://github.com/barrust/pyspellchecker/blob/master/README.rst Checks which words from a given list are present in the spellchecker's word frequency list. ```APIDOC ## known([words]) ### Description Returns those words that are in the word frequency list. ### Parameters #### Path Parameters - **words** (list of strings) - Optional - A list of words to check. ``` -------------------------------- ### letters property Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md A set containing all unique letters found within the corpus. ```APIDOC ## *property* letters *: set[str]* The listing of all letters found within the corpus #### NOTE Not settable * **Type:** set ``` -------------------------------- ### Check if a word is known Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Determine if a word exists in the spell checker's dictionary using direct lookup or the 'in' operator. ```python from spellchecker import SpellChecker spell = SpellChecker() spell['morning'] # True 'morning' in spell # True ``` -------------------------------- ### Set Levenshtein distance for corrections Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Adjust the Levenshtein distance parameter to control the sensitivity of correction suggestions. Lower values are faster but may miss more distant corrections. The default is 2. ```python from spellchecker import SpellChecker spell = SpellChecker(distance=1) # set the Levenshtein Distance parameter # do additional work # now for shorter words, we can revert to Levenshtein Distance of 2! spell.distance = 2 ``` -------------------------------- ### unique_words property Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md The total count of distinct words present in the word frequency list. ```APIDOC ## *property* unique_words *: int* The total number of unique words in the word frequency list #### NOTE Not settable * **Type:** int ``` -------------------------------- ### remove_words Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md Remove a list of specified words from the word frequency list. ```APIDOC ## remove_words(words: Iterable[str | bytes]) -> None Remove a list of words from the word frequency list * **Parameters:** **words** (*list*) – The list of words to remove ``` -------------------------------- ### longest_word_length property Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/code.md The length of the longest word found in the dictionary. ```APIDOC ## *property* longest_word_length *: int* The longest word length in the dictionary #### NOTE Not settable * **Type:** int ``` -------------------------------- ### Remove words from the dictionary Source: https://github.com/barrust/pyspellchecker/blob/master/docs/source/quickstart.md Remove multiple words from the spell checker's frequency list using a list of strings, or remove a single word. ```python from spellchecker import SpellChecker spell = SpellChecker() spell.word_frequency.remove_words(['Text', 'to', 'be','removed', 'from', 'the', 'system']) # or remove a single word spell.word_frequency.remove('meh') ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.