-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmain.cpp
78 lines (67 loc) · 1.51 KB
/
main.cpp
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
#include<iostream>
#include<fstream>
#include<string>
#include "pagetable.h"
#include "stringintmap.h"
using namespace std;
int main()
{
ifstream fin;
string s;
string l;
string command;
int page_num = 0;
int word_num = 0;
int index = 0;
StringIntMap url_map, word_map;
fin.open("webpages.txt");
while (fin >> s) {
//cout << s << "\n";
if (s.find("NEWPAGE") != string::npos) {
page_num++;
index = 0;
} else if (s.find("http://") == string::npos) {
if (!word_map.find(s)) {
word_map.insert(s, word_num);
word_num++;
}
}
if (index == 1) url_map.insert(s, page_num-1);
index++;
}
fin.close();
cout << page_num << "\n";
cout << word_num << "\n";
//url_map.print();
//word_map.print();
Pagetable pt(page_num, word_num);
index = 0;
fin.open("webpages.txt");
while (fin >> s) {
//cout << s << "\n";
if (s.find("NEWPAGE") != string::npos) index = 0;
if (index == 1) {
//cout << s << "\n";
pt.add_page(s);
l = s;
} else if (index > 1) {
// insert words
if (s.find("http://") == string::npos) {
pt.insert_word(s);
pt.add_word_array(word_map[s], l, url_map[l]);
// insert links
} else {
if(url_map.find(s)) pt.insert_link(s, url_map[s]); // if s is not in url_map, ignore it
}
}
index++;
}
fin.close();
pt.set_outgoing_num();
pt.page_rank();
//pt.print();
//while(cin >> s) {
// pt.search(word_map[s]);
//}
return 0;
}