grammar & spell check

Alex Martelli aleaxit at yahoo.com
Fri Dec 22 12:24:57 CET 2000


"Satheesh Babu" <vsbabu at erols.com> wrote in message
news:91u20g$pl3$1 at bob.news.rcn.net...
> Hi,
>
> Is there any suggestions on what services/software I can use
> to do grammar/spell check? for English language.
>
> requirements:
> 1. given a text string, it should do the checks and return
> errors/suggestions report
> 2. Should be able to interface from Python
> 3. Preferably should work from Win32 systems
>       (that gives an idea, can't I use  MS Word's functions for this?)

Of course, if you can count on Word being present on
your target machine; Python, with win32all (already
present in the ActiveState distribution), is an excellent
COM client.

For example, here's a spell-check program in Python:

import win32com.client

msword = win32com.client.Dispatch("Word.Application")

string = "Here is some texxt with a coupple of problems"

for word in string.split():
    if msword.CheckSpelling(word):
       print "!%s! OK!" % word
    else:
       print "?%s? ->"%word,
       suggestions = msword.GetSpellingSuggestions(word)
       for suggest in suggestions:
           print suggest.Name,
       print

D:\PySym>python spel.py
!Here! OK!
!is! OK!
!some! OK!
?texxt? -> text texts
!with! OK!
!a! OK!
?coupple? -> couple couplet coupler coupled couples
!of! OK!
!problems! OK!

D:\PySym>

You'll need Word's online docs for VBA to learn all the
details about spell-checking and grammar-checking.


For a cross-platform and free solution, I would expect
you could wring something similar out of StarOffice 5.2,
but unfortunately I wouldn't know where to start to
get cross-platform interfacing of Python with SO 5.2
(on Windows, specifically, they probably expose some
COM object model -- but that wouldn't help your programs
run under, say, Linux).  Has anybody managed to drive
StarOffice from Python cross-platformly, btw...?


Alex






More information about the Python-list mailing list