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

Function main

cloud-language/analyze_entities_v2_text.js:17–53  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

15'use strict';
16
17async function main(text) {
18 async function analyzeEntitiesOfText() {
19 // [START language_entities_text]
20 // Imports the Google Cloud client library
21 const language = require('@google-cloud/language').v2;
22
23 // Creates a client
24 const client = new language.LanguageServiceClient();
25
26 /**
27 * TODO(developer): Uncomment the following line to run this code.
28 */
29 // const text = 'Your text to analyze, e.g. Hello, world!';
30
31 // Prepares a document, representing the provided text
32 const document = {
33 content: text,
34 type: 'PLAIN_TEXT',
35 };
36
37 // Detects entities in the document
38 const [result] = await client.analyzeEntities({document});
39
40 const entities = result.entities;
41
42 console.log('Entities:');
43 entities.forEach(entity => {
44 console.log(entity.name);
45 console.log(` - Type: ${entity.type}`);
46 if (entity.metadata) {
47 console.log(` - Metadata: ${entity.metadata}`);
48 }
49 });
50 // [END language_entities_text]
51 }
52 await analyzeEntitiesOfText();
53}
54
55main(...process.argv.slice(2)).catch(err => {
56 console.error(err);

Callers 1

Calls 1

analyzeEntitiesOfTextFunction · 0.70

Tested by

no test coverage detected