Opinions on how to go about this issue??

Opinions on how to go about this issue??

xXJigsaw23Xx
IS what she said.

THISISAMEDAL
2007 Oct 21 • 912
41 ₧
Here is my code I used for the original project. It reads the user input and checks it against a document dictionary for errors and outputs if the word was spelled correctly or if the user meant another word. I need to change this up to read a document and pick out misspelled words out of it. The output would be a list of all the misspelled words in the document.

C++ code

#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
using namespace std;

const int DICT_SIZE=3000; //size of dictionary

ifstream dictIn; //dictionary file stream
string wordList [DICT_SIZE]; //wordlist dictionary file to be loaded
string dictionaryName ="american-english.txt";//name of dictionary

//dictionary file stores word in alphabetical order

int searchDictionary(string dict[], string word, int start, int end)

{


if(end<start)

{ return -1; } //not found

int mid=(start+end)/2;

if(dict[mid]==word)

{ return mid; } //found

else if(dict[mid] < word)

return searchDictionary(dict, word,mid+1, end);

else

return searchDictionary(dict,word,start,mid-1);

}



int main() {

string word = "";
string tempWord = "";

dictIn.open(dictionaryName.c_str()); //load dictionary
int howMany=0; //count length of dictionary

dictIn>> wordList [howMany];

while(dictIn) //read successful

{

howMany++; //count

dictIn>> wordList [howMany]; //read dictionary

}

cout << "Please enter a word to search for: ";
cin >> word;
tempWord = word;

int search = searchDictionary(wordList, word, 0, howMany);
if (search != -1)
cout << "The word " << word << " is spelled incorrectly." << endl;


bool finished = 0;
bool wordFound = 0;
int length = word.length();
int n = 0;
int e = 0;
string userInput = word;


while(search == -1 && e < length && !finished)
{
e++;
n = e - 1;
swap(word[n],word[e]);
search = searchDictionary(wordList, word, 0, howMany);
if (search != -1){
cout << "Did you mean " << word << "? (enter 0 for no, 1 for yes)" << endl;
cin >> wordFound;
if (wordFound)
{
finished = 1;
cout << "The word was " << word << "." << endl;
}
}

search = -1;
word = userInput;
n++;
if (e >= length){
cout << "The word " << word << " is spelled incorrectly." << endl;
finished;
}
}
}
But even then, I had my honor. The largest Banora White tree grew on a wealthy man's estate. It was rumored, that those apples tasted the best, but I never stole from that tree, because the wealthy man's son, was my friend...
 
 
 
2015 Sep 21 at 04:44 UTC
xXJigsaw23Xx
IS what she said.

THISISAMEDAL
2007 Oct 21 • 912
41 ₧
Also, an update on this. Although that was my original code. This is the code that I had planned to work with to deal with punctuation issues.

C++ code

#include <bits/stdc++.h>
using namespace std;

map <string,int> my_map;

bool check(string s){

if (my_map.find(s) == my_map.end())
return true;
return false;
}

int main(){

string ch = ".,:;()'-=+/*[]{}<>?!&|_";
ifstream infile;
infile.open("document.txt");
char c;
string temp = "";

cout << "The output of the spelling checker is a sorted list of misspelled words (all lower case), one word per line. " << endl << endl;

while (infile.get(c)){

if (ch.contains(c) == true || c-37 == 0 || c-47 == 0){

if (check(temp) == false)

cout << temp << endl;

temp = "";

}
else
temp += c;
}
return 0;
}
But even then, I had my honor. The largest Banora White tree grew on a wealthy man's estate. It was rumored, that those apples tasted the best, but I never stole from that tree, because the wealthy man's son, was my friend...
 
 
 
2015 Sep 21 at 05:16 UTC
SuperJer
Websiteman

2005 Mar 21 • 6666
Can you not use a library function to split the document into words? That would make things easier.

You probably want to add SPACE to string ch. Words are usually delimited by spaces.

Maybe try outputting just the words you find until you get the splitting working.

You have some weird stuff in there like "== true" that I would get rid of.

If you're going to check if(a) you don't need to do if(a==true). Pretty soon you'll end up with if((a==true)==true).

Also checking if(c-37==0) is a really awkward way to check if(c==37). which is itself a really awkward way to check if(c=='%').
 
 
 
2015 Sep 21 at 07:38 UTC — Ed. 2015 Sep 21 at 07:51 UTC
xXJigsaw23Xx
IS what she said.

THISISAMEDAL
2007 Oct 21 • 912
41 ₧
So I'll probably post the finished product of this later. but actually there is a good portion of the stuff I posted that ended up like you've said being irrelevant to it. I've changed it a bit.
But even then, I had my honor. The largest Banora White tree grew on a wealthy man's estate. It was rumored, that those apples tasted the best, but I never stole from that tree, because the wealthy man's son, was my friend...
 
 
 
2015 Sep 22 at 04:32 UTC — Ed. 2015 Sep 22 at 04:32 UTC
xXJigsaw23Xx
IS what she said.

THISISAMEDAL
2007 Oct 21 • 912
41 ₧
Actually it's not like I couldn't just let you see. I'm just being a lazy fuck.
I'm trying to mix up the code at this point and just test it some.


code

#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
#include <stdio.h>
#include <string.h>

using namespace std;
const int LENGTH=30;

void removePunct(string & str);

int searchDictionary(string dict[], string word, int start, int end)

{


if(end<start)

{ return -1; } //not found

int mid=(start+end)/2;

if(dict[mid]==word)

{ return mid; } //found

else if(dict[mid] < word)

return searchDictionary(dict, word,mid+1, end);

else

return searchDictionary(dict,word,start,mid-1);

}

int BinarySearch (char ary[][LENGTH], int size, char search_item[LENGTH]){

const int LENGTH=30;
int first = 0, last = size-1;
bool found = false;
int position = -1, middle;

while (!found && first <= last){
middle = (first + last) / 2;
if ((strcmp (ary[middle], search_item))==0){
position = middle;
found = true;
}
else if (ary[middle] < search_item)
first = middle+1;
else last = middle-1;
}
return position;

}

int main() {

const int DICT_SIZE=3000; //size of dictionary

ifstream dictIn; //dictionary file stream
ifstream docIn; //document file stream
string wordList [DICT_SIZE]; //wordlist dictionary file to be loaded
string dictionaryName ="american-english.txt";//name of dictionary
int j=0, l=0, w=0, pos;
char c;

string word = "";
string tempWord = "";

dictIn.open(dictionaryName.c_str()); //load dictionary
int howMany=0; //count length of dictionary

dictIn>> wordList [howMany];

while(dictIn) //read successful

{

howMany++; //count

dictIn>> wordList [howMany]; //read dictionary

}
char templist = wordList[howMany];

docIn.open("document.txt"); //open document

for (l=0; !docIn.eof(); l++){ //test letters and reduce to lowercase
docIn >> word;
for (int a=0; word[a]!=0; a++){
while (word[a]){

c=word[a];
word[a]= (tolower(c));
a++;
}
}

pos=BinarySearch(templist, j, word);
if (pos==-1){
cout << word << " misspelled!!" << endl;
}

}
docIn.close();


return 0;


tempWord = word;

int search = searchDictionary(wordList, word, 0, howMany);
if (search != -1)
cout << "The word " << word << " is spelled incorrectly." << endl;


bool finished = 0;
bool wordFound = 0;
int length = word.length();
int n = 0;
int e = 0;
string userInput = word;


while(search == -1 && e < length && !finished)
{
e++;
n = e - 1;
swap(word[n],word[e]);
search = searchDictionary(wordList, word, 0, howMany);
if (search != -1){
cout << "Did you mean " << word << "? (enter 0 for no, 1 for yes)" << endl;
cin >> wordFound;
if (wordFound)
{
finished = 1;
cout << "The word was " << word << "." << endl;
}
}

search = -1;
word = userInput;
n++;
if (e >= length){
cout << "The word " << word << " is spelled incorrectly." << endl;
finished;
}
}
}



/*Function to remove punctuation from string*/
void removePunct(string & str)
{
str.erase(remove_if(str.begin(), str.end(), static_cast<int(*)(int)>(&ispunct)),str.end());
}
But even then, I had my honor. The largest Banora White tree grew on a wealthy man's estate. It was rumored, that those apples tasted the best, but I never stole from that tree, because the wealthy man's son, was my friend...
 
 
 
2015 Sep 22 at 04:34 UTC
Page [1]