I have a problem. In my project, I take sentence line by line from dataset file which has one sentence each line. Then , I should separate sentences into words. But I couldn’t find this how can I do.
This are the codes of class which will read from dataset:
class Input{
...
public:
string *word;
string *sentence;
Couple *couple; // int x , int y order of sentence and word
int number;
int line;
...
void readInput(string input);
}
This are the codes of read method:
void Input::readInput(string input)
{
cout << "Reading the " << input <<endl;
ifstream infile;
infile.open(input.c_str());
if(!infile.is_open()){
cerr << "Unable to open file: " << input << endl << endl;
exit(-1);
}
for(int i=0; i<line ; i++){
getline(infile, sentence[i]);
//infile >> sentence[i];
}
for(int j=0;j<line ;j++){
// I want to separate sentences into words
}
infile.close();
cout << "Finished Reading the " << input <<endl;
}
You’ll need to do something about punctuation though, if you don’t want those attached to your words. Simple enough I think.