SpellChecker
abosalim
mohammed.abosalim at gmail.com
Thu May 21 14:11:47 EDT 2009
On May 20, 12:37 pm, Mike Kazantsev <mike_kazant... at fraggod.net>
wrote:
> abosalim wrote:
> > I used this code.It works fine,but on word not whole text.I want to
> > extend this code to correct
> > text file not only a word,but i don't know.If you have any help,please
> > inform me.
> ...
> > def correct(word):
> > candidates = known([word]) or known(edits1(word)) or known_edits2
> > (word) or [word]
> > return max(candidates, key=lambda w: NWORDS[w])
>
> Here I assume that "word" is any string consisting of letters, feel free
> to add your own check in place of str.isalpha, like word length or case.
> Note that simple ops like concatenation work much faster with buffers
> than str / unicode.
>
> text = 'some text to correct (anything, really)'
> result = buffer('')
>
> word, c = buffer(''), ''
> for c in text:
> if c.isalpha(): word += c
> else:
> if word:
> result += correct(word)
> word = buffer('')
> result += c
>
> --
> Mike Kazantsev // fraggod.net
>
> signature.asc
> < 1KViewDownload
Thanks a lot
More information about the Python-list
mailing list