-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
95 lines (74 loc) · 2.43 KB
/
Copy pathmain.cpp
File metadata and controls
95 lines (74 loc) · 2.43 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 <iostream>
#include <bits/stdc++.h>
#include <curl/curl.h>
#include <gumbo.h>
#include <vector>
#include <queue>
#include <set>
#include <sstream>
#include "crawler_index.h"
#include "words.h"
using namespace std;
int main() {
make_it();
init();
cout << "Welcome to our search engine, <3.\n";
cout << "To close program type (-1)\n";
cout << "you can write what you want to search about here: ";
// taking search query from the user
string user_text;
getline(cin, user_text);
while (user_text != "-1") {
for (int j = 0; j < user_text.size(); ++j) {
if ((user_text[j] < 'a' || user_text[j] > 'z') && (user_text[j] < 'A' || user_text[j] > 'Z'))
user_text[j] = ' ';
}
stringstream words(user_text);
string word;
vector<string> user_req;
while (words >> word) {
int ans = 1e9;
for (int j = 0; j < (int) word.size(); ++j) {
word[j] = tolower(word[j]);
}
while (word.back() < 'a' || word.back() > 'z')word.pop_back();
if (stopWords.count(word) || word.size() == 0)continue;
//correct
string temp;
for (auto &it: englishWords) {
int dif = correct(word, it);
if (dif < ans) {
ans = dif;
temp = it;
}
}
word = temp;
// change word to its root
word = root(word);
user_req.push_back(word);
}
map<int, int> freq_words;
for (auto search_index: user_req) {
auto _setOfPages = invertedIndex.whereWordExist(search_index);
for (auto [page,freq]: _setOfPages) {
freq_words[page]+=freq;
}
}
vector<pair<int, int>> to_sort;
for (auto [page, freq]: freq_words) {
to_sort.push_back({freq, page});
}
sort(to_sort.rbegin(), to_sort.rend());
int num_of_page = 1;
for (int i = 0; i < to_sort.size(); ++i) {
string link = id[to_sort[i].second];
cout << num_of_page++ << "- ";
cout << link << "\n\n";
}
cout << "To close program type (-1)\n";
cout << "you can write what you want to search about here: ";
getline(cin, user_text);
}
cout << "Tank U for using our search engine.\n";
return 0;
}