dictionary = 'dict.txt' def set_dictionary(filename='dict.txt'): """ Load the specified file as the dictionary, overwriting any previous dictionaries. """ dictionary = filename def spellcheck_text(document_list, index=0): """ Takes a list of words with whitespace removed, and an integer index positive to count from left of list, negative to count from right). Starting at word , return the index of the first word in the list not in the dictionary, or -1 if no such words are found. """ dictionary_file = open(dictionary) dictionary_list = dictionary_file.read().split() count = index for word in document_list[index:]: if dictionary_list.count(word) == 0: return count else: count = count + 1 return -1 ############################### ## Main for testing ## ############################### def remove_punc(word): if word.isalpha(): return word else: stripped_word = '' for char in word: if char.isalpha() or char == "'": stripped_word = stripped_word + char return stripped_word def test(filename='input.txt', index=0): input_file = open(filename) input_string = input_file.read() stripped_words = map(remove_punc, input_string.split()) testhelp(stripped_words, 0) def testhelp(stripped_words, index): nextmisspell = spellcheck_text(stripped_words, index) print stripped_words[nextmisspell] testhelp(stripped_words, nextmisspell+1) ############################### ## Non-implemented functions ## ############################### def add_dictionary(filename): """ Add the words in the specified file to the dictionary. """ def add_to_dictionary(word): """ Add the argument to the dictionary. """ def delete_from_dictionary(word): """ Remove the argument from the dictionary. """ def ignore_word(word): """ Do not find this word as misspelled until the spellchecker exits or is reloaded, even though it is not in the dictionary. """ def find_alternate_words(word): """ Return a list of the closest matches if the word is not in the dictionary, or an empty list if it is. """