-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtry.js
37 lines (31 loc) · 1.13 KB
/
try.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
const NaturalLanguageUnderstandingV1 = require('ibm-watson/natural-language-understanding/v1');
const { IamAuthenticator } = require('ibm-watson/auth');
// https://cloud.ibm.com/apidocs/natural-language-understanding?code=node#features-examples
// this is from the official IBM tutorial
function bigFunction (text) {
const naturalLanguageUnderstanding = new NaturalLanguageUnderstandingV1({
version: '2022-04-07',
authenticator: new IamAuthenticator({
apikey: '_faoS8mAvH-l3VhkgBFElVvtxJRTbsuRUfrSbWGec549',
}),
serviceUrl: 'https://api.au-syd.natural-language-understanding.watson.cloud.ibm.com/instances/6f0caca6-4a6b-4260-8119-d2ea0633b9cb',
});
const analyzeParams = {
'text': text,
'features': {
'emotion': {
}
}
};
naturalLanguageUnderstanding.analyze(analyzeParams)
.then(analysisResults => {
console.log(JSON.stringify(analysisResults.result.emotion.document.emotion, null, 2));
})
.catch(err => {
console.log('error:', err);
});
}
texts = ['Hey, you are disgusting', 'You are amazing!!']
texts.forEach(text => {
bigFunction (text)
});