forked from watson-developer-cloud/node-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersonality_insights.v3.js
81 lines (75 loc) · 2.02 KB
/
personality_insights.v3.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
const PersonalityInsightsV3 = require('watson-developer-cloud/personality-insights/v3');
const fs = require('fs');
const personality_insights = new PersonalityInsightsV3({
username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE',
password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE',
version_date: '2016-10-19'
});
/*
* English example:
* 'text' parameter contains the input text.
*/
personality_insights.profile(
{
text: 'Enter more than 100 unique words here...',
consumption_preferences: true
},
function(err, response) {
if (err) {
console.log('error:', err);
} else {
console.log(JSON.stringify(response, null, 2));
}
}
);
/*
* Spanish example:
* 'language' parameter is needed in 'es' since our
* text content is in Spanish.
*/
personality_insights.profile(
{
text: 'Ingrese un texto de más de 100 palabras aquí...',
headers: { 'Content-Language': 'es' }
},
function(err, response) {
if (err) {
console.log('error:', err);
} else {
console.log(JSON.stringify(response, null, 2));
}
}
);
/*
* Requesting output in an specific language:
* Following the Spanish Example, now we would like to
* obtain the output in Spanish, i.e. all the trait
* names and output messages in Spanish. You can specify
* the expected language by passing 'accept_language'
* parameter with the locale.
*/
personality_insights.profile(
{
text: 'Ingrese un texto de más de 100 palabras aquí...',
headers: { 'Content-Language': 'es', 'Accept-Language': 'es' }
},
function(err, response) {
if (err) {
console.log('error:', err);
} else {
console.log(JSON.stringify(response, null, 2));
}
}
);
/*
* CSV output example:
* https://www.ibm.com/watson/developercloud/doc/personality-insights/output.shtml#outputCSV
*/
personality_insights
.profile({
text: 'Enter more than 100 unique words here...',
csv_headers: true,
headers: { Accept: 'text/csv' }
})
.pipe(fs.createWriteStream('./output.csv'));