Question

Write a program IN PYTHON that checks the spelling of all words in a file. It...

Write a program IN PYTHON that checks the spelling of all words in a file. It should read each word of a file and check whether it is contained in a word list. A word list available below, called words.txt. The program should print out all words that it cannot find in the word list.

Requirements

Your program should implement the follow functions:

  • main()

The main function should prompt the user for a path to the dictionary file and a path to the file with words that need to be checked. It should then call check_words and use the list returned to print out all the words that were misspelled.

  • check_words(dictionary, file_to_check)

The check_words function has two string parameters that contain the file path to the dictionary and file to be spell checked respectively. This function should open both files and check that all words in the file_to_check are also listed in the dictionary file. After checking each word in file_to_check, a list containing each misspelled word should be returned.

When performing the comparison to check, be sure to convert the word you are checking to lowercase so that you avoid any case issues (e.g. 'a' != 'A').

0 0
Add a comment Improve this question Transcribed image text
Answer #1

spelling.py


def check_words(dictionary, file_to_check):

dictonary = open(dictionary, "r")
myFile = open(file_to_check, "r")

file1Arr = []
file2Arr = []

# get words from file to list
for word in dictonary.read().split():
file1Arr.append(word)
for word in myFile.read().split():
file2Arr.append(word)
correctWords = []
  
# get correct words from file to list
for i in file1Arr:
for j in file2Arr:
if i.lower() == j.lower():
correctWords.append(i)   
break
inCorrectWords =[]
# remove correct words to keep incorrect words only

for i in correctWords:
if i in file2Arr:
file2Arr.remove(i)
inCorrectWords=file2Arr
# Print list
print("Spelling correct words")
print(correctWords)
print("Misspelled words")
print(inCorrectWords)


dictonary=input("Enter dictonary file name ")
file_to_check=input("Enter file to check ")
check_words(dictonary,file_to_check)

Output

words.txt

apple
Orange
banana
Blackberry
Blackcurrant
Black sapote
Blueberry
Crab apples
Currant
Cherry

myFIle.txt

apple
Orange
banana
Blackberry
Blackcurrant
Black sapote
Blueberry
Crab apples
Currant
Cherry

Add a comment
Know the answer?
Add Answer to:
Write a program IN PYTHON that checks the spelling of all words in a file. It...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ and not Java: Implement a spelling checker by using a hash table. Assume that...

    In C++ and not Java: Implement a spelling checker by using a hash table. Assume that the dictionary comes from two sources: an existing large dictionary and a second file containing a personal dictionary. Output all misspelled words and the line numbers on which they occur. Also, for each misspelled word, list any words in the dictionary that are obtainable by applying any of the following rules: 1. Add one character. 2. Remove one character. 3. Exchange adjacent characters The...

  • Dictionary.java DictionaryInterface.java Spell.java SpellCheck.java In this lab you will write a spell check program. The program...

    Dictionary.java DictionaryInterface.java Spell.java SpellCheck.java In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the input file to be spell checked. The program will read in the words for the dictionary, then will read the input file and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is, add...

  • Write a program that employs the four letter word dictionary to check the spelling of an...

    Write a program that employs the four letter word dictionary to check the spelling of an input word (test word). You will need to save the dictionary file to a folder on your computer. For this program you will prompt the user to enter a four letter word (or four characters). Then using a loop read each word from the dictionary and compare it to the input test word. If there is a match then you have spellchecked the word....

  • In this lab you will write a spell check program. The program has two input files:...

    In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...

  • For this week's lab, you will use two of the classes in the Java Collection Framework:...

    For this week's lab, you will use two of the classes in the Java Collection Framework: HashSet and TreeSet. You will use these classes to implement a spell checker. Set Methods For this lab, you will need to use some of the methods that are defined in the Set interface. Recall that if set is a Set, then the following methods are defined: set.size() -- Returns the number of items in the set. set.add(item) -- Adds the item to the...

  • For this week's lab, you will use two of the classes in the Java Collection Framework:...

    For this week's lab, you will use two of the classes in the Java Collection Framework: HashSet and TreeSet. You will use these classes to implement a spell checker. Set Methods For this lab, you will need to use some of the methods that are defined in the Set interface. Recall that if set is a Set, then the following methods are defined: set.size() -- Returns the number of items in the set. set.add(item) -- Adds the item to the...

  • Overview: The goal of this assignment is to implement a simple spell checker using a hash...

    Overview: The goal of this assignment is to implement a simple spell checker using a hash table. You will be given the basic guidelines for your implementation, but other than that you are free to determine and implement the exact classes and methods that you might need. Your spell-checker will be reading from two input files. The first file is a dictionary containing one word per line. The program should read the dictionary and insert the words into a hash...

  • (Python 3) Write a program that reads the contents of a text file. The program should...

    (Python 3) Write a program that reads the contents of a text file. The program should then create a dictionary in which the keys are individual words found in the file and the values are the number of times each word appears and a list that contains the line numbers in the file where the word (the key) is found. Then the program will create another text file. The file should contain an alphabetical listing of the words that are...

  • Write a Python equivalent program for the Unix spell utility. You can use the dictionary at /usr/...

    Write a Python equivalent program for the Unix spell utility. You can use the dictionary at /usr/share/dict/words (if you machine does not have it, you can copy it from a Linux machine such as npu29). The minimum requirement is to check if each word in the file exists in the dictionary as is (case insensitive). Your spell checker should inlcude at least two features: 1. Check the simple plural forms (add s or es). 2. Check the simple verb past...

  • PYTHON 1- Write a program that creates a dictionary of the English words for all single...

    PYTHON 1- Write a program that creates a dictionary of the English words for all single digit numbers as follows: 1: 'one', 2: 'two', 3: 'three', etc. 2- Write a function called numConvert that receives the above dictionary and an integer number as parameters, and prints the English words for all the number's digits. For example, if the function receives 2311, it will print: two three one one 3- Test your program by adding a main function, which calls numConvert....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT