-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestApi2.js
42 lines (32 loc) · 1.1 KB
/
testApi2.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
// Imports the Google Cloud client library
const language = require(`@google-cloud/language`);
const beautify = require("json-beautify");
const chalk = require(`chalk`);
// 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`,
};
async function googleCloud(document) {
// Instantiates a client
const client = new language.LanguageServiceClient();
// hit all APIs at same time, don't proceed until all have responded
const [analyzeSentiment, analyzeEntities, analyzeSyntax, analyzeEntitySentiment] = await Promise.all([
client.analyzeSentiment({document: document}),
client.analyzeEntities({document: document}),
client.analyzeSyntax({document: document}),
client.analyzeEntitySentiment({document: document}),
]);
// load up an object with data from the APIs
let payload = {
analyzeSentiment,
analyzeEntities,
analyzeSyntax,
analyzeEntitySentiment
}
// make it pretty
print = beautify(payload, null, 2, 10);
console.log(print)
}
googleCloud(document);