"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 a list of every word in W that could be a correct spelling of s. Your program should be able to handle all the common ways that s might be a misspelling of a word in W, including swapping adjacent characters in a word , inserting a single character inbetween two adjacent characters in a word, deleting a single character from a word, and replacing a character in a word with another character. for an extra challenge, consider phonetic substitutions as well. "
I dont need the code just a little help to get me on the right path. Let me explain to you what I understand and then maybe you all can give me some tips from there.
So basically I'll just have the main func store a word as string s and that will check against array string W. If the word is spelled correctly then the func spellCheck will return s, the original word. If the word doesn't match up with a word in the array W then it'll give a list of basically suggested words that could be the correct spelling of s.
Where should I get this data array for a bunch of words? Do I download like a dictionary? Should I use something other than a array? Once I download all the words, I check the user entered word against the elements of whatever data structure i use with a search algorithm right?
Also seems like I need to do some more reading and understanding on what a hash table is. Doing that now !
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
#include <cstdlib>
#include <string>
#include "spellChecker.h"
using namespace std;
int main() {
spellChecker userInput;
cout << "Enter a word to spell check: ";
cin >> userInput.s;
userInput.spellCheck(userInput.s);
return 0;
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
#ifndef PROJECT2_SPELLCHECKER_H
#define PROJECT2_SPELLCHECKER_H
class spellChecker{
private:
unsigned int tableSize = 3;
string W[3] = {"word" ,"check", "test"};
public:
string s;
void spellCheck(string s);
};
#endif //PROJECT2_SPELLCHECKER_H
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <iostream>
#include <cstdlib>
#include <string>
#include "spellChecker.h"
using namespace std;
void spellChecker::spellCheck(string s){
for (int i = 0 ; i < tableSize ; i++ ) {
if (s == W[i]) {
cout << "Your word was in our database";
return ;
}
}
}
|