Here is all the files: Ive already written the code in the textreader file but my answer is giving me errors. Can you fix the errors in my code in one of the functions or which ever one doesnt work.
my answer for the functions in text reader file:
void TextReader::readIn(const string& filename) {
fstream fi; //file object to read the data
fi.open(filename, ios::in); //opening the file
vector key; //vector to store the keys
if(fi){ //if file opened successfully then continue the operation
fi.clear();
fi.seekg(0); //making the file reading position at start
string s; //string to read the file data
while(getline(fi, s)){ //reading the file data
stringstream ss(s);
string w, l;
while(ss >> w){ //taking each word form the line to operate over them
l = ” “;
string n = w.substr(w.size() – 1); //taking the last digit of the word
if (n == “.” || n == “?” || n == “!”){ //checking if it is a terminal symbol
l = w[w.size() – 1]; //if it is then store the data
w.pop_back(); //remove that from the original word
goto a; //goto a lebel to perform next operation
b:w = l; //after operating on the word store it again in w to perform operation on it
l = ” “; //making l again blank
}
a:int x = 0; //variable to check if the key is present in the vector already or not
for (int i = 0; i < key.size(); i++) if (w == key[i]){ //if key is present then make x 1 and break the loop x = 1; break; } if (x == 0) //if key not present then add it to the vector key.push_back(w); if (l != " ") //if l is not blank then goto b label to perform operation on the terminal symbol goto b; } } for (int i = 0; i < key.size(); i++){ //loop through all keys to store their next values fi.clear(); fi.seekg(0); //making the file reading position at start to start reading from first again vector value; //vector to store the values next to the key while(getline(fi, s)){ //reading the file data stringstream ss(s); string w, l; while(ss >> w){ //getting each word from the line
l = ” “;
string n = w.substr(w.size() – 1); //taking the last digit of the word
if (n == “.” || n == “?” || n == “!”){ //checking if it is a terminal symbol
l = w[w.size() – 1]; //if it is then store the data
w.pop_back(); //remove that from the original word
}
if (key[i] == w && w != “.” && w != “?” && w != “!”){ //if w is not terminal then push it to the vector
if (l != ” “){ //if their is no terminal symbol in the next word then push it
w = l;
}
else{
ss >> w;
l = w.substr(w.size() – 1); //otherwise store the terminal symbol
if (l == “.” || l == “?” || l == “!”) //remove the terminal symbol from the word
w.pop_back();
}
int x = 0; //variable to check the data is present in the value vector already or not
for (int j = 0; j < value.size(); j++) //checking the vector to check if present or not if (w == value[j]){ x = 1; break; } if (x == 0) //if not present push the next values in the vector value.push_back(w); } } } wordFollowers.insert(pair>(key[i], value)); //insert the key and the vector containing next values
}
}
fi.close(); //close the file
}
//This should return true if the given char is one of the following: . ? !
bool TextReader::isEndPunctuation(const char& character) {
if (character == ‘.’ || character == ‘?’ || character == ‘!’) //checking if the character is ‘.’ or ‘?’ or ‘!’ is or not. If it is then return true
return true;
return false; //otherwise false
}
//This should return the vector of words following a given key.
vector TextReader::getValues(const string& key) {
map>::iterator i; //iterator to iterate over the map
for (i = wordFollowers.begin(); i != wordFollowers.end(); i++) //if key is present in the map return the corrosponding vector
if (key == i->first)
return i->second;
vector x; //otherwise return empty vector
return x;
}
//This should return true if the given key is found, else it should return false.
bool TextReader::search(const string& key) {
map>::iterator i; //iterator to iterate over the map
for (i = wordFollowers.begin(); i != wordFollowers.end(); i++) //if the key is present in the map return true
if (key == i->first)
return true;
return false; //otherwise false
}
//This should return the count of words that follow the given word in the text.
size_t TextReader::howManyfollowers(const string& key) {
map>::iterator i; //iterator to iterate over the map
for (i = wordFollowers.begin(); i != wordFollowers.end(); i++) //if key is present in the map return the corrosponding vector size
if (key == i->first)
return i->second.size();
return -1; //otherwise -1
}
int main(){
TextReader obj; //declaring object of TextReader
obj.readIn(“Test.txt”); //reading from the text file
vector word = obj.getValues(“I”); //getting all values for the value “I”
for (int i = 0; i < word.size(); i++) //printing received vector cout << word[i] << " "; cout << endl; word = obj.getValues("love"); //getting all values for the value "love" for (int i = 0; i < word.size(); i++) //printing received vector cout << word[i] << " "; cout << endl; word = obj.getValues("travelling"); //getting all values for the value "travelling" for (int i = 0; i < word.size(); i++) //printing received vector cout << word[i] << " "; cout << endl; /*word = obj.getValues("also"); //getting all values for the value "also" for (int i = 0; i < word.size(); i++) //printing received vector cout << word[i] << " "; cout << endl;*/ word = obj.getValues("reading"); //getting all values for the value "reading" for (int i = 0; i < word.size(); i++) //printing received vector cout << word[i] << " "; cout << endl; word = obj.getValues("books"); //getting all values for the value "books" for (int i = 0; i < word.size(); i++) //printing received vector cout << word[i] << " "; cout << endl; return 0; } here is the orignal files provided: main.cpp : #include #include #include // abs() #include "TextReader.hpp" using namespace std; // Global static variables static int testCount = 0; static const int testTotal = 16; static const string GREEN = "33[32m"; static const string RED = "33[31m"; static const string RESET = "33[0m"; // Prototypes template bool assertEquals(const string& nameOfTest, const T& expected, const U& actual); template bool assertVectorEquals(const string& nameOfTest, const vector& expected, const vector& actual); // Main int main(int argc, char const *argv[]) { TextReader gen; assertEquals("'.' is Punctuation :", true, gen.isEndPunctuation('.')); assertEquals("'?' is Punctuation :", true, gen.isEndPunctuation('?')); assertEquals("'!' is Punctuation :", true, gen.isEndPunctuation('!')); assertEquals("'a' is Punctuation :", false, gen.isEndPunctuation('a')); TextReader Frankenstein; Frankenstein.readIn("Frankenstein or The Modern Prometheus by Mary Shelley.txt"); { vector expected = { "lovers,", "days", "lovers" }; assertVectorEquals("Values : Frankenstein 'youthful'", expected, Frankenstein.getValues("youthful")); expected = { "out", "the", "the", "by", "in", "their", "on" }; assertVectorEquals("Values : Frankenstein 'marked'", expected, Frankenstein.getValues("marked")); assertEquals("Value Count : Frankenstein '^' > 0: “, true, Frankenstein.getValues(“^”).size() > 10);
assertEquals(“Searching : Frankenstein ‘rejoice’ found”, true, Frankenstein.search(“rejoice”));
assertEquals(“Followers Count : Frankenstein ‘breeze'”, 8, Frankenstein.howManyfollowers(“breeze”));
assertEquals(“Followers Count : Frankenstein ‘river'”, 9, Frankenstein.howManyfollowers(“river”));
}
TextReader SleepyHollow;
SleepyHollow.readIn(“The Legend of Sleep Hollow by Washington Irving.txt”);
{
vector expected = { “hill,”,”crests”, “dell,” };
assertVectorEquals(“Values : SleepyHollow ‘woody'”, expected, SleepyHollow.getValues(“woody”));
expected = { “which”, “of”, “of” };
assertVectorEquals(“Values : SleepyHollow ‘quarter'”, expected, SleepyHollow.getValues(“quarter”));
assertEquals(“Value Count : SleepyHollow ‘^’ < 0", false, SleepyHollow.getValues("^").size() < 10); assertEquals("Searching : SleepyHollow 'complexity' found", false, SleepyHollow.search("complexity")); assertEquals("Followers Count : SleepyHollow 'complexity'", 0, SleepyHollow.howManyfollowers("complexity")); assertEquals("Followers Count : SleepyHollow 'river'", 2, SleepyHollow.howManyfollowers("river")); } cout << endl << testCount << " tests passed out of " << testTotal << " total tests" << endl << 100.0 * (float)testCount / (float)testTotal << "/100" << endl; return 0; } // Helper Functions template bool assertVectorEquals(const string& nameOfTest, const vector& expected, const vector& actual) { if (expected.size() == actual.size()) { for (size_t i = 0; i < expected.size(); i++) { if (expected[i] != actual[i]) { // Red colored text cout << RED << "FAILED " << RESET << nameOfTest << ": expected '" << expected[i] << "' but actually '" << actual[i] << "'" << endl; return false; } } // Green colored text cout << GREEN << "PASSED " << RESET << nameOfTest << ": expected and actual lists match: {"; for (int i = 0; i < expected.size(); i++) { cout << " " << expected[i]; } cout << " }" << endl; testCount++; return true; } // Red colored text cout << RED << "FAILED " << RESET << nameOfTest << ": expected size '" << expected.size() << "' but actually size is '" << actual.size() << "'" << endl; return false; } template bool assertEquals(const string& nameOfTest, const T& expected, const U& actual) { if (expected == actual) { // Green colored text cout << RESET << GREEN << "PASSED " << RESET << nameOfTest << GREEN << ": expected and actual '" << RESET << actual << GREEN << "'" << RESET << endl; testCount++; return true; } // Red colored text cout << RESET << RED << "FAILED " << RESET << nameOfTest << RED << ": expected '" << RESET << expected << RED << "' but actually '" << RESET << actual << RED << "'" << RESET << endl; return false; } sanitze : #pragma once #include #include void sanitize(std::string &); bool shouldFilter(const char &); // Sanitizes a given word by removing non-essential characters from the start // and end. void sanitize(std::string & word) { size_t start_index = 0; size_t end_index = word.size() - 1; while (shouldFilter(word[start_index])) { start_index++; } while (end_index <= word.size() - 1 && shouldFilter(word[end_index])) { end_index--; } if (start_index != 0 || end_index != word.size() - 1) { size_t len = end_index - start_index; word = word.substr(start_index, len + 1); } } // Returns true if character should be filtered out. bool shouldFilter(const char & target) { char bad_char[] = { ' ', '_', '-', '"'

For This or a Similar Paper Click Here To Order Now