Home » , » How to use Spell checking in Python

How to use Spell checking in Python

1. using the popen2 module in python to call the commandlines
http://code.activestate.com/recipes/117221/

http://blog.quibb.org/2009/04/spell-checking-in-python/

Spell4Py is a Wrapper for Hunspell library. Org.keyphrene has been splited to several simple projects.
There is a tutorial for Hunspell here: http://blog.keyphrene.com/keyphrene/index.php/Tutorialorgkeyphrene

2. using a pure python program.

http://norvig.com/spell-correct.html
This page provides a very simple pure python spell checking program.
You can train it with a dictionary or a textual corpus off-the-shelf with
an accuracy around 70%.


3. Google API
http://developer.51cto.com/art/201103/252396.htm

http://stackoverflow.com/questions/8428767/how-to-implement-python-spell-checker-using-googles-did-you-mean


import httplibimport xml.dom.minidom

data = """
0" ignoredups="0" ignoredigits="1" ignoreallcaps="1">
 %s 

"""
def spellCheck(word_to_spell):

    con
= httplib.HTTPSConnection("www.google.com")
    con
.request("POST", "/tbproxy/spell?lang=en", data % word_to_spell)
    response
= con.getresponse()

    dom
= xml.dom.minidom.parseString(response.read())
    dom_data
= dom.getElementsByTagName('spellresult')[0]

   
if dom_data.childNodes:
       
for child_node in dom_data.childNodes:
            result
= child_node.firstChild.data.split()
       
for word in result:
           
if word_to_spell.upper() == word.upper():
               
return True;
       
return False;
   
else:
       
return True;

Popular Posts