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

Attachment: signature.asc
Description: OpenPGP digital signature

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to