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

Function classifyTextOfText

cloud-language/analyze.v1.js:298–333  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

296}
297
298async function classifyTextOfText(text) {
299 // [START language_classify_text]
300 // Imports the Google Cloud client library
301 const language = require('@google-cloud/language');
302
303 // Creates a client
304 const client = new language.LanguageServiceClient();
305
306 /**
307 * TODO(developer): Uncomment the following line to run this code.
308 */
309 // const text = 'Your text to analyze, e.g. Hello, world!';
310
311 // Prepares a document, representing the provided text
312 const document = {
313 content: text,
314 type: 'PLAIN_TEXT',
315 };
316
317 const classificationModelOptions = {
318 v2Model: {
319 contentCategoriesVersion: 'V2',
320 },
321 };
322
323 // Classifies text in the document
324 const [classification] = await client.classifyText({
325 document,
326 classificationModelOptions,
327 });
328 console.log('Categories:');
329 classification.categories.forEach(category => {
330 console.log(`Name: ${category.name}, Confidence: ${category.confidence}`);
331 });
332 // [END language_classify_text]
333}
334
335async function classifyTextInFile(bucketName, fileName) {
336 // [START language_classify_gcs]

Callers 1

analyze.v1.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected