-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmystem.js
21 lines (20 loc) · 852 Bytes
/
mystem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const path = require('path');
const exec = require('child_process').execFile;
const mystemPath = process.env.MYSTEM_PATH || path.join(__dirname, 'mystem-linux');
const mystemParams = process.env.MYSTEM_PARAMS ? process.env.MYSTEM_PARAMS.split(' ') : ['-cigfn', '--format', 'json'];
const timeout = 5 * 1000;
module.exports = function(input) {
return new Promise((resolve, reject) => {
const mystem = exec(mystemPath, mystemParams, { timeout }, (err, stdout, stderr) => {
if (err) return reject({error: err.message});
let arr = [];
for (const line of stdout.split("\n")) {
if (!line || !line.length) continue;
arr.push(JSON.parse(line));
}
return resolve(arr);
});
mystem.stdin.write(input);
mystem.stdin.end();
});
};