Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function analyzeSyntaxOfText(text) {
// [START language_syntax_string]
// Imports the Google Cloud client library
const language = require('@google-cloud/language').v1beta2;
// Creates a v1beta2 client
const client = new language.LanguageServiceClient();
/**
* TODO(developer): Uncomment the following line to run this code.
*/
// const text = 'Your text to analyze, e.g. Hello, world!';
// Prepares a document, representing the provided text
const document = {
content: text,
type: 'PLAIN_TEXT',
};
// Detects syntax in the document
const [syntax] = await client.analyzeSyntax({document});
console.log('Parts of speech:');
async function analyzeSentimentOfText(text) {
// [START language_sentiment_string]
// Imports the Google Cloud client library
const language = require('@google-cloud/language').v1beta2;
// Creates a v1beta2 client
const client = new language.LanguageServiceClient();
/**
* TODO(developer): Uncomment the following line to run this code.
*/
// const text = 'Your text to analyze, e.g. Hello, world!';
// Prepares a document, representing the provided text
const document = {
content: text,
type: 'PLAIN_TEXT',
};
// Detects the sentiment of the document
const [result] = await client.analyzeSentiment({document});
const sentiment = result.documentSentiment;
console.log(`Document sentiment:`);
async function classifyTextInFile(bucketName, fileName) {
// [START language_classify_file]
// Imports the Google Cloud client library
const language = require('@google-cloud/language').v1beta2;
// Creates a v1beta2 client
const client = new language.LanguageServiceClient();
/**
* TODO(developer): Uncomment the following lines to run this code
*/
// const bucketName = 'Your bucket name, e.g. my-bucket';
// const fileName = 'Your file name, e.g. my-file.txt';
// Prepares a document, representing a text file in Cloud Storage
const document = {
gcsContentUri: `gs://${bucketName}/${fileName}`,
type: 'PLAIN_TEXT',
};
// Classifies text in the document
const [classification] = await client.classifyText({document});
console.log('Categories:');
async function classifyTextOfText(text) {
// [START language_classify_string]
// Imports the Google Cloud client library
const language = require('@google-cloud/language').v1beta2;
// Creates a v1beta2 client
const client = new language.LanguageServiceClient();
/**
* TODO(developer): Uncomment the following line to run this code.
*/
// const text = 'Your text to analyze, e.g. Hello, world!';
// Prepares a document, representing the provided text
const document = {
content: text,
type: 'PLAIN_TEXT',
};
// Classifies text in the document
const [classification] = await client.classifyText({document});
console.log('Categories:');
classification.categories.forEach(category => {
async function analyzeSentimentInFile(bucketName, fileName) {
// [START language_sentiment_file]
// Imports the Google Cloud client library
const language = require('@google-cloud/language').v1beta2;
// Creates a v1beta2 client
const client = new language.LanguageServiceClient();
/**
* TODO(developer): Uncomment the following lines to run this code
*/
// const bucketName = 'Your bucket name, e.g. my-bucket';
// const fileName = 'Your file name, e.g. my-file.txt';
// Prepares a document, representing a text file in Cloud Storage
const document = {
gcsContentUri: `gs://${bucketName}/${fileName}`,
type: 'PLAIN_TEXT',
};
// Detects the sentiment of the document
const [result] = await client.analyzeSentiment({document});
const sentiment = result.documentSentiment;
async function analyzeEntitiesInFile(bucketName, fileName) {
// [START language_entities_file]
// Imports the Google Cloud client library
const language = require('@google-cloud/language').v1beta2;
// Creates a v1beta2 client
const client = new language.LanguageServiceClient();
/**
* TODO(developer): Uncomment the following lines to run this code
*/
// const bucketName = 'Your bucket name, e.g. my-bucket';
// const fileName = 'Your file name, e.g. my-file.txt';
// Prepares a document, representing a text file in Cloud Storage
const document = {
gcsContentUri: `gs://${bucketName}/${fileName}`,
type: 'PLAIN_TEXT',
};
// Detects entities in the document
const [result] = await client.analyzeEntities({document});
const entities = result.entities;
async function analyzeSyntaxInFile(bucketName, fileName) {
// [START language_syntax_file]
// Imports the Google Cloud client library
const language = require('@google-cloud/language').v1beta2;
// Creates a v1beta2 client
const client = new language.LanguageServiceClient();
/**
* TODO(developer): Uncomment the following lines to run this code
*/
// const bucketName = 'Your bucket name, e.g. my-bucket';
// const fileName = 'Your file name, e.g. my-file.txt';
// Prepares a document, representing a text file in Cloud Storage
const document = {
gcsContentUri: `gs://${bucketName}/${fileName}`,
type: 'PLAIN_TEXT',
};
// Detects syntax in the document
const [syntax] = await client.analyzeSyntax({document});
async function analyzeEntitiesOfText(text) {
// [START language_entities_string]
// Imports the Google Cloud client library
const language = require('@google-cloud/language').v1beta2;
// Creates a v1beta2 client
const client = new language.LanguageServiceClient();
/**
* TODO(developer): Uncomment the following line to run this code.
*/
// const text = 'Your text to analyze, e.g. Hello, world!';
// Prepares a document, representing the provided text
const document = {
content: text,
type: 'PLAIN_TEXT',
};
// Detects entities in the document
const [result] = await client.analyzeEntities({document});
const entities = result.entities;