Spell checker (Programming 3)

"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 ;
        }
    }

}

Last edited on
Where did this exercise come from?
What does "Programming 3" mean?

It seems pretty difficult for a beginner, and I don't see how a hash table is a good data structure for this.

EDIT: I guess it could be okay for a basic checker where you look up the word and if it isn't in the table then you generate all possible variations (like swapping adjacent letters) and check for them.
Last edited on
programming 3 is just the class. I took programming one and two at a community college here. Not sure if this is still considered beginner or not? our teacher posted the question.
Last edited on
std::unordered_map is a hash table.
http://www.cplusplus.com/reference/unordered_map/unordered_map/

EDIT: Actually, std::unordered_set would probably be better.
http://www.cplusplus.com/reference/unordered_set/unordered_set/
Last edited on
Topic archived. No new replies allowed.