-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-stop-words.js
64 lines (58 loc) · 1.69 KB
/
create-stop-words.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
/**
* Tools generate vietnamese stopwords to events imports file.
* Using for EventServer PredictionIO.
*
* Author: Van-Duyet Le
*/
'use strict';
// ===============================
// CONFIG
// ===============================
var OUTPUT = "../data/stopwords-vietnamese.json"; // Output for EventServer-import-file.
// ===============================
// MAIN
// ===============================
var fs = require('fs');
var wget = require('wget');
var path = OUTPUT;
var wget = require('wget');
var options = {
protocol: 'https',
host: 'raw.githubusercontent.com',
path: '/duyetdev/vietnamese-stopwords/master/vietname-stopwords.txt',
method: 'GET'
};
var req = wget.request(options, function(res) {
var content = '';
if (res.statusCode === 200) {
res.on('error', function(err) {
console.log(err);
});
res.on('data', function(chunk) {
content += chunk;
});
res.on('end', function() {
fs.unlink(path, function() {
var words = content.split('\n');
for (var i in words) {
var stopWordRecord = {
event: "stopwords",
eventTime: new Date(),
entityId: i,
entityType: "resource",
properties: {
word: words[i]
}
}
fs.appendFile(path, JSON.stringify(stopWordRecord) + "\n");
}
});
});
} else {
console.log('Server respond ' + res.statusCode);
}
});
req.end();
req.on('error', function(err) {
console.log(err);
});