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

Function main

cloud-language/analyze_entities_v2_file.js:17–54  ·  view source on GitHub ↗
(bucketName, fileName)

Source from the content-addressed store, hash-verified

15'use strict';
16
17async function main(bucketName, fileName) {
18 async function analyzeEntitiesInFile() {
19 // [START language_entities_gcs]
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 lines to run this code
28 */
29 // const bucketName = 'Your bucket name, e.g. my-bucket';
30 // const fileName = 'Your file name, e.g. my-file.txt';
31
32 // Prepares a document, representing a text file in Cloud Storage
33 const document = {
34 gcsContentUri: `gs://${bucketName}/${fileName}`,
35 type: 'PLAIN_TEXT',
36 };
37
38 // Detects entities in the document
39 const [result] = await client.analyzeEntities({document});
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
51 // [END language_entities_gcs]
52 }
53 await analyzeEntitiesInFile();
54}
55
56main(...process.argv.slice(2)).catch(err => {
57 console.error(err);

Callers 1

Calls 1

analyzeEntitiesInFileFunction · 0.70

Tested by

no test coverage detected