Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fill in 2 methods in .cpp file C++ #ifndef WEBTOPIC_HPP_ #define WEBTOPIC_HPP_ #include SNode.hpp #include SLL.hpp #include using namespace std; class WebTopic { int currpriority;

Fill in 2 methods in .cpp file C++

#ifndef WEBTOPIC_HPP_

#define WEBTOPIC_HPP_

#include "SNode.hpp"

#include "SLL.hpp"

#include

using namespace std;

class WebTopic {

int currpriority;

//This priority changes as the web page is traversed based on the last tag

//that has been read in

SLL *wordlist;

//the list of words ordered by priority

string file;

//The name of the web page file being read in

// (below) the ARRAY of stopwords, to be removed from the linked list

string stopwords[50]={"a",

"along",

"although",

"am",

"among",

"and",

"are",

"as",

"at",

"be",

"because",

"between",

"can",

"do",

"dont",

"either",

"for",

"got",

"has",

"have",

"havent",

"he",

"i",

"in",

"is",

"isnt",

"it",

"more",

"much",

"neither",

"no",

"none",

"nor",

"not",

"of",

"one",

"or",

"that",

"the",

"they",

"this",

"though",

"was",

"when",

"while",

"why",

"with",

"without",

"you",

"your"

};

int swlen = 50; // the length of the ARRAY stopwords, above

public:

WebTopic(string filename);

//constructor

void ReadFile();

//reads in the web page, character by character, into a a line, setting the

//current priority based on the latest tag read in. This method calls

//getPriority when a tag has been read in, and it calls parseString when the //text between tags has been read in.

void parseString(string line);

//takes a line of characters and breaks the line up into words by creating a

//new string of only alphabetical characters: Note: I did this by first

//breaking the string into individual words separated by spaces, and then used

//the function stripSpace to remove anything that wasnt an alphanumeric

//character using the built in isalpha function.

string stripSpace(string s);

//Strips out any character that isnt alphanumeric and returns the stripped

//string

void getPriority(string line);

//The line is the tag, without the first <. This method uses the line to

//determine the current priority as follows:

//If the first 5 characters in the line match the word title (I used

//line.compare for this), or the first 2 characters match either h2 or h2,

//then the current priority is set to 1. If the first 2 characters are

//anything between h3 and h6, then the priority is set to 2, and if its

//anything else, its set to 3.

void printPage();

// (6 pts) YOU WRITE

//prints out the list of words on the web page, ordered by their priority (and

//listing each words priority

void removeStopWords();

// (4 pts) YOU WRITE

// after the linked list has been created, this method removes all the

// stopwords in the array of stopwords from the linked list (using the

// removeAll method)

};

#endif /* WEBTOPIC_HPP_ */

//.cpp

#include "SLL.hpp"

#include "SNode.hpp"

#include "WebTopic.hpp"

#include

#include

#include

#include

#include

#include

using namespace std;

WebTopic::WebTopic(string filename) {

file = filename;

wordlist = new SLL();

currpriority = 3;

}

void WebTopic::getPriority(string line) {

//cout << endl;

//cout << line << endl;

if (line.compare(0,5,"title") == 0 || line.compare(0,2,"h1")==0 || line.compare(0,2, "h2")==0) {

currpriority = 1;

}

else if (line.compare(0,2,"h3") == 0 ||line.compare(0,2,"h4") == 0||line.compare(0,2,"h5") == 0||line.compare(0,2,"h6") == 0) {

currpriority = 2;

}

else {

currpriority = 3;

}

// cout << "Curr Priority: " << currpriority << endl;

}

void WebTopic::printPage() {

// YOU WRITE

}

void WebTopic::readFile() {

ifstream infile(file.c_str(),ios::in); // open file

string line = "";

char c;

while (infile.get(c)) {

if (c == '<') {

if (!line.empty()) {

//cout << "Line outside of tag: "<

//cout << line << endl << endl;

parseString(line);

line = "";

}

}

else if (c == '>') {

//cout << "Line inside of tag: "<

//cout << line << endl << endl;

getPriority(line);

line = "";

}

else {

line += c;

}

}

cout <<"*****************************************" << endl;

cout << "BEFORE REMOVING STOP WORDS" << endl;

printPage();

cout << endl;

removeStopWords();

cout <<"*****************************************" << endl;

cout << "AFTER REMOVING STOP WORDS" << endl;

printPage();

cout << endl;

infile.close();

}

string WebTopic::stripSpace(string s) {

unsigned int i = 0;

while (i < s.length()) {

if (!isalpha(s[i])) {

s.erase(i);

}

i++;

}

return s;

}

void WebTopic::parseString(string line) {

char *l=const_cast(line.c_str());

char *token = strtok(l, " ");

while (token != NULL) {

string s = stripSpace(token);

if (s != "") {

wordlist->priorityInsert(s,currpriority);

}

token = strtok(NULL, " ");

}

}

void WebTopic::removeStopWords(){

// YOU MUST WRITE

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Ai And The Lottery Defying Odds With Intelligent Prediction

Authors: Gary Covella Ph D

1st Edition

B0CND1ZB98, 979-8223302568

More Books

Students also viewed these Databases questions