-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
173 lines (171 loc) · 4.28 KB
/
main.cpp
File metadata and controls
173 lines (171 loc) · 4.28 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <iostream>
#include <sstream>
#include "Skyline.h"
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <tuple>
using namespace std;
void read_node_from_file(
const string path,
unordered_map<int, string> &id_to_name,
unordered_map<string, int> &name_to_id,
vector<SkylineOnRDF::RDFNode> &nodes)
{
ifstream f(path.c_str());
if (!f.is_open())
{
cerr << "file not open !" << endl;
return;
}
string line;
int id = 0;
while (getline(f, line))
{
SkylineOnRDF::RDFNode node;
string name, info;
size_t pos = line.find(':');
name = line.substr(0, pos);
info = line.substr(pos + 2);
stringstream ss(info);
while (getline(ss, info, ',')) {
node.info.push_back(info);
}
node.is_location = true;
id_to_name.insert({ id, name });
name_to_id.insert({ name, id });
nodes.push_back(node);
id++;
}
f.close();
}
void read_edge_from_file(const string path, SkylineOnRDF::Skyline &sky, unordered_map<string, int>& name_to_id)
{
ifstream f(path.c_str());
if (!f.is_open())
{
cerr << "file not open !" << endl;
return;
}
string line;
set<int> nexts;
int lose_vertex = 0, lose_edge = 0;
while (getline(f, line))
{
string name, next;
size_t pos = line.find(':');
name = line.substr(0, pos);
next = line.substr(pos + 2);
stringstream ss(next);
nexts.clear();
while (getline(ss, next, ',')) {
auto iter = name_to_id.find(next);
if (iter != name_to_id.end())
nexts.insert(iter->second);
else
lose_edge++;
}
auto it = name_to_id.find(name);
if (it != name_to_id.end())
{
sky.addNext(name_to_id.find(name)->second, nexts);
sky.addPrior(name_to_id.find(name)->second, nexts);
}
else
lose_vertex++;
}
cout << "lose vertex: " << lose_vertex << endl;
cout << "lost edge: " << lose_edge << endl;
}
int main()
{
/*int num;
cin >> num;
string name, info, next;*/
SkylineOnRDF::Skyline sky;
unordered_map<int, string> id_to_name;
unordered_map<string, int> name_to_id;
vector<SkylineOnRDF::RDFNode> nodes;
clock_t t0 = clock();
read_node_from_file("node_keywords.txt", id_to_name, name_to_id, nodes);
/*int round = num;
int id = 0;
while(round-- > 0)
{
SkylineOnRDF::RDFNode node;
cin >> name >> info;
stringstream ss(info);
while (getline(ss, info, ',')) {
node.info.push_back(info);
}
if (name.find('P') != name.npos)
node.is_location = true;
else
node.is_location = false;
id_to_name.insert({ id, name });
name_to_id.insert({ name, id });
nodes.push_back(node);
id++;
}*/
sky.init(nodes, id_to_name);
/*round = num;
while(round-- > 0)
{
cin >> name >> next;
if (next == "@end")
continue;
stringstream ss(next);
set<int> nexts;
while (getline(ss, next, ',')) {
nexts.insert(name_to_id.find(next)->second);
}
sky.addNext(name_to_id.find(name)->second, nexts);
sky.addPrior(name_to_id.find(name)->second, nexts);
}*/
read_edge_from_file("edge.txt", sky, name_to_id);
cout << "Init success." << endl;
clock_t t1 = clock();
cout << "Read data cost: " << (double)(t1 - t0) / CLOCKS_PER_SEC << endl;
sky.buildKeywordMap(true);
clock_t t2 = clock();
cout << "build keywords Hash Table cost: " << (double)(t2 - t1) / CLOCKS_PER_SEC << endl;
while (true)
{
cout << "please input the keywords:";
string keywords;
cin >> keywords;
string word;
vector<string> words;
stringstream ss(keywords);
while (getline(ss, word, ',')) {
words.push_back(word);
}
sky.setKeywords(words);
/*cout << "please input the keywords num:";
int num;
cin >> num;
sky.setkeywords(num);*/
clock_t t1 = clock();
sky.computeDistanceMatrix();
clock_t t2 = clock();
//sky.fastComputeDistanceMatrix();
clock_t t3 = clock();
int candidate_sp = sky.BNL();
clock_t t4 = clock();
if (candidate_sp > 0)
{
sky.buildTree();
}
cout << "©Ç©¥©¥©¥©¥©¥©¥©¥©¥©¥BDM Cost: " << (double)(t2 - t1) / CLOCKS_PER_SEC << endl <<endl;
//cout << "©Ç©¥©¥©¥©¥©¥©¥©¥©¥©¥BDM Cost: " << (double)(t3 - t2) / CLOCKS_PER_SEC << endl << endl;
cout << "©Ç©¥©¥©¥©¥©¥©¥©¥©¥©¥BNL Cost: " << (double)(t4 - t3) / CLOCKS_PER_SEC << endl <<endl;
cout << "©Ç©¥©¥©¥©¥©¥©¥©¥©¥©¥All Cost: " << (double)(t4 - t1) / CLOCKS_PER_SEC << endl <<endl;
cout << "©»";
int counter = 33 + 7 + 3 * words.size() - 2 - 2;
while (counter-- > 0)
cout << "©¥";
cout << "©¿\n" << std::endl;
}
//system("pause");
return 0;
}