-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathillchange.js
More file actions
38 lines (31 loc) · 826 Bytes
/
illchange.js
File metadata and controls
38 lines (31 loc) · 826 Bytes
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
var dic = require( './illdic-sample.json' );
const URL = "https://mecab-web-api.herokuapp.com/v1/parse";
const request = require('sync-request');
//illchange("メイのバカ");
function illchange(str) {
var text = '';
var response = request('GET', URL,
{
qs: {
'sentence': str,
},
}
);
var json = JSON.parse(response.getBody('utf8')).items[0];
for (var i = 0; i < json.words.length; i++) {
var matchData = dic.filter(function (item) {
if (item.yomi == json.words[i].reading) {
return item.another;
}
}
);
if (matchData[0] !== undefined) {
var rnd = Math.floor(Math.random() * matchData.length);
text += matchData[rnd].another;
}else {
text += json.words[i].surface;
}
}
console.log(text);
return text;
}