(text)
| 15 | 'use strict'; |
| 16 | |
| 17 | async function main(text) { |
| 18 | async function classifyTextOfText() { |
| 19 | // [START language_classify_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 | // Classifies text in the document |
| 38 | const [classification] = await client.classifyText({document}); |
| 39 | console.log('Categories:'); |
| 40 | classification.categories.forEach(category => { |
| 41 | console.log(`Name: ${category.name}, Confidence: ${category.confidence}`); |
| 42 | }); |
| 43 | // [END language_classify_text] |
| 44 | } |
| 45 | await classifyTextOfText(); |
| 46 | } |
| 47 | |
| 48 | main(...process.argv.slice(2)).catch(err => { |
| 49 | console.error(err); |
no test coverage detected