forked from watson-developer-cloud/node-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersonality_insights.v2.js
68 lines (61 loc) · 1.82 KB
/
personality_insights.v2.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
'use strict';
var watson = require('watson-developer-cloud');
var fs = require('fs');
var personality_insights = watson.personality_insights({
username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE',
password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE',
version: 'v2'
});
/*
* English example:
* 'text' parameter contains the input text.
*/
personality_insights.profile({
text: 'Enter more than 100 unique words here...' },
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í...',
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í...',
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/smarterplanet/us/en/ibmwatson/developercloud/doc/personality-insights/output.shtml#outputCSV
*/
personality_insights.profile({
text: 'Enter more than 100 unique words here...',
csv: true,
csv_headers: true
}).pipe(fs.createWriteStream('./output.csv'));