""" Purpose: produce spell-check corrected text """ # define annotation markers CORRECTED_WORD_MARKER = "*" UNKNOWN_WORD_MARKER = "_" # get access to url support import url # most common words MOST_COMMON_URL = "http://www.cs.virginia.edu/~cs1112/words/most-common" # words correctsions CSV CORRECTIONS_URL = "http://www.cs.virginia.edu/~cs1112/words/corrections" # get contents of most common words url contents = url.get_contents( MOST_COMMON_URL ) # split contents into a list of good words good_words = contents.split() # get corrections dictionary misspellings_dictionary = url.get_dictionary( CORRECTIONS_URL ) # get the user text to be checked reply = input( "Enter text: " ) # convert reply into a list of words text = reply.split() # what now -- accumulate the spell check output of the user text output = "" for current_word in text : # look at each word in the given input # if word is good, add it to output if ( current_word in good_words ) : printed_word = current_word # otherwise if the word is a known misspelling, add the correction to the output elif ( current_word in misspellings_dictionary ) : correction = misspellings_dictionary.get( current_word ) printed_word = CORRECTED_WORD_MARKER + correction + CORRECTED_WORD_MARKER # otherwise, add flagged word to output else : printed_word = UNKNOWN_WORD_MARKER + current_word + UNKNOWN_WORD_MARKER # update our accumulator with the necessary output, stored in printed_word output = output + printed_word + " " # print spell check results print( output )