pythainlp.spell

The pythainlp.spell finds the closest correctly spelled word to the given text.

Modules

pythainlp.spell.correct(word: str, engine: str = 'pn')str[source]
Parameters
  • word (str) – word to correct spelling

  • engine (str) –

    • pn - Peter Norvig’s algorithm (default)

Returns

the corrected word

pythainlp.spell.spell(word: str, engine: str = 'pn')List[str][source]
Parameters
  • word (str) – word to check spelling

  • engine (str) –

    • pn - Peter Norvig’s algorithm (default)

Returns

list of words

class pythainlp.spell.NorvigSpellChecker(custom_dict: Optional[List[Tuple[str, int]]] = None, min_freq: int = 2, min_len: int = 2, max_len: int = 40, dict_filter: Callable[[str], bool] = <function _is_thai_and_not_num>)[source]
correct(word: str)str[source]

Return the most possible word, using the probability from the spelling dictionary

Parameters

word (str) – A word to correct its spelling

dictionary()List[Tuple[str, int]][source]

Return the spelling dictionary currently used by this spell checker

freq(word: str)int[source]

Return frequency of an input word, according to the spelling dictionary

Parameters

word (str) – A word to check its frequency

known(words: List[str])List[str][source]

Return a list of given words that found in the spelling dictionary

Parameters

words (str) – A list of words to check if they are in the spelling dictionary

prob(word: str)float[source]

Return probability of an input word, according to the spelling dictionary

Parameters

word (str) – A word to check its probability of occurrence

spell(word: str)List[str][source]

Return a list of possible words, according to edit distance of 1 and 2, sorted by frequency of word occurrance in the spelling dictionary

Parameters

word (str) – A word to check its spelling

pythainlp.spell.DEFAULT_SPELL_CHECKER = Default instance of standard NorvigSpellChecker, using word list from Thai National Corpus