Skip to content
WJunction - Webmaster Forum

[Python] Simple Spellcheck Program

Status
Not open for further replies.
This is a simple application that I had to make during the exam today. Basically what it does is do a spell check for 2 or more words. This is done by using Google (the more results your word has, the correcter it is)

Before you can work with the app below you have to download the xgoogle module, which can be found here.

Simply extract it, and put your python file (that we are going to make in a bit), in the same place as the location of your xgoogle folder. So do not place it inside the xgoogle folder.

Here is the code of the spellchecker.py file:
Code:
#!/usr/bin/python
from xgoogle.search import GoogleSearch, SearchError
import sys
highest = -1
winner = ""
filename = sys.argv[0]
if sys.argv != "" and len(sys.argv) > 1:
    for word in sys.argv:
        if word != filename:
            try:
                gs = GoogleSearch(word)
                gs.results_per_page = 50
                results = gs.get_results()
                amount = gs.num_results
                print "Results for " + word + ": " + str(amount)
                if(highest <= amount):
                    highest = amount
                    winner = word
            except SearchError, e:
                print "Search failed: %s" % e
else:
    input = raw_input('Enter your spellcheck words seperated by a comma:\n')
    words = input.split(",")
    for word in words:
        try:
            gs = GoogleSearch(word)
            gs.results_per_page = 50
            results = gs.get_results()
            amount = gs.num_results
            print "Results for " + word + ": " + str(amount)
            if(highest <= amount):
                highest = amount
                winner = word
        except SearchError, e:
            print "Search failed: %s" % e        
print "And the most likely correct word is: " + winner
You have 2 options of running this.
1) run ./spellchecker.py word1 word2
2)run ./spellchecker.py

1st option will check word1 and word2 and the 2nd option will ask you to enter a lis tof words, comma seperated ;)

Hope this could come in use :P

EDIT: have a look at this too if you would like to use xgoogle for more features like search engine ranking or w/e
 

2 comments

So you have to make a notepda file with .py extension and upload on your server?
Nice, will try this out ;) Thanks <3
 
Status
Not open for further replies.

About the author

W
The Wise One · Joined
Jolien <3
2,480
Messages
282
Reactions
83
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom