-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-combined-data-view.js
55 lines (41 loc) · 1.48 KB
/
generate-combined-data-view.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
var fs = require('fs');
var _ = require('lodash');
var normalizeUrl = require('normalize-url');
var parse = require('csv-parse/lib/sync');
var webpagesCsvBing = fs.readFileSync('./webpages-data-view-032918.txt', 'utf8');
var webpagesCsvGoogle = fs.readFileSync('./webpages-data-view-040418.txt', 'utf8');
var webpagesBing = parse(webpagesCsvBing, {
columns: true,
delimiter: '\t'
});
var webpagesGoogle = parse(webpagesCsvGoogle, {
columns: true,
delimiter: '\t'
});
var normalizedUrlToWebpageBing = _.groupBy(webpagesBing, e => normalizeUrl(e.url, {
normalizeHttps: true
}));
var normalizedUrlToWebpageGoogle = _.groupBy(webpagesGoogle, e => normalizeUrl(e.url, {
normalizeHttps: true
}));
function customizer(objValue, srcValue) {
if (_.isArray(objValue)) {
return objValue.concat(srcValue);
}
}
var normalizedUrlToWebpages = _.mergeWith(_.cloneDeep(normalizedUrlToWebpageBing), normalizedUrlToWebpageGoogle, customizer);
var cnt = 0;
Object.keys(normalizedUrlToWebpages).forEach(function (normalizedUrl) {
if (normalizedUrlToWebpages[normalizedUrl].length >= 2) {
cnt++;
}
});
console.log(cnt);
var normalizedUrlsBing = webpagesBing.map(e => normalizeUrl(e.url, {
normalizeHttps: true
}));
var normalizedUrlsGoogle = webpagesGoogle.map(e => normalizeUrl(e.url, {
normalizeHttps: true
}));
fs.writeFileSync('./normalized-urls-bing.txt', normalizedUrlsBing.join('\n'), 'utf8');
fs.writeFileSync('./normalized-urls-google.txt', normalizedUrlsGoogle.join('\n'), 'utf8');