-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestApi.js
81 lines (69 loc) · 2.01 KB
/
testApi.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
// Imports the Google Cloud client library
const language = require('@google-cloud/language');
const beautify = require("json-beautify");
const chalk = require('chalk');
const toolbox = require('./private/toolbox');
// The text to analyze
const text = "Hello, my name is Inigo Montoya. You killed my father. Prepare to die.";
const document = {
content: text,
type: 'PLAIN_TEXT',
};
googleCloud(document);
function googleCloud(document) {
// Instantiates a client
const client = new language.LanguageServiceClient();
// Detects the sentiment of the text
client.analyzeSentiment({document: document})
.then((result) => {
result = beautify(result, null, 2, 10);
logWhite('Analyze Sentiment:')
console.log(result);
})
.catch(error => {
toolbox.logError(error)
})
// Detects entities in the text
client.analyzeEntities({document: document})
.then((result) => {
result = beautify(result, null, 2, 10);
logWhite('Detect entities:')
console.log(result);
})
.catch(error => {
toolbox.logError(error)
})
// Analyze Syntax in the text
client.analyzeSyntax({document: document})
.then((result) => {
result = beautify(result, null, 2, 10);
logWhite('Analyze Syntax:')
console.log(result);
})
.catch(error => {
toolbox.logError(error)
})
// Analyze entity Sentiment in the text
client.analyzeEntitySentiment({document: document})
.then((result) => {
result = beautify(result, null, 2, 10);
logWhite('Analyze Entity Sentiment:')
console.log(result);
})
.catch(error => {
toolbox.logError(error)
})
// Classify text (needs to be a certian length......)
client.classifyText({document: document})
.then((result) => {
result = beautify(result, null, 2, 10);
logWhite('Classify text:')
console.log(result);
})
.catch(error => {
toolbox.logError(error)
})
}
function logWhite(log){
console.log(chalk.black.bold.bgWhite(log));
}