-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathranking.js
322 lines (288 loc) · 10.8 KB
/
ranking.js
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
$(function() {
var dialog;
var dHeight = $(window).height() * 0.9;
dialog = $("#dialog_2").dialog({
autoOpen: false,
height: dHeight,
width: "98%",
modal: true
});
// $("#hi").on("click", function() {
// console.log("open it!");
// dialog.dialog("open");
// });
$("#increase-nodes-button").click(function() {
others_count++;
showModal(last_clicked_element);
});
$("#decrease-nodes-button").click(function() {
others_count--;
others_count = Math.max(0, others_count);
showModal(last_clicked_element);
});
});
//$(document).ready(function() {
var top_k = 10;
var rect_width = 120;
var rect_height = 30;
var truncate_limit = 18;
var others_count = 2;
var lists_arr = Array();
var last_clicked_element;
function generateAllLists(result_dir, query_index, tk, query_text) {
// alert(query_index);
top_k = tk;
// var query = "5";
var root_dir = result_dir;
// var root_dir = "data\\ranking\\dblp_c50_top2000";
// console.log("query_index" + query_index);
var selectedDataset = $(".datasetpicker").select().val();
if (selectedDataset == "citation") {
extension = "";
} else {
extension = ".txt";
}
var src_file1 = root_dir + "\\source\\rwr\\answer.query" + (query_index + 1) + extension;
var target_file1 = root_dir + "\\target\\rwr\\answer.query" + (query_index + 1) + extension;
var src_file2 = root_dir + "\\source\\simrank\\answer.query" + (query_index + 1) + extension;
var target_file2 = root_dir + "\\target\\simrank\\answer.query" + (query_index + 1) + extension;
var src_file3 = root_dir + "\\source\\pathsim\\answer.query" + (query_index + 1) + extension;
var target_file3 = root_dir + "\\target\\pathsim\\answer.query" + (query_index + 1) + extension;
var src_file4 = root_dir + "\\source\\udb\\answer.query" + (query_index + 1) + extension;
var target_file4 = root_dir + "\\target\\udb\\answer.query" + (query_index + 1) + extension;
generateList("#ranking1", src_file1, target_file1, 0);
generateList("#ranking2", src_file2, target_file2, 1);
generateList("#ranking3", src_file3, target_file3, 2);
generateList("#ranking4", src_file4, target_file4, 3);
}
function generateList(selector, src_query_file, target_query_file, listIndex) {
// d3.select(selector).remove();
var list_size = top_k;
d3.select(selector).selectAll("*").remove();
var svgContainer = d3.select(selector).append("svg")
.attr("width", 280)
.attr("height", list_size * 35);
readFileWithoutHeader(src_query_file, function(src_list) {
readFileWithoutHeader(target_query_file, function(target_list) {
// console.log(src_list);
// console.log(src_list);
// console.log(target_list[1]);
// console.log(src_list[5]);
// console.log(svgContainer);
lists_arr[listIndex] = Array();
lists_arr[listIndex]["src"] = src_list;
lists_arr[listIndex]["target"] = target_list;
console.log("initialized the list_arr");
list_size = Math.min(list_size, src_list.length);
createAll(svgContainer, list_size, src_list, target_list, listIndex);
});
});
}
function createAll(svg, top_k, src_list, target_list, listIndex) {
var srcRects = createList(svg, 5, 4, top_k, src_list, src_list, target_list, listIndex, 1);
var destRects = createList(svg, 155, 4, top_k, target_list, src_list, target_list, listIndex, 0);
var connect_src = [];
var connect_target = [];
for (var i = 0; i < top_k; i++) {
for (var j = 0; j < top_k; j++) {
if (src_list[i][0] == target_list[j][0]) {
createLine(svg, srcRects[i], destRects[j]);
connect_src[i] = true;
connect_target[j] = true;
}
}
}
for (var i = 0; i < top_k; i++) {
if (!connect_src[i]) {
createLineSrcToEnd(svg, srcRects[i], srcRects[top_k - 1]);
}
}
for (var i = 0; i < top_k; i++) {
if (!connect_target[i]) {
createLineTargetToEnd(svg, destRects[i], srcRects[top_k - 1]);
}
}
}
function createList(svg, x_init, y_init, count, labels, srcLabels, targetLabels, listIndex, isSource) {
var rects = [];
for (var i = 0; i < count; i++) {
var rectangle = svg.append("rect")
.attr("x", x_init)
.attr("y", y_init + (rect_height * (i)))
.attr("width", rect_width)
.attr("height", rect_height)
.attr("fill", "white")
.attr("stroke", "black")
.attr("stroke-width", 1);
rects[i] = rectangle;
// console.log(labels[i]);
var lb = labels[i][0];
var original_text = labels[i][0];
if (lb != null) {
if (lb.length > truncate_limit) {
lb = lb.substring(0, truncate_limit) + "...";
}
}
var tooltip = rectangle.append("svg:title")
.text(original_text);
var text = svg.append("text")
.attr("x", x_init + 5)
.attr("y", y_init + (rect_height * (i)) + 20)
.text(lb)
.attr("svg:title", original_text)
.attr("id", listIndex + "-" + isSource + "-" + i)
.attr("data-isSource", isSource)
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
.attr("fill", "black");
text.on("click", function(d) {
last_clicked_element = $(this);
var selectedDataset = $(".datasetpicker").select().val();
others_count = dbs[selectedDataset]["other_nodes_count"];
showModal($(this));
d3.event.stopPropagation();
});
rectangle.on("mouseover", function() {
// console.log("over");
// console.log($(this).attr("x"));
$(this).attr("fill", "#ADD8E6");
// d3.event.stopPropagation();
});
rectangle.on("mouseout", function() {
// console.log("over");
// console.log($(this).attr("x"));
$(this).attr("fill", "white");
// d3.event.stopPropagation();
});
}
return rects;
}
function createLine(svg, src, dest) {
var line = svg.append("line")
.attr("x1", (+src.attr("x")) + (+src.attr("width")))
.attr("y1", (+src.attr("y")) + (+src.attr("height") / 2))
.attr("x2", (+dest.attr("x")))
.attr("y2", (+dest.attr("y")) + (+dest.attr("height") / 2))
.attr("stroke-width", 2)
.attr("stroke", "black");
// console.log(line);
}
function createLineSrcToEnd(svg, src, lastsrc) {
var r = Math.floor((Math.random() * 20) + 5);
var line = svg.append("line")
.attr("x1", (+src.attr("x")) + (+src.attr("width")))
.attr("y1", (+src.attr("y")) + (+src.attr("height") / 2))
.attr("x2", (+lastsrc.attr("x")) + (+lastsrc.attr("width") + r))
.attr("y2", (+lastsrc.attr("y")) + (+lastsrc.attr("height")))
.attr("stroke-width", 2)
.attr("stroke", "gray");
// console.log(line);
}
function createLineTargetToEnd(svg, src, lastsrc) {
var r = Math.floor((Math.random() * 20) + 5);
var line = svg.append("line")
.attr("x1", (+src.attr("x")))
.attr("y1", (+src.attr("y")) + (+src.attr("height") / 2))
.attr("x2", (+lastsrc.attr("x")) + (+lastsrc.attr("width") + r))
.attr("y2", (+lastsrc.attr("y")) + (+lastsrc.attr("height")))
.attr("stroke-width", 2)
.attr("stroke", "gray");
// console.log(line);
}
//});
function readFileWithoutHeader(file, callback) {
if (file.charAt(0) == "/") {
file = file.substring(1, file.length);
console.log("readFile, file name changed: " + file);
} else {
console.log("readFile, name is fine: " + file);
}
$.get(file, function(data) {
var list = parseFileWithoutHeader(data);
// console.log(list);
callback(list);
});
}
function readFile(file, callback) {
if (file.charAt(0) == "/") {
file = file.substring(1, file.length);
console.log("readFile, file name changed: " + file);
} else {
console.log("readFile, name is fine: " + file);
}
$.get(file, function(data) {
var list = parseFile(data);
// console.log(list);
callback(list);
});
}
function parseFileWithoutHeader(allText) {
var allTextLines = allText.split(/\r\n|\n/);
var result = [];
// console.log("lines");
// console.log(allTextLines);
for (var i = 0; i < allTextLines.length; i++) {
if (allTextLines[i].length == 0) {
break;
}
var split = allTextLines[i].split('\t');
// console.log(split.length);
if (split.length > 1) {
result[i] = [split[0], split[2]];
} else {
result[i] = split[0];
}
}
//alert(lines.length);
return result;
}
function parseFile(allText) {
var allTextLines = allText.split(/\r\n|\n/);
var result = [];
for (var i = 1; i < allTextLines.length; i++) {
var split = allTextLines[i].split('\t');
result[i] = split[0];
}
//alert(lines.length);
return result;
}
function generateOtherNodes(labels, rank, count) {
var other_nodes_list = Array();
var pre_count = Math.ceil(count / 2);
var post_count = count - pre_count;
var pre_rank = Math.max(0, rank - pre_count);
var post_rank = Math.min(labels.length - 1, rank + post_count);
for (var i = pre_rank; i <= post_rank; i++) {
if (i != rank) {
other_nodes_list.push(labels[i][0])
}
}
return other_nodes_list;
}
algorithmList = ["RWR", "SimRank", "PathSim", "Universal-DB"];
function showModal($element) {
console.log("open it!!!");
var lb_text = $element.attr("title");
var id = $element.attr("id");
var split = id.split("-");
var listIndex = split[0];
var isSource = split[1];
console.log($element);
console.log(lists_arr);
console.log("listIndex: " + listIndex);
console.log("isSource: " + isSource);
var labels = lists_arr[listIndex]["target"];
if (isSource == 1) {
labels = lists_arr[listIndex]["src"];
}
var rank = findInArray(labels, lb_text);
var other_nodes = generateOtherNodes(labels, rank, others_count);
// console.log(lb_text);
$("#dialog_2").dialog("open");
setTimeout(
function()
{
var q_text = $('.search-box').val();
generateModalContent(lb_text, q_text, lists_arr[listIndex]["src"], lists_arr[listIndex]["target"], other_nodes, algorithmList[listIndex]);
}, 50);
}