#!D:/Python/python.exe # Date: Fri, 27 Oct 2000 12:44:55 EDT # From: GregHolmes@aol.com # To: htdig@htdig.org # Subject: [htdig] spell check - python wrapper script # In case anyone might find this useful, I have attached a python wrapper # script that uses ispell to suggest alternatives to search words that may be # typos. The alternatives are presented as links that trigger the same search, # with the suggested word replacing the typo. # It's win32 speciifc, but should be easy to adapt to *nix. I imagine it would # be easy to reimplement in Perl as well. import os import sys import string import win32pipe def main(): #if main returns 0 the user will get an error message theQuery=os.environ['QUERY_STRING'] #Build an exec string to pass to the OS execString="c:\opt\www\cgi-bin\htsearch.exe " execString=execString + '"' execString=execString + theQuery execString=execString + '" ' #Do the search; put the result page into a temporary file resultsFile=win32pipe.popen(execString, 'r') if (resultsFile): resultsOut=resultsFile.read() resultsTestLine=string.split(resultsOut, "\n") resultsFile.close() if (string.find(resultsTestLine[2], "
| Search Word | Suggested Spelling(s) Click on a suggestion to search for that word |
| " fragment=string.split(Line, ":") origWordList=string.split(fragment[0]) origWord=origWordList[1] replaceString=replaceString + origWord + " | " suggestList=string.split(fragment[1], ", ") newQuery=string.lower(theQuery) for suggestWord in suggestList: suggestWord1=string.strip(suggestWord) newQuery1=string.replace(newQuery, origWord, suggestWord1) replaceString=replaceString + "" + suggestWord1 + " " replaceString=replaceString +" |
There was some sort of error.
\n" print "\n\n"