From 4fc18a84270795a0c8277490277e5e959ea86cb6 Mon Sep 17 00:00:00 2001 From: Alex <7764119+AVaksman@users.noreply.github.com> Date: Thu, 2 Apr 2020 13:58:44 -0400 Subject: [PATCH] feat!: drop node8 support (#405) --- cloud-language/snippets/analyze.v1.js | 80 +++---- .../automl/automlNaturalLanguageDataset.js | 132 ++++++------ .../automl/automlNaturalLanguageModel.js | 204 +++++++++--------- .../automl/automlNaturalLanguagePredict.js | 52 ++--- .../snippets/test/analyze.v1.test.js | 6 +- .../test/automlNaturalLanguage.test.js | 4 +- 6 files changed, 239 insertions(+), 239 deletions(-) diff --git a/cloud-language/snippets/analyze.v1.js b/cloud-language/snippets/analyze.v1.js index afe9882f0e..162f190880 100644 --- a/cloud-language/snippets/analyze.v1.js +++ b/cloud-language/snippets/analyze.v1.js @@ -39,7 +39,7 @@ async function analyzeSentimentOfText(text) { const [result] = await client.analyzeSentiment({document}); const sentiment = result.documentSentiment; - console.log(`Document sentiment:`); + console.log('Document sentiment:'); console.log(` Score: ${sentiment.score}`); console.log(` Magnitude: ${sentiment.magnitude}`); @@ -77,7 +77,7 @@ async function analyzeSentimentInFile(bucketName, fileName) { const [result] = await client.analyzeSentiment({document}); const sentiment = result.documentSentiment; - console.log(`Document sentiment:`); + console.log('Document sentiment:'); console.log(` Score: ${sentiment.score}`); console.log(` Magnitude: ${sentiment.magnitude}`); @@ -189,7 +189,7 @@ async function analyzeSyntaxOfText(text) { console.log('Tokens:'); syntax.tokens.forEach(part => { console.log(`${part.partOfSpeech.tag}: ${part.text.content}`); - console.log(`Morphology:`, part.partOfSpeech); + console.log('Morphology:', part.partOfSpeech); }); // [END language_syntax_text] } @@ -223,7 +223,7 @@ async function analyzeSyntaxInFile(bucketName, fileName) { console.log('Parts of speech:'); syntax.tokens.forEach(part => { console.log(`${part.partOfSpeech.tag}: ${part.text.content}`); - console.log(`Morphology:`, part.partOfSpeech); + console.log('Morphology:', part.partOfSpeech); }); // [END language_syntax_gcs] } @@ -251,7 +251,7 @@ async function analyzeEntitySentimentOfText(text) { const [result] = await client.analyzeEntitySentiment({document}); const entities = result.entities; - console.log(`Entities and sentiments:`); + console.log('Entities and sentiments:'); entities.forEach(entity => { console.log(` Name: ${entity.name}`); console.log(` Type: ${entity.type}`); @@ -285,7 +285,7 @@ async function analyzeEntitySentimentInFile(bucketName, fileName) { const [result] = await client.analyzeEntitySentiment({document}); const entities = result.entities; - console.log(`Entities and sentiments:`); + console.log('Entities and sentiments:'); entities.forEach(entity => { console.log(` Name: ${entity.name}`); console.log(` Type: ${entity.type}`); @@ -353,98 +353,98 @@ async function classifyTextInFile(bucketName, fileName) { // [END language_classify_gcs] } -require(`yargs`) +require('yargs') .demand(1) .command( - `sentiment-text `, - `Detects sentiment of a string.`, + 'sentiment-text ', + 'Detects sentiment of a string.', {}, opts => analyzeSentimentOfText(opts.text) ) .command( - `sentiment-file `, - `Detects sentiment in a file in Google Cloud Storage.`, + 'sentiment-file ', + 'Detects sentiment in a file in Google Cloud Storage.', {}, opts => analyzeSentimentInFile(opts.bucketName, opts.fileName) ) - .command(`entities-text `, `Detects entities in a string.`, {}, opts => + .command('entities-text ', 'Detects entities in a string.', {}, opts => analyzeEntitiesOfText(opts.text) ) .command( - `entities-file `, - `Detects entities in a file in Google Cloud Storage.`, + 'entities-file ', + 'Detects entities in a file in Google Cloud Storage.', {}, opts => analyzeEntitiesInFile(opts.bucketName, opts.fileName) ) - .command(`syntax-text `, `Detects syntax of a string.`, {}, opts => + .command('syntax-text ', 'Detects syntax of a string.', {}, opts => analyzeSyntaxOfText(opts.text) ) .command( - `syntax-file `, - `Detects syntax in a file in Google Cloud Storage.`, + 'syntax-file ', + 'Detects syntax in a file in Google Cloud Storage.', {}, opts => analyzeSyntaxInFile(opts.bucketName, opts.fileName) ) .command( - `entity-sentiment-text `, - `Detects sentiment of the entities in a string.`, + 'entity-sentiment-text ', + 'Detects sentiment of the entities in a string.', {}, opts => analyzeEntitySentimentOfText(opts.text) ) .command( - `entity-sentiment-file `, - `Detects sentiment of the entities in a file in Google Cloud Storage.`, + 'entity-sentiment-file ', + 'Detects sentiment of the entities in a file in Google Cloud Storage.', {}, opts => analyzeEntitySentimentInFile(opts.bucketName, opts.fileName) ) - .command(`classify-text `, `Classifies text of a string.`, {}, opts => + .command('classify-text ', 'Classifies text of a string.', {}, opts => classifyTextOfText(opts.text) ) .command( - `classify-file `, - `Classifies text in a file in Google Cloud Storage.`, + 'classify-file ', + 'Classifies text in a file in Google Cloud Storage.', {}, opts => classifyTextInFile(opts.bucketName, opts.fileName) ) .example( - `node $0 sentiment-text "President Obama is speaking at the White House."` + 'node $0 sentiment-text "President Obama is speaking at the White House."' ) .example( - `node $0 sentiment-file my-bucket file.txt`, - `Detects sentiment in gs://my-bucket/file.txt` + 'node $0 sentiment-file my-bucket file.txt', + 'Detects sentiment in gs://my-bucket/file.txt' ) .example( - `node $0 entities-text "President Obama is speaking at the White House."` + 'node $0 entities-text "President Obama is speaking at the White House."' ) .example( - `node $0 entities-file my-bucket file.txt`, - `Detects entities in gs://my-bucket/file.txt` + 'node $0 entities-file my-bucket file.txt', + 'Detects entities in gs://my-bucket/file.txt' ) .example( - `node $0 syntax-text "President Obama is speaking at the White House."` + 'node $0 syntax-text "President Obama is speaking at the White House."' ) .example( - `node $0 syntax-file my-bucket file.txt`, - `Detects syntax in gs://my-bucket/file.txt` + 'node $0 syntax-file my-bucket file.txt', + 'Detects syntax in gs://my-bucket/file.txt' ) .example( - `node $0 entity-sentiment-text "President Obama is speaking at the White House."` + 'node $0 entity-sentiment-text "President Obama is speaking at the White House."' ) .example( - `node $0 entity-sentiment-file my-bucket file.txt`, - `Detects sentiment of entities in gs://my-bucket/file.txt` + 'node $0 entity-sentiment-file my-bucket file.txt', + 'Detects sentiment of entities in gs://my-bucket/file.txt' ) .example( - `node $0 classify-text "Android is a mobile operating system developed by Google, based on the Linux kernel and designed primarily for touchscreen mobile devices such as smartphones and tablets."` + 'node $0 classify-text "Android is a mobile operating system developed by Google, based on the Linux kernel and designed primarily for touchscreen mobile devices such as smartphones and tablets."' ) .example( - `node $0 classify-file my-bucket android_text.txt`, - `Detects syntax in gs://my-bucket/android_text.txt` + 'node $0 classify-file my-bucket android_text.txt', + 'Detects syntax in gs://my-bucket/android_text.txt' ) .wrap(120) .recommendCommands() .epilogue( - `For more information, see https://cloud.google.com/natural-language/docs` + 'For more information, see https://cloud.google.com/natural-language/docs' ) .help() .strict().argv; diff --git a/cloud-language/snippets/automl/automlNaturalLanguageDataset.js b/cloud-language/snippets/automl/automlNaturalLanguageDataset.js index 9ddedc7b7e..c6c584a07d 100755 --- a/cloud-language/snippets/automl/automlNaturalLanguageDataset.js +++ b/cloud-language/snippets/automl/automlNaturalLanguageDataset.js @@ -29,7 +29,7 @@ async function createDataset( multilabel ) { // [START automl_language_createDataset] - const automl = require(`@google-cloud/automl`); + const automl = require('@google-cloud/automl'); const client = new automl.v1beta1.AutoMlClient(); @@ -45,9 +45,9 @@ async function createDataset( const projectLocation = client.locationPath(projectId, computeRegion); // Classification type is assigned based on multilabel value. - let classificationType = `MULTICLASS`; + let classificationType = 'MULTICLASS'; if (multilabel) { - classificationType = `MULTILABEL`; + classificationType = 'MULTILABEL'; } // Set dataset name and metadata. @@ -65,14 +65,14 @@ async function createDataset( }); // Display the dataset information. console.log(`Dataset name: ${dataset.name}`); - console.log(`Dataset id: ${dataset.name.split(`/`).pop(-1)}`); + console.log(`Dataset id: ${dataset.name.split('/').pop(-1)}`); console.log(`Dataset display name: ${dataset.displayName}`); console.log(`Dataset example count: ${dataset.exampleCount}`); - console.log(`Text classification type:`); + console.log('Text classification type:'); console.log( `\t ${dataset.textClassificationDatasetMetadata.classificationType}` ); - console.log(`Dataset create time:`); + console.log('Dataset create time:'); console.log(`\tseconds: ${dataset.createTime.seconds}`); console.log(`\tnanos: ${dataset.createTime.nanos}`); // [END automl_language_createDataset] @@ -80,7 +80,7 @@ async function createDataset( async function listDatasets(projectId, computeRegion, filter) { // [START automl_language_listDatasets] - const automl = require(`@google-cloud/automl`); + const automl = require('@google-cloud/automl'); const client = new automl.v1beta1.AutoMlClient(); @@ -100,27 +100,27 @@ async function listDatasets(projectId, computeRegion, filter) { filter: filter, }); // Display the dataset information. - console.log(`List of datasets:`); + console.log('List of datasets:'); datasets.forEach(dataset => { console.log(`Dataset name: ${dataset.name}`); - console.log(`Dataset id: ${dataset.name.split(`/`).pop(-1)}`); + console.log(`Dataset id: ${dataset.name.split('/').pop(-1)}`); console.log(`Dataset display name: ${dataset.displayName}`); console.log(`Dataset example count: ${dataset.exampleCount}`); - console.log(`Text classification type:`); + console.log('Text classification type:'); console.log( `\t ${dataset.textClassificationDatasetMetadata.classificationType}` ); - console.log(`Dataset create time: `); + console.log('Dataset create time: '); console.log(`\tseconds: ${dataset.createTime.seconds}`); console.log(`\tnanos: ${dataset.createTime.nanos}`); - console.log(`\n`); + console.log('\n'); }); // [END automl_language_listDatasets] } async function getDataset(projectId, computeRegion, datasetId) { // [START automl_language_getDataset] - const automl = require(`@google-cloud/automl`); + const automl = require('@google-cloud/automl'); const client = new automl.v1beta1.AutoMlClient(); @@ -138,13 +138,13 @@ async function getDataset(projectId, computeRegion, datasetId) { const [dataset] = await client.getDataset({name: datasetFullId}); // Display the dataset information. console.log(`Dataset name: ${dataset.name}`); - console.log(`Dataset id: ${dataset.name.split(`/`).pop(-1)}`); + console.log(`Dataset id: ${dataset.name.split('/').pop(-1)}`); console.log(`Dataset display name: ${dataset.displayName}`); console.log(`Dataset example count: ${dataset.exampleCount}`); console.log( `Text classification type: ${dataset.textClassificationDatasetMetadata.classificationType}` ); - console.log(`Dataset create time: `); + console.log('Dataset create time: '); console.log(`\tseconds: ${dataset.createTime.seconds}`); console.log(`\tnanos: ${dataset.createTime.nanos}`); // [END automl_language_getDataset] @@ -152,7 +152,7 @@ async function getDataset(projectId, computeRegion, datasetId) { async function importData(projectId, computeRegion, datasetId, path) { // [START automl_language_importDataset] - const automl = require(`@google-cloud/automl`); + const automl = require('@google-cloud/automl'); const client = new automl.v1beta1.AutoMlClient(); @@ -168,7 +168,7 @@ async function importData(projectId, computeRegion, datasetId, path) { const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId); // Get the multiple Google Cloud Storage URIs. - const inputUris = path.split(`,`); + const inputUris = path.split(','); const inputConfig = { gcsSource: { inputUris: inputUris, @@ -180,17 +180,17 @@ async function importData(projectId, computeRegion, datasetId, path) { name: datasetFullId, inputConfig: inputConfig, }); - console.log(`Processing import...`); + console.log('Processing import...'); const response = await operation.promise(); // The final result of the operation. - if (response[2].done === true) console.log(`Data imported.`); + if (response[2].done === true) console.log('Data imported.'); // [END automl_language_importDataset] } async function exportData(projectId, computeRegion, datasetId, outputUri) { // [START automl_language_exportDataset] - const automl = require(`@google-cloud/automl`); + const automl = require('@google-cloud/automl'); const client = new automl.v1beta1.AutoMlClient(); @@ -217,16 +217,16 @@ async function exportData(projectId, computeRegion, datasetId, outputUri) { name: datasetFullId, outputConfig: outputConfig, }); - console.log(`Processing export...`); + console.log('Processing export...'); const response = await operation.promise(); // The final result of the operation. - if (response[2].done === true) console.log(`Data exported.`); + if (response[2].done === true) console.log('Data exported.'); // [END automl_language_exportDataset] } async function deleteDataset(projectId, computeRegion, datasetId) { // [START automl_language_deleteDataset] - const automl = require(`@google-cloud/automl`); + const automl = require('@google-cloud/automl'); const client = new automl.v1beta1.AutoMlClient(); @@ -244,72 +244,72 @@ async function deleteDataset(projectId, computeRegion, datasetId) { const [operation] = await client.deleteDataset({name: datasetFullId}); const response = await operation.promise(); // The final result of the operation. - if (response[2].done === true) console.log(`Dataset deleted.`); + if (response[2].done === true) console.log('Dataset deleted.'); // [END automl_language_deleteDataset] } -require(`yargs`) +require('yargs') .demand(1) .options({ computeRegion: { - alias: `c`, - type: `string`, + alias: 'c', + type: 'string', default: process.env.REGION_NAME, requiresArg: true, - description: `region name e.g. "us-central1"`, + description: 'region name e.g. "us-central1"', }, datasetName: { - alias: `n`, - type: `string`, - default: `testDataSet`, + alias: 'n', + type: 'string', + default: 'testDataSet', requiresArg: true, - description: `Name of the Dataset`, + description: 'Name of the Dataset', }, datasetId: { - alias: `i`, - type: `string`, + alias: 'i', + type: 'string', requiresArg: true, - description: `Id of the dataset`, + description: 'Id of the dataset', }, filter: { - alias: `f`, - default: `text_classification_dataset_metadata:*`, - type: `string`, + alias: 'f', + default: 'text_classification_dataset_metadata:*', + type: 'string', requiresArg: false, - description: `filter expression`, + description: 'filter expression', }, multilabel: { - alias: `m`, - type: `string`, + alias: 'm', + type: 'string', default: false, requiresArg: true, description: - `Type of the classification problem, ` + - `False - MULTICLASS, True - MULTILABEL.`, + 'Type of the classification problem, ' + + 'False - MULTICLASS, True - MULTILABEL.', }, outputUri: { - alias: `o`, - type: `string`, + alias: 'o', + type: 'string', requiresArg: true, - description: `URI (or local path) to export dataset`, + description: 'URI (or local path) to export dataset', }, path: { - alias: `p`, - type: `string`, + alias: 'p', + type: 'string', global: true, - default: `gs://nodejs-docs-samples-vcm/flowerTraindataMini.csv`, + default: 'gs://nodejs-docs-samples-vcm/flowerTraindataMini.csv', requiresArg: true, - description: `URI or local path to input .csv, or array of .csv paths`, + description: 'URI or local path to input .csv, or array of .csv paths', }, projectId: { - alias: `z`, - type: `number`, + alias: 'z', + type: 'number', default: process.env.GCLOUD_PROJECT, requiresArg: true, - description: `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`, + description: 'The GCLOUD_PROJECT string, e.g. "my-gcloud-project"', }, }) - .command(`create-dataset`, `creates a new Dataset`, {}, opts => + .command('create-dataset', 'creates a new Dataset', {}, opts => createDataset( opts.projectId, opts.computeRegion, @@ -317,21 +317,21 @@ require(`yargs`) opts.multilabel ) ) - .command(`list-datasets`, `list all Datasets`, {}, opts => + .command('list-datasets', 'list all Datasets', {}, opts => listDatasets(opts.projectId, opts.computeRegion, opts.filter) ) - .command(`get-dataset`, `Get a Dataset`, {}, opts => + .command('get-dataset', 'Get a Dataset', {}, opts => getDataset(opts.projectId, opts.computeRegion, opts.datasetId) ) - .command(`delete-dataset`, `Delete a dataset`, {}, opts => + .command('delete-dataset', 'Delete a dataset', {}, opts => deleteDataset(opts.projectId, opts.computeRegion, opts.datasetId) ) - .command(`import-data`, `Import labeled items into dataset`, {}, opts => + .command('import-data', 'Import labeled items into dataset', {}, opts => importData(opts.projectId, opts.computeRegion, opts.datasetId, opts.path) ) .command( - `export-data`, - `Export a dataset to a Google Cloud Storage Bucket`, + 'export-data', + 'Export a dataset to a Google Cloud Storage Bucket', {}, opts => exportData( @@ -341,15 +341,15 @@ require(`yargs`) opts.outputUri ) ) - .example(`node $0 create-dataset -n "newDataSet"`) - .example(`node $0 list-datasets -f "imageClassificationDatasetMetadata:*"`) - .example(`node $0 get-dataset -i "DATASETID"`) - .example(`node $0 delete-dataset -i "DATASETID"`) + .example('node $0 create-dataset -n "newDataSet"') + .example('node $0 list-datasets -f "imageClassificationDatasetMetadata:*"') + .example('node $0 get-dataset -i "DATASETID"') + .example('node $0 delete-dataset -i "DATASETID"') .example( - `node $0 import-data -i "dataSetId" -p "gs://myproject/mytraindata.csv"` + 'node $0 import-data -i "dataSetId" -p "gs://myproject/mytraindata.csv"' ) .example( - `node $0 export-data -i "dataSetId" -o "gs://myproject/outputdestination.csv"` + 'node $0 export-data -i "dataSetId" -o "gs://myproject/outputdestination.csv"' ) .wrap(120) .recommendCommands() diff --git a/cloud-language/snippets/automl/automlNaturalLanguageModel.js b/cloud-language/snippets/automl/automlNaturalLanguageModel.js index f75d57c06e..6702dc3840 100755 --- a/cloud-language/snippets/automl/automlNaturalLanguageModel.js +++ b/cloud-language/snippets/automl/automlNaturalLanguageModel.js @@ -24,7 +24,7 @@ async function createModel(projectId, computeRegion, datasetId, modelName) { // [START automl_language_createModel] - const automl = require(`@google-cloud/automl`); + const automl = require('@google-cloud/automl'); const client = new automl.v1beta1.AutoMlClient(); @@ -52,21 +52,21 @@ async function createModel(projectId, computeRegion, datasetId, modelName) { model: myModel, }); console.log(`Training operation name: ${initialApiResponse.name}`); - console.log(`Training started...`); + console.log('Training started...'); const [model] = await operation.promise(); // Retrieve deployment state. - let deploymentState = ``; + let deploymentState = ''; if (model.deploymentState === 1) { - deploymentState = `deployed`; + deploymentState = 'deployed'; } else if (model.deploymentState === 2) { - deploymentState = `undeployed`; + deploymentState = 'undeployed'; } // Display the model information. console.log(`Model name: ${model.name}`); - console.log(`Model id: ${model.name.split(`/`).pop(-1)}`); + console.log(`Model id: ${model.name.split('/').pop(-1)}`); console.log(`Model display name: ${model.displayName}`); - console.log(`Model create time:`); + console.log('Model create time:'); console.log(`\tseconds: ${model.createTime.seconds}`); console.log(`\tnanos: ${model.createTime.nanos}`); console.log(`Model deployment state: ${deploymentState}`); @@ -75,7 +75,7 @@ async function createModel(projectId, computeRegion, datasetId, modelName) { async function getOperationStatus(operationFullId) { // [START automl_language_getOperationStatus] - const automl = require(`@google-cloud/automl`); + const automl = require('@google-cloud/automl'); const client = new automl.v1beta1.AutoMlClient(); @@ -95,7 +95,7 @@ async function getOperationStatus(operationFullId) { async function listModels(projectId, computeRegion, filter) { // [START automl_language_listModels] - const automl = require(`@google-cloud/automl`); + const automl = require('@google-cloud/automl'); const client = new automl.v1beta1.AutoMlClient(); @@ -110,21 +110,21 @@ async function listModels(projectId, computeRegion, filter) { const projectLocation = client.locationPath(projectId, computeRegion); // List all the models available in the region by applying filter. - if (filter === ``) filter = `textClassificationModelMetadata:*`; + if (filter === '') filter = 'textClassificationModelMetadata:*'; const [models] = await client.listModels({ parent: projectLocation, filter: filter, }); // Display the model information. - console.log(`List of models:`); + console.log('List of models:'); models.forEach(model => { console.log(`Model name: ${model.name}`); - console.log(`Model id: ${model.name.split(`/`).pop(-1)}`); + console.log(`Model id: ${model.name.split('/').pop(-1)}`); console.log(`Model display name: ${model.displayName}`); console.log(`Model dataset id: ${model.datasetId}`); - if (model.modelMetadata === `translationModelMetadata`) { - console.log(`Translation model metadata:`); + if (model.modelMetadata === 'translationModelMetadata') { + console.log('Translation model metadata:'); console.log(`\tBase model: ${model.translationModelMetadata.baseModel}`); console.log( `\tSource language code: ${model.translationModelMetadata.sourceLanguageCode}` @@ -132,12 +132,12 @@ async function listModels(projectId, computeRegion, filter) { console.log( `\tTarget language code: ${model.translationModelMetadata.targetLanguageCode}` ); - } else if (model.modelMetadata === `textClassificationModelMetadata`) { + } else if (model.modelMetadata === 'textClassificationModelMetadata') { console.log( `Text classification model metadata: ${model.textClassificationModelMetadata}` ); - } else if (model.modelMetadata === `imageClassificationModelMetadata`) { - console.log(`Image classification model metadata:`); + } else if (model.modelMetadata === 'imageClassificationModelMetadata') { + console.log('Image classification model metadata:'); console.log( `\tBase model id: ${model.imageClassificationModelMetadata.baseModelId}` ); @@ -151,21 +151,21 @@ async function listModels(projectId, computeRegion, filter) { `\tStop reason: ${model.imageClassificationModelMetadata.stopReason}` ); } - console.log(`Model create time:`); + console.log('Model create time:'); console.log(`\tseconds: ${model.createTime.seconds}`); console.log(`\tnanos: ${model.createTime.nanos}`); - console.log(`Model update time:`); + console.log('Model update time:'); console.log(`\tseconds: ${model.updateTime.seconds}`); console.log(`\tnanos: ${model.updateTime.nanos}`); console.log(`Model deployment state: ${model.deploymentState}`); - console.log(`\n`); + console.log('\n'); }); // [END automl_language_listModels] } async function getModel(projectId, computeRegion, modelId) { // [START automl_language_getModel] - const automl = require(`@google-cloud/automl`); + const automl = require('@google-cloud/automl'); const client = new automl.v1beta1.AutoMlClient(); @@ -184,11 +184,11 @@ async function getModel(projectId, computeRegion, modelId) { // Display the model information. console.log(`Model name: ${model.name}`); - console.log(`Model id: ${model.name.split(`/`).pop(-1)}`); + console.log(`Model id: ${model.name.split('/').pop(-1)}`); console.log(`Model display name: ${model.displayName}`); console.log(`Model dataset id: ${model.datasetId}`); - if (model.modelMetadata === `translationModelMetadata`) { - console.log(`Translation model metadata:`); + if (model.modelMetadata === 'translationModelMetadata') { + console.log('Translation model metadata:'); console.log(`\tBase model: ${model.translationModelMetadata.baseModel}`); console.log( `\tSource language code: ${model.translationModelMetadata.sourceLanguageCode}` @@ -196,12 +196,12 @@ async function getModel(projectId, computeRegion, modelId) { console.log( `\tTarget language code: ${model.translationModelMetadata.targetLanguageCode}` ); - } else if (model.modelMetadata === `textClassificationModelMetadata`) { + } else if (model.modelMetadata === 'textClassificationModelMetadata') { console.log( `Text classification model metadata: ${model.textClassificationModelMetadata}` ); - } else if (model.modelMetadata === `imageClassificationModelMetadata`) { - console.log(`Image classification model metadata:`); + } else if (model.modelMetadata === 'imageClassificationModelMetadata') { + console.log('Image classification model metadata:'); console.log( `\tBase model id: ${model.imageClassificationModelMetadata.baseModelId}` ); @@ -215,10 +215,10 @@ async function getModel(projectId, computeRegion, modelId) { `\tStop reason: ${model.imageClassificationModelMetadata.stopReason}` ); } - console.log(`Model create time:`); + console.log('Model create time:'); console.log(`\tseconds: ${model.createTime.seconds}`); console.log(`\tnanos: ${model.createTime.nanos}`); - console.log(`Model update time:`); + console.log('Model update time:'); console.log(`\tseconds: ${model.updateTime.seconds}`); console.log(`\tnanos: ${model.updateTime.nanos}`); console.log(`Model deployment state: ${model.deploymentState}`); @@ -232,8 +232,8 @@ async function listModelEvaluations( filter_ ) { // [START automl_language_listModelEvaluations] - const automl = require(`@google-cloud/automl`); - const util = require(`util`); + const automl = require('@google-cloud/automl'); + const util = require('util'); const client = new automl.v1beta1.AutoMlClient(); @@ -253,7 +253,7 @@ async function listModelEvaluations( parent: modelFullId, filter: filter_, }); - console.log(`List of model evaluations:`); + console.log('List of model evaluations:'); elements.forEach(element => { console.log(util.inspect(element, false, null)); }); @@ -268,8 +268,8 @@ async function getModelEvaluation( modelEvaluationId ) { // [START automl_language_getModelEvaluation] - const automl = require(`@google-cloud/automl`); - const util = require(`util`); + const automl = require('@google-cloud/automl'); + const util = require('util'); const client = new automl.v1beta1.AutoMlClient(); @@ -299,8 +299,8 @@ async function getModelEvaluation( async function displayEvaluation(projectId, computeRegion, modelId, filter) { // [START automl_language_displayEvaluation] - const automl = require(`@google-cloud/automl`); - const math = require(`mathjs`); + const automl = require('@google-cloud/automl'); + const math = require('mathjs'); const client = new automl.v1beta1.AutoMlClient(); @@ -324,7 +324,7 @@ async function displayEvaluation(projectId, computeRegion, modelId, filter) { // There is evaluation for each class in a model and for overall model. // Get only the evaluation of overall model. if (!element.annotationSpecId) { - const modelEvaluationId = element.name.split(`/`).pop(-1); + const modelEvaluationId = element.name.split('/').pop(-1); // Resource name for the model evaluation. const modelEvaluationFullId = client.modelEvaluationPath( @@ -348,31 +348,31 @@ async function displayEvaluation(projectId, computeRegion, modelId, filter) { confidenceMetricsEntries.forEach(confidenceMetricsEntry => { if (confidenceMetricsEntry.confidenceThreshold === 0.5) { console.log( - `Precision and recall are based on a score threshold of 0.5` + 'Precision and recall are based on a score threshold of 0.5' ); console.log( - `Model Precision: `, - math.round(confidenceMetricsEntry.precision * 100, 2) + `%` + 'Model Precision: ', + math.round(confidenceMetricsEntry.precision * 100, 2) + '%' ); console.log( - `Model Recall: `, - math.round(confidenceMetricsEntry.recall * 100, 2) + `%` + 'Model Recall: ', + math.round(confidenceMetricsEntry.recall * 100, 2) + '%' ); console.log( - `Model F1 score: `, - math.round(confidenceMetricsEntry.f1Score * 100, 2) + `%` + 'Model F1 score: ', + math.round(confidenceMetricsEntry.f1Score * 100, 2) + '%' ); console.log( - `Model Precision@1: `, - math.round(confidenceMetricsEntry.precisionAt1 * 100, 2) + `%` + 'Model Precision@1: ', + math.round(confidenceMetricsEntry.precisionAt1 * 100, 2) + '%' ); console.log( - `Model Recall@1: `, - math.round(confidenceMetricsEntry.recallAt1 * 100, 2) + `%` + 'Model Recall@1: ', + math.round(confidenceMetricsEntry.recallAt1 * 100, 2) + '%' ); console.log( - `Model F1 score@1: `, - math.round(confidenceMetricsEntry.f1ScoreAt1 * 100, 2) + `%` + 'Model F1 score@1: ', + math.round(confidenceMetricsEntry.f1ScoreAt1 * 100, 2) + '%' ); } }); @@ -383,7 +383,7 @@ async function displayEvaluation(projectId, computeRegion, modelId, filter) { async function deleteModel(projectId, computeRegion, modelId) { // [START automl_language_deleteModel] - const automl = require(`@google-cloud/automl`); + const automl = require('@google-cloud/automl'); const client = new automl.v1beta1.AutoMlClient(); @@ -401,78 +401,78 @@ async function deleteModel(projectId, computeRegion, modelId) { const [operation] = client.deleteModel({name: modelFullId}); const response = await operation.promise(); // The final result of the operation. - if (response[2].done === true) console.log(`Model deleted.`); + if (response[2].done === true) console.log('Model deleted.'); // [END automl_language_deleteModel] } -require(`yargs`) +require('yargs') .demand(1) .options({ computeRegion: { - alias: `c`, - type: `string`, + alias: 'c', + type: 'string', default: process.env.REGION_NAME, requiresArg: true, - description: `region name e.g. "us-central1"`, + description: 'region name e.g. "us-central1"', }, datasetId: { - alias: `i`, - type: `string`, + alias: 'i', + type: 'string', requiresArg: true, - description: `Id of the dataset`, + description: 'Id of the dataset', }, filter: { - alias: `f`, - default: ``, - type: `string`, + alias: 'f', + default: '', + type: 'string', requiresArg: true, - description: `Name of the Dataset to search for`, + description: 'Name of the Dataset to search for', }, modelName: { - alias: `m`, - type: `string`, + alias: 'm', + type: 'string', default: false, requiresArg: true, - description: `Name of the model`, + description: 'Name of the model', }, modelId: { - alias: `a`, - type: `string`, - default: ``, + alias: 'a', + type: 'string', + default: '', requiresArg: true, - description: `Id of the model`, + description: 'Id of the model', }, modelEvaluationId: { - alias: `e`, - type: `string`, - default: ``, + alias: 'e', + type: 'string', + default: '', requiresArg: true, - description: `Id of the model evaluation`, + description: 'Id of the model evaluation', }, operationFullId: { - alias: `o`, - type: `string`, - default: ``, + alias: 'o', + type: 'string', + default: '', requiresArg: true, - description: `Full name of an operation`, + description: 'Full name of an operation', }, projectId: { - alias: `z`, - type: `number`, + alias: 'z', + type: 'number', default: process.env.GCLOUD_PROJECT, requiresArg: true, - description: `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`, + description: 'The GCLOUD_PROJECT string, e.g. "my-gcloud-project"', }, trainBudget: { - alias: `t`, - type: `string`, - default: ``, + alias: 't', + type: 'string', + default: '', requiresArg: true, - description: `Budget for training the model`, + description: 'Budget for training the model', }, }) - .command(`create-model`, `creates a new Model`, {}, opts => + .command('create-model', 'creates a new Model', {}, opts => createModel( opts.projectId, opts.computeRegion, @@ -482,18 +482,18 @@ require(`yargs`) ) ) .command( - `get-operation-status`, - `Gets status of current operation`, + 'get-operation-status', + 'Gets status of current operation', {}, opts => getOperationStatus(opts.operationFullId) ) - .command(`list-models`, `list all Models`, {}, opts => + .command('list-models', 'list all Models', {}, opts => listModels(opts.projectId, opts.computeRegion, opts.filter) ) - .command(`get-model`, `Get a Model`, {}, opts => + .command('get-model', 'Get a Model', {}, opts => getModel(opts.projectId, opts.computeRegion, opts.modelId) ) - .command(`list-model-evaluations`, `List model evaluations`, {}, opts => + .command('list-model-evaluations', 'List model evaluations', {}, opts => listModelEvaluations( opts.projectId, opts.computeRegion, @@ -501,7 +501,7 @@ require(`yargs`) opts.filter ) ) - .command(`get-model-evaluation`, `Get model evaluation`, {}, opts => + .command('get-model-evaluation', 'Get model evaluation', {}, opts => getModelEvaluation( opts.projectId, opts.computeRegion, @@ -509,7 +509,7 @@ require(`yargs`) opts.modelEvaluationId ) ) - .command(`display-evaluation`, `Display evaluation`, {}, opts => + .command('display-evaluation', 'Display evaluation', {}, opts => displayEvaluation( opts.projectId, opts.computeRegion, @@ -517,17 +517,17 @@ require(`yargs`) opts.filter ) ) - .command(`delete-model`, `Delete a Model`, {}, opts => + .command('delete-model', 'Delete a Model', {}, opts => deleteModel(opts.projectId, opts.computeRegion, opts.modelId) ) - .example(`node $0 create-model -i "DatasetID" -m "myModelName" -t "2"`) - .example(`node $0 get-operation-status -i "datasetId" -o "OperationFullID"`) - .example(`node $0 list-models -f "textClassificationModelMetadata:*"`) - .example(`node $0 get-model -a "ModelID"`) - .example(`node $0 list-model-evaluations -a "ModelID"`) - .example(`node $0 get-model-evaluation -a "ModelId" -e "ModelEvaluationID"`) - .example(`node $0 display-evaluation -a "ModelId"`) - .example(`node $0 delete-model -a "ModelID"`) + .example('node $0 create-model -i "DatasetID" -m "myModelName" -t "2"') + .example('node $0 get-operation-status -i "datasetId" -o "OperationFullID"') + .example('node $0 list-models -f "textClassificationModelMetadata:*"') + .example('node $0 get-model -a "ModelID"') + .example('node $0 list-model-evaluations -a "ModelID"') + .example('node $0 get-model-evaluation -a "ModelId" -e "ModelEvaluationID"') + .example('node $0 display-evaluation -a "ModelId"') + .example('node $0 delete-model -a "ModelID"') .wrap(120) .recommendCommands() .help() diff --git a/cloud-language/snippets/automl/automlNaturalLanguagePredict.js b/cloud-language/snippets/automl/automlNaturalLanguagePredict.js index 41cfc0a144..535899ec15 100755 --- a/cloud-language/snippets/automl/automlNaturalLanguagePredict.js +++ b/cloud-language/snippets/automl/automlNaturalLanguagePredict.js @@ -24,8 +24,8 @@ async function predict(projectId, computeRegion, modelId, filePath) { // [START automl_language_predict] - const automl = require(`@google-cloud/automl`); - const fs = require(`fs`); + const automl = require('@google-cloud/automl'); + const fs = require('fs'); // Create client for prediction service. const client = new automl.v1beta1.PredictionServiceClient(); @@ -42,13 +42,13 @@ async function predict(projectId, computeRegion, modelId, filePath) { const modelFullId = client.modelPath(projectId, computeRegion, modelId); // Read the file content for prediction. - const snippet = fs.readFileSync(filePath, `utf8`); + const snippet = fs.readFileSync(filePath, 'utf8'); // Set the payload by giving the content and type of the file. const payload = { textSnippet: { content: snippet, - mimeType: `text/plain`, + mimeType: 'text/plain', }, }; @@ -59,7 +59,7 @@ async function predict(projectId, computeRegion, modelId, filePath) { payload: payload, params: {}, }); - console.log(`Prediction results:`); + console.log('Prediction results:'); response[0].payload.forEach(result => { console.log(`Predicted class name: ${result.displayName}`); console.log(`Predicted class score: ${result.classification.score}`); @@ -67,47 +67,47 @@ async function predict(projectId, computeRegion, modelId, filePath) { // [END automl_language_predict] } -require(`yargs`) +require('yargs') .demand(1) .options({ computeRegion: { - alias: `c`, - type: `string`, + alias: 'c', + type: 'string', default: process.env.REGION_NAME, requiresArg: true, - description: `region name e.g. "us-central1"`, + description: 'region name e.g. "us-central1"', }, filePath: { - alias: `f`, - default: `./resources/test.txt`, - type: `string`, + alias: 'f', + default: './resources/test.txt', + type: 'string', requiresArg: true, - description: `local text file path of the content to be classified`, + description: 'local text file path of the content to be classified', }, modelId: { - alias: `i`, - type: `string`, + alias: 'i', + type: 'string', requiresArg: true, - description: `Id of the model which will be used for text classification`, + description: 'Id of the model which will be used for text classification', }, projectId: { - alias: `z`, - type: `number`, + alias: 'z', + type: 'number', default: process.env.GCLOUD_PROJECT, requiresArg: true, - description: `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`, + description: 'The GCLOUD_PROJECT string, e.g. "my-gcloud-project"', }, scoreThreshold: { - alias: `s`, - type: `string`, - default: `0.5`, + alias: 's', + type: 'string', + default: '0.5', requiresArg: true, description: - `A value from 0.0 to 1.0. When the model makes predictions for an image it will` + - `only produce results that have at least this confidence score threshold. Default is .5`, + 'A value from 0.0 to 1.0. When the model makes predictions for an image it will' + + 'only produce results that have at least this confidence score threshold. Default is .5', }, }) - .command(`predict`, `classify the content`, {}, opts => + .command('predict', 'classify the content', {}, opts => predict( opts.projectId, opts.computeRegion, @@ -116,7 +116,7 @@ require(`yargs`) opts.scoreThreshold ) ) - .example(`node $0 predict -i "modelId" -f "./resources/test.txt" -s "0.5"`) + .example('node $0 predict -i "modelId" -f "./resources/test.txt" -s "0.5"') .wrap(120) .recommendCommands() .help() diff --git a/cloud-language/snippets/test/analyze.v1.test.js b/cloud-language/snippets/test/analyze.v1.test.js index 8e9404b060..4dc992f8ea 100644 --- a/cloud-language/snippets/test/analyze.v1.test.js +++ b/cloud-language/snippets/test/analyze.v1.test.js @@ -18,7 +18,7 @@ const fs = require('fs'); const path = require('path'); const {Storage} = require('@google-cloud/storage'); const {assert} = require('chai'); -const {describe, it} = require('mocha'); +const {after, before, describe, it} = require('mocha'); const cp = require('child_process'); const uuid = require('uuid'); @@ -28,8 +28,8 @@ describe('analyze.v1', () => { const storage = new Storage(); const cmd = 'node analyze.v1.js'; const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`; - const fileName = `text.txt`; - const fileName2 = `android_text.txt`; + const fileName = 'text.txt'; + const fileName2 = 'android_text.txt'; const localFilePath = path.join(__dirname, `../resources/${fileName}`); const localFilePath2 = path.join(__dirname, `../resources/${fileName2}`); const text = fs.readFileSync(localFilePath, 'utf-8'); diff --git a/cloud-language/snippets/test/automlNaturalLanguage.test.js b/cloud-language/snippets/test/automlNaturalLanguage.test.js index 8f68970e2e..efc5daab67 100644 --- a/cloud-language/snippets/test/automlNaturalLanguage.test.js +++ b/cloud-language/snippets/test/automlNaturalLanguage.test.js @@ -93,7 +93,7 @@ describe.skip('automl', () => { }); it('should display evaluation from prexisting model', async () => { - const donotdeleteModelId = `TCN4740161257642267869`; + const donotdeleteModelId = 'TCN4740161257642267869'; // Confirm dataset exists let output = execSync(`${cmdDataset} list-datasets`); @@ -112,7 +112,7 @@ describe.skip('automl', () => { }); it('should run Prediction from prexisting model', async () => { - const donotdeleteModelId = `TCN4740161257642267869`; + const donotdeleteModelId = 'TCN4740161257642267869'; // Confirm dataset exists let output = execSync(`${cmdDataset} list-datasets`);