pythainlp.spell¶
The pythainlp.spell
finds the closest correctly spelled word to the given text.
-
pythainlp.spell.
spell
(word: str, engine: str = 'pn') → List[str][source]¶ Provides a list of possible correct spelling of the given word. The list of words are from the words in the dictionary that incurs an edit distance value of 1 or 2. The result is a list of words sorted by their occurrences in the spelling dictionary in descending order.
- Parameters
word (str) – Word to spell check
engine (str) –
pn - Peter Norvig’s algorithm [#norvig_spellchecker]_ (default)
- Returns
list of possible correct words within 1 or 2 edit distance and sorted by frequency of word occurrences in the spelling dictionary in descending order.
- Return type
- Example
from pythainlp.spell import spell spell("เส้นตรบ", engine="pn") # output: ['เส้นตรง'] spell("เส้นตรบ") # output: ['เส้นตรง'] spell("ครัช") # output: ['ครับ', 'ครัว', 'รัช', 'ครัม', 'ครัน', 'วรัช', 'ครัส', # 'ปรัช', 'บรัช', 'ครัง', 'คัช', 'คลัช', 'ครัย', 'ครัด'] spell("กระปิ") # output: ['กะปิ', 'กระบิ'] spell("สังเกตุ") # output: ['สังเกต'] spell("เหตการณ") # output: ['เหตุการณ์']