Question

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 file to be used can be found here: use words.txt from https://github.com/dwyl/english-words.

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

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

#include <iostream> #include <string> #include <fstream> using namespace std; enum errorType { CORRECT, SUB, DEL, INS, TRANS, MANY}; void count( errorType error, int& correct, int& ins, int& del, int& sub, int& trans, int& many ) { switch( error ) { case CORRECT: correct++; break; case INS: ins++; break; case DEL: del++; break; case SUB: sub++; break; case TRANS: trans++; break; case MANY: many++; break; } } // SUBSTITUTION bool isSub( string cw, string bw ) { int i; for( i = 0; i < cw.length(); i++ ) if( cw.at( i ) != bw.at( i ) ) break; return ( cw.substr( i+1 ) == bw.substr( i+1 ) ); } // TRANSPOSITION bool isTrans( string cw, string bw ) { int i; for( i = 0; i < cw.length(); i++ ) if( cw.at( i ) != bw.at( i ) ) break; if( bw.at( i ) == cw.at( i+1 ) && bw.at( i+1 ) == cw.at( i ) ) return ( cw.substr( i+2 ) == bw.substr( i+2 ) ); } // DELETION bool isDel( string cw, string bw ) { int i; for( i = 0; i < cw.length(); i++ ) if( cw.at( i ) != bw.at( i ) ) break; return ( cw.substr( i+1 ) == bw.substr( i ) || cw.substr( 0, cw.length()-1 ) == bw ); } // INSERTION bool isIns( string cw, string bw ) { int i; for( i = 0; i < cw.length(); i++ ) if( cw.at( i ) != bw.at( i ) ) break; return ( cw.substr( i ) == bw.substr( i+1 ) ); } int main() { ifstream fin; errorType error; string cWord, bWord; // SUBSTITUTION, TRANSPOSITION, DELETION, INSERTION int correct, sub, trans, del, ins, many; correct = 0; sub = 0; trans = 0; del = 0; ins = 0; many = 0; char ch; fin.open( "mp5spelling.txt" ); if( !fin ) { cout << "mp5spelling.txt could not be found." << endl; return 1; } // GET FIRST WORD AS CORRECT WORD fin >> cWord; while( !fin.eof() ) { cout << "The correct word is " << cWord << endl; cout << "************************" << endl; // GET NEXT CHARACTER fin.get( ch ); // CHECK IF NEXT CHARACTER IS NOT A NEW LINE while( ch != '\n' ) { // GET NEXT BAD WORD fin >> bWord; cout << bWord << '\t'; // PERFORM ERROR CHECK if( cWord == bWord ) { cout << " No Error" << endl; error = CORRECT; } else if( cWord.length() == bWord.length() ) { // SUBSTITUTION if( isSub( cWord, bWord ) ) { cout << " Substitution Error" << endl; error = SUB; } // TRANSPOSITION else if( isTrans( cWord, bWord ) ) { cout << " Transposition Error" << endl; error = TRANS; } // TOO MANY ERRORS else { cout << " Too many Errors" << endl; error = MANY; } } else { // DELETION if( isDel( cWord, bWord ) ) { cout << " Deletion Error" << endl; error = DEL; } // INSERTION if( isIns( cWord, bWord ) ) { cout << " Insertion Error" << endl; error = INS; } } cout << endl; fin.get( ch ); } cout << "************************" << endl; fin >> cWord; } fin.close(); return 0; }

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
In C++ and not Java: Implement a spelling checker by using a hash table. Assume that...
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
  • 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...

  • Write a spell checker that stores a set of words, W, in a hash table and...

    Write a spell checker that stores a set of words, W, in a hash table and implements a function, spellCheck(s), which performs a spell check on the string s with respect to the set of words, W. If s is in W, then the call to spellCheck(s) returns an iterable collection that contains only s, because it is assumed to be spelled correctly in this case. Otherwise, if s is not in W, then the call to spellCheck(s) returns a...

  • create a hash table to implement spell checker in java 1. Create a file of 100...

    create a hash table to implement spell checker in java 1. Create a file of 100 words of varying length (max 8 characters). 2. All the words are in lower case. 3. design a hash table. 4. enter each word in the hash table. Once the hash table is created, run it as a spell checker.enter a word (interactive), find the word in the hash table. If not found enter an error message. Then prompt for next word. End the...

  • Write a spell checker class that stores a set of words, W, in a hash table...

    Write a spell checker class that stores a set of words, W, in a hash table and implements a function, spellCheck(s), which performs a Spell Check on the string s with respect to the set of words, W. If s is in W, then the call to spellCheck(s) returns an iterable collection that contains only s, since it is assumed to be spelled correctly in this case. Otherwise, if s is not in W, then the call to spellCheck(s) returns...

  • IN JAVA: Write a spell checker class that stores a set of words, W, in a...

    IN JAVA: Write a spell checker class that stores a set of words, W, in a hash table and implements a function, spellCheck(s), which performs a Spell Check on the string s with respect to the set of words, W. If s is in W, then the call to spellCheck(s) returns an iterable collection that contains only s, since it is assumed to be spelled correctly in this case. Otherwise, if s is not in W, then the call to...

  • using java create hash set that can for the file use a txt file: Hi my...

    using java create hash set that can for the file use a txt file: Hi my name is rick. (a) Read one word from the file. (b) Remove all non-alphanumeric characters from the word. A non-alphanumeric character is any character other than the lowercase and uppercase English letters, and the numerals 0 through 9. (c) Add the modified word to the hash set.

  • 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...

  • 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...

  • In this assignment you will implement the second version of your spell checker. Using the randomi...

    In this assignment you will implement the second version of your spell checker. Using the randomized dictionary (random_dictionary.txt) given, read in the dictionary into an array of 26 Binary Search Trees (BST) , one for each letter of the alphabet. Thus the first BST would contain only those words starting with letter 'a', while the last would contain only those words starting with letter 'z'. Then, when you read in the book (oliver.txt), you examine the first character of each...

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