-
Notifications
You must be signed in to change notification settings - Fork 6
/
toneAnalyzer.js
38 lines (35 loc) · 908 Bytes
/
toneAnalyzer.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
const nlulib = require('watson-developer-cloud/natural-language-understanding/v1.js');
const watsonConfig = {
"username": process.env.WATSON_USER,
"password": process.env.WATSON_PASS,
"version_date": "2017-02-27"
};
const nlu = new nlulib(watsonConfig);
module.exports.analyzeTone = function(text)
{
var parameters = {
'text': text,
'features': {
'keywords': {
'sentiment': true,
'emotion': true,
'limit': 2
}
}
};
return new Promise((resolve, reject) =>
{
nlu.analyze(parameters, (err, res) =>
{
if (err)
reject(err);
else
{
resolve([
res.keywords[0].sentiment.score,
res.keywords[1].sentiment.score
]);
}
});
});
}