What is spell checking?
In computing, a spell checker (or spell check) is an application program that flags words in a document that may not be spelled correctly. Spell checkers may be stand-alone, capable of operating on a block of text, or as part of a larger application, such as a word processor, email client, electronic dictionary, or search engine.
1. using the popen2 module in python to call the commandlines
Spell4Py is a Wrapper for Hunspell library. Org.keyphrene has been
splited to several simple projects.
There is a tutorial for Hunspell here:
2. using a pure python program.
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%.
I also deploy an application online, click here as an example. You can also try other words for testing.
3. Google API
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;
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;
Post a Comment