MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / quickstart

Function quickstart

cloud-language/quickstart.js:18–40  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16
17// [START language_quickstart]
18async function quickstart() {
19 // Imports the Google Cloud client library
20 const language = require('@google-cloud/language');
21
22 // Instantiates a client
23 const client = new language.LanguageServiceClient();
24
25 // The text to analyze
26 const text = 'Hello, world!';
27
28 const document = {
29 content: text,
30 type: 'PLAIN_TEXT',
31 };
32
33 // Detects the sentiment of the text
34 const [result] = await client.analyzeSentiment({document: document});
35 const sentiment = result.documentSentiment;
36
37 console.log(`Text: ${text}`);
38 console.log(`Sentiment score: ${sentiment.score}`);
39 console.log(`Sentiment magnitude: ${sentiment.magnitude}`);
40}
41// [END language_quickstart]
42
43quickstart().catch(console.error);

Callers 1

quickstart.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected