| 333 | } |
| 334 | |
| 335 | async 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 | |
| 365 | require('yargs') |
| 366 | .demand(1) |