Spell checking¶
spell ¶
Check Odia spelling against the offline dictionary.
A word is correct when its NFC form is a dictionary word or a bundled stopword.
Suggestions are other dictionary words within Damerau-Levenshtein distance 2
over aksharas (insertion, deletion, substitution, or transposition of two
adjacent aksharas, including a transposition combined with another edit),
closest akshara distance first. Words at the same akshara distance are ordered
by a score: the Damerau-Levenshtein distance over NFC code points minus 0.75
times the natural log of how often the word appears in the dictionary, lowest
first, then by code point. One letter of distance weighs the same as appearing
e**(4/3), about 3.8, times as often, so a word one letter further away ranks ahead
only when it appears more than 3.8 times as often. For ବୀଚ୍ଛେଦ, ବିଚ୍ଛେଦ
(one letter away, seen 11 times in the dictionary) ranks ahead of ଉଚ୍ଛେଦ
(two letters away, seen 15 times). A vowel sign such as ୈ or ୌ is one NFC
code point, so it counts as one letter: ଭାବୈଲା gives ଭାବିଲା first.
correct_text replaces
each unknown Odia word with its first suggestion and leaves whitespace, punctuation,
digits and non-Odia text as written. It does not join or split words. A word with
no candidate within distance 2 is left as written.
This module needs a release newer than 0.2.0: import openodia.spell fails on
0.2.0.
Examples:
>>> from openodia import spell
>>> spell.is_correct("ନମସ୍କାର")
True
>>> spell.is_correct("ନମସ୍କର")
False
>>> spell.suggest("ନମସ୍କର", top_k=1)
['ନମସ୍କାର']
>>> spell.correct_text("ସେ ଆମ ଘରକୁ ଆସୁଛନ୍ତ")
'ସେ ଆମ ଘରକୁ ଆସୁଛନ୍ତି'
is_correct ¶
is_correct(word: str) -> bool
Return whether word is in the dictionary after NFC normalization.
suggest ¶
suggest(word: str, top_k: int = 5) -> list[str]
Return up to top_k dictionary corrections, best first.
A dictionary word returns itself and nothing else. An empty word returns
[]. top_k must be an integer greater than or equal to 0.
correct_text ¶
correct_text(text: str) -> str
Replace each misspelled Odia word with its first suggestion.
Whitespace, punctuation, digits and non-Odia text are copied through. A known word keeps the characters it was written with.