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

Function classifyTextInFile

cloud-language/analyze.v1.js:335–363  ·  view source on GitHub ↗
(bucketName, fileName)

Source from the content-addressed store, hash-verified

333}
334
335async function classifyTextInFile(bucketName, fileName) {
336 // [START language_classify_gcs]
337 // Imports the Google Cloud client library.
338 const language = require('@google-cloud/language');
339
340 // Creates a client.
341 const client = new language.LanguageServiceClient();
342
343 /**
344 * TODO(developer): Uncomment the following lines to run this code
345 */
346 // const bucketName = 'Your bucket name, e.g. my-bucket';
347 // const fileName = 'Your file name, e.g. my-file.txt';
348
349 // Prepares a document, representing a text file in Cloud Storage
350 const document = {
351 gcsContentUri: `gs://${bucketName}/${fileName}`,
352 type: 'PLAIN_TEXT',
353 };
354
355 // Classifies text in the document
356 const [classification] = await client.classifyText({document});
357
358 console.log('Categories:');
359 classification.categories.forEach(category => {
360 console.log(`Name: ${category.name}, Confidence: ${category.confidence}`);
361 });
362 // [END language_classify_gcs]
363}
364
365require('yargs')
366 .demand(1)

Callers 1

analyze.v1.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected