diff --git a/automl/delete_dataset.js b/automl/delete_dataset.js new file mode 100644 index 0000000000..ba1a17b2ed --- /dev/null +++ b/automl/delete_dataset.js @@ -0,0 +1,53 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main( + projectId = 'YOUR_PROJECT_ID', + location = 'us-central1', + datasetId = 'YOUR_DATASET_ID' +) { + // [START automl_delete_dataset] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'YOUR_PROJECT_ID'; + // const location = 'us-central1'; + // const datasetId = 'YOUR_DATASET_ID'; + + // Imports the Google Cloud AutoML library + const {AutoMlClient} = require(`@google-cloud/automl`).v1; + + // Instantiates a client + const client = new AutoMlClient(); + + async function deleteDataset() { + // Construct request + const request = { + name: client.datasetPath(projectId, location, datasetId), + }; + + const [operation] = await client.deleteDataset(request); + + // Wait for operation to complete. + const [response] = await operation.promise(); + console.log(`Dataset deleted: ${response}`); + } + + deleteDataset(); + // [END automl_delete_dataset] +} + +main(...process.argv.slice(2)); diff --git a/automl/export_dataset.js b/automl/export_dataset.js new file mode 100644 index 0000000000..d399786b1a --- /dev/null +++ b/automl/export_dataset.js @@ -0,0 +1,59 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main( + projectId = 'YOUR_PROJECT_ID', + location = 'us-central1', + datasetId = 'YOUR_DATASET_ID', + gcsUri = 'gs://BUCKET_ID/path_to_export/' +) { + // [START automl_export_dataset] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'YOUR_PROJECT_ID'; + // const location = 'us-central1'; + // const datasetId = 'YOUR_DATASET_ID'; + // const gcsUri = 'gs://BUCKET_ID/path_to_export/'; + + // Imports the Google Cloud AutoML library + const {AutoMlClient} = require(`@google-cloud/automl`).v1; + + // Instantiates a client + const client = new AutoMlClient(); + + async function exportDataset() { + // Construct request + const request = { + name: client.datasetPath(projectId, location, datasetId), + outputConfig: { + gcsDestination: { + outputUriPrefix: gcsUri, + }, + }, + }; + + const [operation] = await client.exportData(request); + // Wait for operation to complete. + const [response] = await operation.promise(); + console.log(`Dataset exported: ${response}`); + } + + exportDataset(); + // [END automl_export_dataset] +} + +main(...process.argv.slice(2)); diff --git a/automl/get_dataset.js b/automl/get_dataset.js new file mode 100644 index 0000000000..a98424ee48 --- /dev/null +++ b/automl/get_dataset.js @@ -0,0 +1,119 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main( + projectId = 'YOUR_PROJECT_ID', + location = 'us-central1', + datasetId = 'YOUR_DATASET_ID' +) { + // [START automl_language_entity_extraction_get_dataset] + // [START automl_language_sentiment_analysis_get_dataset] + // [START automl_language_text_classification_get_dataset] + // [START automl_translate_get_dataset] + // [START automl_vision_classification_get_dataset] + // [START automl_vision_object_detection_get_dataset] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'YOUR_PROJECT_ID'; + // const location = 'us-central1'; + // const datasetId = 'YOUR_DATASET_ID'; + + // Imports the Google Cloud AutoML library + const {AutoMlClient} = require(`@google-cloud/automl`).v1; + + // Instantiates a client + const client = new AutoMlClient(); + + async function getDataset() { + // Construct request + const request = { + name: client.datasetPath(projectId, location, datasetId), + }; + + const [response] = await client.getDataset(request); + + console.log(`Dataset name: ${response.name}`); + console.log( + `Dataset id: ${ + response.name.split('/')[response.name.split('/').length - 1] + }` + ); + console.log(`Dataset display name: ${response.displayName}`); + console.log(`Dataset create time`); + console.log(`\tseconds ${response.createTime.seconds}`); + console.log(`\tnanos ${response.createTime.nanos / 1e9}`); + // [END automl_language_sentiment_analysis_get_dataset] + // [END automl_language_text_classification_get_dataset] + // [END automl_translate_get_dataset] + // [END automl_vision_classification_get_dataset] + // [END automl_vision_object_detection_get_dataset] + console.log( + `Text extraction dataset metadata: ${response.textExtractionDatasetMetadata}` + ); + // [END automl_language_entity_extraction_get_dataset] + + // [START automl_language_sentiment_analysis_get_dataset] + console.log( + `Text sentiment dataset metadata: ${response.textSentimentDatasetMetadata}` + ); + // [END automl_language_sentiment_analysis_get_dataset] + + // [START automl_language_text_classification_get_dataset] + console.log( + `Text classification dataset metadata: ${response.textClassificationDatasetMetadata}` + ); + // [END automl_language_text_classification_get_dataset] + + // [START automl_translate_get_dataset] + if (response.translationDatasetMetadata !== undefined) { + console.log(`Translation dataset metadata:`); + console.log( + `\tSource language code: ${response.translationDatasetMetadata.sourceLanguageCode}` + ); + console.log( + `\tTarget language code: ${response.translationDatasetMetadata.targetLanguageCode}` + ); + } + // [END automl_translate_get_dataset] + + // [START automl_vision_classification_get_dataset] + console.log( + `Image classification dataset metadata: ${response.imageClassificationDatasetMetadata}` + ); + // [END automl_vision_classification_get_dataset] + + // [START automl_vision_object_detection_get_dataset] + console.log( + `Image object detection dataset metatdata: ${response.imageObjectDetectionDatasetMetatdata}` + ); + // [START automl_language_entity_extraction_get_dataset] + // [START automl_language_sentiment_analysis_get_dataset] + // [START automl_language_text_classification_get_dataset] + // [START automl_translate_get_dataset] + // [START automl_vision_classification_get_dataset] + } + + getDataset(); + // [END automl_language_entity_extraction_get_dataset] + // [END automl_language_sentiment_analysis_get_dataset] + // [END automl_language_text_classification_get_dataset] + // [END automl_translate_get_dataset] + // [END automl_vision_classification_get_dataset] + // [END automl_vision_object_detection_get_dataset] +} + +main(...process.argv.slice(2)); diff --git a/automl/import_dataset.js b/automl/import_dataset.js new file mode 100644 index 0000000000..f3a00475d6 --- /dev/null +++ b/automl/import_dataset.js @@ -0,0 +1,62 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main( + projectId = 'YOUR_PROJECT_ID', + location = 'us-central1', + datasetId = 'YOUR_DISPLAY_ID', + path = 'gs://BUCKET_ID/path_to_training_data.csv' +) { + // [START automl_import_dataset] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'YOUR_PROJECT_ID'; + // const location = 'us-central1'; + // const datasetId = 'YOUR_DISPLAY_ID'; + // const path = 'gs://BUCKET_ID/path_to_training_data.csv'; + + // Imports the Google Cloud AutoML library + const {AutoMlClient} = require(`@google-cloud/automl`).v1; + + // Instantiates a client + const client = new AutoMlClient(); + + async function importDataset() { + // Construct request + const request = { + name: client.datasetPath(projectId, location, datasetId), + inputConfig: { + gcsSource: { + inputUris: path.split(','), + }, + }, + }; + + // Import dataset + console.log(`Proccessing import`); + const [operation] = await client.importData(request); + + // Wait for operation to complete. + const [response] = await operation.promise(); + console.log(`Dataset imported: ${response}`); + } + + importDataset(); + // [END automl_import_dataset] +} + +main(...process.argv.slice(2)); diff --git a/automl/language_entity_extraction_create_dataset.js b/automl/language_entity_extraction_create_dataset.js index da894cd849..fde5717aa3 100644 --- a/automl/language_entity_extraction_create_dataset.js +++ b/automl/language_entity_extraction_create_dataset.js @@ -1,17 +1,16 @@ -/** - * Copyright 2019 Google LLC - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. 'use strict'; diff --git a/automl/language_entity_extraction_create_model.js b/automl/language_entity_extraction_create_model.js index a3b88f3f8e..2f5e6af89d 100644 --- a/automl/language_entity_extraction_create_model.js +++ b/automl/language_entity_extraction_create_model.js @@ -1,17 +1,16 @@ -/** - * Copyright 2019 Google LLC - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. 'use strict'; diff --git a/automl/language_entity_extraction_predict.js b/automl/language_entity_extraction_predict.js index fdea47c343..77473e410e 100644 --- a/automl/language_entity_extraction_predict.js +++ b/automl/language_entity_extraction_predict.js @@ -1,17 +1,16 @@ -/** - * Copyright 2019 Google LLC - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. 'use strict'; diff --git a/automl/list_datasets.js b/automl/list_datasets.js new file mode 100644 index 0000000000..91d5a16b68 --- /dev/null +++ b/automl/list_datasets.js @@ -0,0 +1,118 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(projectId = 'YOUR_PROJECT_ID', location = 'us-central1') { + // [START automl_language_entity_extraction_list_datasets] + // [START automl_language_sentiment_analysis_list_datasets] + // [START automl_language_text_classification_list_datasets] + // [START automl_translate_list_datasets] + // [START automl_vision_classification_list_datasets] + // [START automl_vision_object_detection_list_datasets] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'YOUR_PROJECT_ID'; + // const location = 'us-central1'; + + // Imports the Google Cloud AutoML library + const {AutoMlClient} = require(`@google-cloud/automl`).v1; + + // Instantiates a client + const client = new AutoMlClient(); + + async function listDatasets() { + // Construct request + const request = { + parent: client.locationPath(projectId, location), + filter: 'translation_dataset_metadata:*', + }; + + const [response] = await client.listDatasets(request); + + console.log(`List of datasets:`); + for (const dataset of response) { + console.log(`Dataset name: ${dataset.name}`); + console.log( + `Dataset id: ${ + dataset.name.split('/')[dataset.name.split('/').length - 1] + }` + ); + console.log(`Dataset display name: ${dataset.displayName}`); + console.log(`Dataset create time`); + console.log(`\tseconds ${dataset.createTime.seconds}`); + console.log(`\tnanos ${dataset.createTime.nanos / 1e9}`); + // [END automl_language_sentiment_analysis_list_datasets] + // [END automl_language_text_classification_list_datasets] + // [END automl_translate_list_datasets] + // [END automl_vision_classification_list_datasets] + // [END automl_vision_object_detection_list_datasets] + console.log( + `Text extraction dataset metadata: ${dataset.textExtractionDatasetMetadata}` + ); + // [END automl_language_entity_extraction_list_datasets] + + // [START automl_language_sentiment_analysis_list_datasets] + console.log( + `Text sentiment dataset metadata: ${dataset.textSentimentDatasetMetadata}` + ); + // [END automl_language_sentiment_analysis_list_datasets] + + // [START automl_language_text_classification_list_datasets] + console.log( + `Text classification dataset metadata: ${dataset.textClassificationDatasetMetadata}` + ); + // [END automl_language_text_classification_list_datasets] + + // [START automl_translate_list_datasets] + if (dataset.translationDatasetMetadata !== undefined) { + console.log(`Translation dataset metadata:`); + console.log( + `\tSource language code: ${dataset.translationDatasetMetadata.sourceLanguageCode}` + ); + console.log( + `\tTarget language code: ${dataset.translationDatasetMetadata.targetLanguageCode}` + ); + } + // [END automl_translate_list_datasets] + + // [START automl_vision_classification_list_datasets] + console.log( + `Image classification dataset metadata: ${dataset.imageClassificationDatasetMetadata}` + ); + // [END automl_vision_classification_list_datasets] + + // [START automl_vision_object_detection_list_datasets] + console.log( + `Image object detection dataset metatdata: ${dataset.imageObjectDetectionDatasetMetatdata}` + ); + // [START automl_language_entity_extraction_list_datasets] + // [START automl_language_sentiment_analysis_list_datasets] + // [START automl_language_text_classification_list_datasets] + // [START automl_translate_list_datasets] + // [START automl_vision_classification_list_datasets] + } + } + + listDatasets(); + // [END automl_language_entity_extraction_list_datasets] + // [END automl_language_sentiment_analysis_list_datasets] + // [END automl_language_text_classification_list_datasets] + // [END automl_translate_list_datasets] + // [END automl_vision_classification_list_datasets] + // [END automl_vision_object_detection_list_datasets] +} + +main(...process.argv.slice(2)); diff --git a/automl/test/delete_dataset.test.js b/automl/test/delete_dataset.test.js new file mode 100644 index 0000000000..057cfb29ac --- /dev/null +++ b/automl/test/delete_dataset.test.js @@ -0,0 +1,63 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +const {assert} = require('chai'); +const {AutoMlClient} = require('@google-cloud/automl').v1; + +const cp = require('child_process'); +const uuid = require('uuid'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + +const DELETE_DATASET_REGION_TAG = 'delete_dataset'; +const LOCATION = 'us-central1'; + +describe('Automl Translate Delete Dataset Tests', () => { + const client = new AutoMlClient(); + let datasetId; + + before('should create a dataset', async () => { + const projectId = await client.getProjectId(); + const displayName = `test_${uuid + .v4() + .replace(/-/g, '_') + .substring(0, 26)}`; + const request = { + parent: client.locationPath(projectId, LOCATION), + dataset: { + displayName: displayName, + translationDatasetMetadata: { + sourceLanguageCode: 'en', + targetLanguageCode: 'ja', + }, + }, + }; + const [operation] = await client.createDataset(request); + const [response] = await operation.promise(); + datasetId = response.name + .split('/') + [response.name.split('/').length - 1].split('\n')[0]; + }); + + it('should delete a dataset', async () => { + const projectId = await client.getProjectId(); + // delete + const delete_output = execSync( + `node ${DELETE_DATASET_REGION_TAG}.js ${projectId} ${LOCATION} ${datasetId}` + ); + assert.match(delete_output, /Dataset deleted/); + }); +}); diff --git a/automl/test/export_dataset.test.js b/automl/test/export_dataset.test.js new file mode 100644 index 0000000000..7cc956ce9f --- /dev/null +++ b/automl/test/export_dataset.test.js @@ -0,0 +1,62 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +const {assert} = require('chai'); +const {AutoMlClient} = require('@google-cloud/automl').v1; +const {Storage} = require('@google-cloud/storage'); + +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + +const DATASET_ID = 'TRL8522556519449886720'; +const EXPORT_DATASET_REGION_TAG = 'export_dataset'; +const LOCATION = 'us-central1'; + +describe('Automl Translate Dataset Tests', () => { + const client = new AutoMlClient(); + const prefix = 'TEST_EXPORT_OUTPUT'; + + it('should export a datset', async () => { + const projectId = await client.getProjectId(); + const bucketName = `${projectId}-automl-translate`; + const export_output = execSync( + `node ${EXPORT_DATASET_REGION_TAG}.js ${projectId} ${LOCATION} ${DATASET_ID} gs://${bucketName}/${prefix}/` + ); + + assert.match(export_output, /Dataset exported/); + }); + + after('delete created files', async () => { + const projectId = await client.getProjectId(); + const bucketName = `${projectId}-automl-translate`; + + const storageClient = new Storage(); + const options = { + prefix: prefix, + }; + const [files] = await storageClient + .bucket(`gs://${bucketName}`) + .getFiles(options); + + for (const file of files) { + await storageClient + .bucket(`gs://${bucketName}`) + .file(file.name) + .delete(); + } + }); +}); diff --git a/automl/test/get_dataset.test.js b/automl/test/get_dataset.test.js new file mode 100644 index 0000000000..f9d1dff5ce --- /dev/null +++ b/automl/test/get_dataset.test.js @@ -0,0 +1,39 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +const {assert} = require('chai'); +const {AutoMlClient} = require('@google-cloud/automl').v1; + +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + +const GET_DATASET_REGION_TAG = 'get_dataset'; +const DATASET_ID = 'TRL8522556519449886720'; +const LOCATION = 'us-central1'; + +describe('Automl Get Dataset Tests', () => { + const client = new AutoMlClient(); + + it('should get a dataset', async () => { + const projectId = await client.getProjectId(); + const get_output = execSync( + `node ${GET_DATASET_REGION_TAG}.js ${projectId} ${LOCATION} ${DATASET_ID}` + ); + + assert.match(get_output, /Dataset id/); + }); +}); diff --git a/automl/test/import_dataset.test.js b/automl/test/import_dataset.test.js new file mode 100644 index 0000000000..70aad765ea --- /dev/null +++ b/automl/test/import_dataset.test.js @@ -0,0 +1,72 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +const {assert} = require('chai'); +const {AutoMlClient} = require('@google-cloud/automl').v1; + +const cp = require('child_process'); +const uuid = require('uuid'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + +const IMPORT_DATASET_REGION_TAG = 'import_dataset'; +const LOCATION = 'us-central1'; + +describe('Automl Import Dataset Test', () => { + const client = new AutoMlClient(); + let datasetId; + + before('should create a dataset', async () => { + const projectId = await client.getProjectId(); + const displayName = `test_${uuid + .v4() + .replace(/-/g, '_') + .substring(0, 26)}`; + const request = { + parent: client.locationPath(projectId, LOCATION), + dataset: { + displayName: displayName, + translationDatasetMetadata: { + sourceLanguageCode: 'en', + targetLanguageCode: 'ja', + }, + }, + }; + const [operation] = await client.createDataset(request); + const [response] = await operation.promise(); + datasetId = response.name + .split('/') + [response.name.split('/').length - 1].split('\n')[0]; + }); + + it('should create, import, and delete a dataset', async () => { + const projectId = await client.getProjectId(); + const data = `gs://${projectId}-automl-translate/en-ja-short.csv`; + const import_output = execSync( + `node ${IMPORT_DATASET_REGION_TAG}.js ${projectId} ${LOCATION} ${datasetId} ${data}` + ); + assert.match(import_output, /Dataset imported/); + }); + + after('delete created dataset', async () => { + const projectId = await client.getProjectId(); + const request = { + name: client.datasetPath(projectId, LOCATION, datasetId), + }; + const [operation] = await client.deleteDataset(request); + await operation.promise(); + }); +}); diff --git a/automl/test/language_entity_extraction_create_dataset.test.js b/automl/test/language_entity_extraction_create_dataset.test.js index 8b6bbc4070..ff90eac131 100644 --- a/automl/test/language_entity_extraction_create_dataset.test.js +++ b/automl/test/language_entity_extraction_create_dataset.test.js @@ -1,17 +1,16 @@ -/** - * Copyright 2019 Google LLC - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. 'use strict'; diff --git a/automl/test/language_entity_extraction_create_model.test.js b/automl/test/language_entity_extraction_create_model.test.js index 60e448ef9e..08ba95a371 100644 --- a/automl/test/language_entity_extraction_create_model.test.js +++ b/automl/test/language_entity_extraction_create_model.test.js @@ -1,17 +1,16 @@ -/** - * Copyright 2019 Google LLC - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. 'use strict'; diff --git a/automl/test/language_entity_extraction_predict.test.js b/automl/test/language_entity_extraction_predict.test.js index fb44939646..7b8a71a1ef 100644 --- a/automl/test/language_entity_extraction_predict.test.js +++ b/automl/test/language_entity_extraction_predict.test.js @@ -1,17 +1,16 @@ -/** - * Copyright 2019 Google LLC - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. 'use strict'; diff --git a/automl/test/list_datasets.test.js b/automl/test/list_datasets.test.js new file mode 100644 index 0000000000..0164f7eed9 --- /dev/null +++ b/automl/test/list_datasets.test.js @@ -0,0 +1,38 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +const {assert} = require('chai'); +const {AutoMlClient} = require('@google-cloud/automl').v1; + +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + +const LIST_DATASET_REGION_TAG = 'list_datasets'; +const LOCATION = 'us-central1'; + +describe('Automl List Dataset Tests', () => { + const client = new AutoMlClient(); + + it('should list datasets', async () => { + const projectId = await client.getProjectId(); + const list_output = execSync( + `node ${LIST_DATASET_REGION_TAG}.js ${projectId} ${LOCATION}` + ); + + assert.match(list_output, /Dataset id/); + }); +});