-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalchemytest.js
55 lines (51 loc) · 1.69 KB
/
alchemytest.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 watson = require('watson-developer-cloud');
var alchemy_language = watson.alchemy_language({
api_key: '0d48b5ecfeb6b69c069f2ffd09287ec518c1d91c'
})
var headlines=['New York Today: An Ode to Opera',
'What Donald Trump Got Wrong on Stop-and-Frisk',
'1941: Van Gogh Painting Acquired',
'Caleb Carr’s New Thriller Takes On Fancy Forensics. Michael Connelly Reviews.',
'New York Today: Final Call for Voters',
'New York Today: Our Past in Pencils',
'New York Today: Mourning a Brooklyn Prosecutor',
'Showgirls, Pastrami and Candor: Gloria Steinem’s New York'
]
var bigbigString="New York Today: An Ode to Opera"+
"What Donald Trump Got Wrong on Stop-and-Frisk"+
"1941: Van Gogh Painting Acquired"+
"Caleb Carr’s New Thriller Takes On Fancy Forensics. Michael Connelly Reviews."+
"New York Today: Final Call for Voters"+
"New York Today: Our Past in Pencils"+
"New York Today: Mourning a Brooklyn Prosecutor"+
"Showgirls, Pastrami and Candor: Gloria Steinem’s New York"
var bigDataCenter={
anger:0.0,
disgust:0.0,
fear:0.0,
joy:0.0,
sadness:0.0
}
var parameters = {
text:bigbigString
};
for(i=0;i<headlines.length;i++){
alchemy_language.emotion(parameters, function (err, response) {
if (err)
console.log('error:', err);
else{
console.log(JSON.stringify(response, null, 2));
bigDataCenter.anger+=response.docEmotions.anger
bigDataCenter.disgust+=response.docEmotions.disgust
bigDataCenter.fear+=response.docEmotions.fear
bigDataCenter.joy+=response.docEmotions.joy
bigDataCenter.sadness+=response.docEmotions.sadness
}
});
}
//for calculating the averages
bigDataCenter.anger/=8
bigDataCenter.disgust/=8
bigDataCenter.fear/=8
bigDataCenter.joy/=8
bigDataCenter.sadness/=8