-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
95 lines (82 loc) · 1.99 KB
/
Copy pathmain.cpp
File metadata and controls
95 lines (82 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <string>
#include <fstream>
#include <iostream>
#include <string.h>
#include "stringset.h"
using namespace std;
void searchengine(void)
{
string word;
int tempCounter = 0;
int URLcounter = 0;
int wordCounter = 0;
Stringset S;
string mainURL;
ifstream inputFile("webpages.txt");
while (inputFile >> word)
{
if (word == "NEWPAGE")
{
inputFile >> word;
mainURL = word;
S.insert(word, tempCounter);
tempCounter++;
URLcounter++;
}
else if (word[0] == 'h' && word [1] == 't' && word[2] == 't' && word[3] == 'p')
{
//do nothing.
}
else
{
S.insertWord(word, mainURL);
wordCounter++;
}
}
inputFile.close();
S.allocateInvertedIndex(wordCounter);
//In the below block, we're not removing bad links; we've refrained from
//inserting links and instead have inserted NEWPAGEs and words in the first
//While loop, so now we only insert the links (which we identiy via their
//beginning with 'https') for which S.find(word) is true.
inputFile.open("webpages.txt");
int currentPageID;
while (inputFile >> word)
{
if (word == "NEWPAGE")
{
//Making sure we don't catch NEWPAGEs with our insertLink
inputFile >> word;
mainURL = word;
currentPageID = S.externalHash(word);
}
else if (word[0] == 'h' && word [1] == 't' && word[2] == 't' && word[3] == 'p')
{
//ignore Links that are not NEWPAGEs.
if (S.find(word))
{
S.insertLink(word, mainURL);
}
}
else
{
S.insertWordToIndex(word, wordCounter, currentPageID);
}
}
inputFile.close();
S.rankPages(URLcounter);
string searchTerm;
cout << endl << "Please enter a search term (or quit to exit program): ";
cin >> searchTerm;
while (searchTerm != "quit")
{
S.search(searchTerm, URLcounter);
cout << endl << "Please enter a search term (or quit to exit program): ";
cin >> searchTerm;
}
}
int main(void)
{
searchengine();
return 0;
}