From 7b0bffc1e866205945962c37c84c84abd9c7a2e7 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Thu, 19 Mar 2020 15:03:38 -0600 Subject: [PATCH] docs: delete samples that are no longer used in docs and tests are skipped (#350) --- .../create-dataset.v1beta1.js | 67 -------- .../entity-extraction/create-model.v1beta1.js | 58 ------- .../delete-dataset.v1beta1.js | 58 ------- .../entity-extraction/delete-model.v1beta1.js | 59 -------- .../entity-extraction/deploy-model.v1beta1.js | 52 ------- .../display-evaluation.v1beta1.js | 112 -------------- .../entity-extraction/export-data.v1beta1.js | 71 --------- .../entity-extraction/get-dataset.v1beta1.js | 62 -------- .../get-model-evaluation.v1beta1.js | 105 ------------- .../entity-extraction/get-model.v1beta1.js | 66 -------- .../get-operation-status.v1beta1.js | 56 ------- .../entity-extraction/import-data.v1beta1.js | 70 --------- .../list-datasets.v1beta1.js | 65 -------- .../list-model-evaluations.v1beta1.js | 103 ------------- .../entity-extraction/list-models.v1beta1.js | 69 --------- .../list-operations-status.v1beta1.js | 68 --------- .../entity-extraction/predict.v1beta1.js | 82 ---------- .../undeploy-model.v1beta1.js | 52 ------- .../create-dataset.v1beta1.js | 67 -------- .../create-model.v1beta1.js | 58 ------- .../delete-dataset.v1beta1.js | 58 ------- .../delete-model.v1beta1.js | 58 ------- .../deploy-model.v1beta1.js | 52 ------- .../display-evaluation.v1beta1.js | 143 ------------------ .../sentiment-analysis/export-data.v1beta1.js | 71 --------- .../sentiment-analysis/get-dataset.v1beta1.js | 58 ------- .../get-model-evaluation.v1beta1.js | 138 ----------------- .../sentiment-analysis/get-model.v1beta1.js | 66 -------- .../get-operation-status.v1beta1.js | 56 ------- .../sentiment-analysis/import-data.v1beta1.js | 70 --------- .../list-datasets.v1beta1.js | 66 -------- .../list-model-evaluations.v1beta1.js | 138 ----------------- .../sentiment-analysis/list-models.v1beta1.js | 69 --------- .../list-operation-status.v1beta1.js | 65 -------- .../sentiment-analysis/predict.v1beta1.js | 75 --------- .../undeploy-model.v1beta1.js | 52 ------- ...mlLangaugeSentimentDataSet.v1beta1.test.js | 74 --------- ...utomlLanguageEntityDataSet.v1beta1.test.js | 82 ---------- .../automlLanguageEntityModel.v1beta1.test.js | 125 --------------- ...mlLanguageEntityPrediction.v1beta1.test.js | 42 ----- ...tomlLanguageSentimentModel.v1beta1.test.js | 114 -------------- ...anguageSentimentPrediction.v1beta1.test.js | 45 ------ ...sionObjectDetectionDataset.v1beta1.test.js | 82 ---------- ...VisionObjectDetectionModel.v1beta1.test.js | 127 ---------------- ...sionObjectDetectionPredict.v1beta1.test.js | 40 ----- .../datasets/create-dataset.v1beta1.js | 66 -------- .../datasets/delete-dataset.v1beta1.js | 45 ------ .../translate/datasets/get-dataset.v1beta1.js | 58 ------- .../translate/datasets/import-data.v1beta1.js | 62 -------- .../datasets/list-datasets.v1beta1.js | 67 -------- .../translate/models/create-model.v1beta1.js | 77 ---------- .../translate/models/delete-model.v1beta1.js | 46 ------ .../models/get-model-evaluation.v1beta1.js | 52 ------- automl/translate/models/get-model.v1beta1.js | 84 ---------- .../models/get-operation-status.v1beta1.js | 36 ----- .../models/list-model-evaluations.v1beta1.js | 52 ------- .../translate/models/list-models.v1beta1.js | 63 -------- .../translate/prediction/predict.v1beta1.js | 77 ---------- automl/vision/automlVisionDataset.js | 111 -------------- automl/vision/automlVisionModel.js | 82 ---------- .../create-dataset.v1beta1.js | 70 --------- .../object-detection/create-model.v1beta1.js | 60 -------- .../delete-dataset.v1beta1.js | 59 -------- .../object-detection/delete-model.v1beta1.js | 58 ------- .../object-detection/deploy-model.v1beta1.js | 57 ------- .../display-evaluation.v1beta1.js | 118 --------------- .../object-detection/export-data.v1beta1.js | 73 --------- .../object-detection/get-dataset.v1beta1.js | 61 -------- .../get-model-evaluations.v1beta1.js | 133 ---------------- .../object-detection/get-model.v1beta1.js | 93 ------------ .../object-detection/import-data.v1beta1.js | 69 --------- .../object-detection/list-datasets.v1beta1.js | 64 -------- .../list-model-evaluations.v1beta1.js | 135 ----------------- .../object-detection/list-models.v1beta1.js | 92 ----------- .../list-operation-status.v1beta1.js | 55 ------- .../object-detection/predict.v1beta1.js | 87 ----------- .../undeploy-model.v1beta1.js | 58 ------- 77 files changed, 5686 deletions(-) delete mode 100644 automl/language/entity-extraction/create-dataset.v1beta1.js delete mode 100644 automl/language/entity-extraction/create-model.v1beta1.js delete mode 100644 automl/language/entity-extraction/delete-dataset.v1beta1.js delete mode 100644 automl/language/entity-extraction/delete-model.v1beta1.js delete mode 100644 automl/language/entity-extraction/deploy-model.v1beta1.js delete mode 100644 automl/language/entity-extraction/display-evaluation.v1beta1.js delete mode 100644 automl/language/entity-extraction/export-data.v1beta1.js delete mode 100644 automl/language/entity-extraction/get-dataset.v1beta1.js delete mode 100644 automl/language/entity-extraction/get-model-evaluation.v1beta1.js delete mode 100644 automl/language/entity-extraction/get-model.v1beta1.js delete mode 100644 automl/language/entity-extraction/get-operation-status.v1beta1.js delete mode 100644 automl/language/entity-extraction/import-data.v1beta1.js delete mode 100644 automl/language/entity-extraction/list-datasets.v1beta1.js delete mode 100644 automl/language/entity-extraction/list-model-evaluations.v1beta1.js delete mode 100644 automl/language/entity-extraction/list-models.v1beta1.js delete mode 100644 automl/language/entity-extraction/list-operations-status.v1beta1.js delete mode 100644 automl/language/entity-extraction/predict.v1beta1.js delete mode 100644 automl/language/entity-extraction/undeploy-model.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/create-dataset.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/create-model.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/delete-dataset.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/delete-model.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/deploy-model.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/display-evaluation.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/export-data.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/get-dataset.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/get-model-evaluation.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/get-model.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/get-operation-status.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/import-data.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/list-datasets.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/list-model-evaluations.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/list-models.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/list-operation-status.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/predict.v1beta1.js delete mode 100644 automl/language/sentiment-analysis/undeploy-model.v1beta1.js delete mode 100644 automl/test/automlLangaugeSentimentDataSet.v1beta1.test.js delete mode 100644 automl/test/automlLanguageEntityDataSet.v1beta1.test.js delete mode 100644 automl/test/automlLanguageEntityModel.v1beta1.test.js delete mode 100644 automl/test/automlLanguageEntityPrediction.v1beta1.test.js delete mode 100644 automl/test/automlLanguageSentimentModel.v1beta1.test.js delete mode 100644 automl/test/automlLanguageSentimentPrediction.v1beta1.test.js delete mode 100644 automl/test/automlVisionObjectDetectionDataset.v1beta1.test.js delete mode 100644 automl/test/automlVisionObjectDetectionModel.v1beta1.test.js delete mode 100644 automl/test/automlVisionObjectDetectionPredict.v1beta1.test.js delete mode 100644 automl/translate/datasets/create-dataset.v1beta1.js delete mode 100644 automl/translate/datasets/delete-dataset.v1beta1.js delete mode 100644 automl/translate/datasets/get-dataset.v1beta1.js delete mode 100644 automl/translate/datasets/import-data.v1beta1.js delete mode 100644 automl/translate/datasets/list-datasets.v1beta1.js delete mode 100644 automl/translate/models/create-model.v1beta1.js delete mode 100644 automl/translate/models/delete-model.v1beta1.js delete mode 100644 automl/translate/models/get-model-evaluation.v1beta1.js delete mode 100644 automl/translate/models/get-model.v1beta1.js delete mode 100644 automl/translate/models/get-operation-status.v1beta1.js delete mode 100644 automl/translate/models/list-model-evaluations.v1beta1.js delete mode 100644 automl/translate/models/list-models.v1beta1.js delete mode 100644 automl/translate/prediction/predict.v1beta1.js delete mode 100644 automl/vision/object-detection/create-dataset.v1beta1.js delete mode 100644 automl/vision/object-detection/create-model.v1beta1.js delete mode 100644 automl/vision/object-detection/delete-dataset.v1beta1.js delete mode 100644 automl/vision/object-detection/delete-model.v1beta1.js delete mode 100644 automl/vision/object-detection/deploy-model.v1beta1.js delete mode 100644 automl/vision/object-detection/display-evaluation.v1beta1.js delete mode 100644 automl/vision/object-detection/export-data.v1beta1.js delete mode 100644 automl/vision/object-detection/get-dataset.v1beta1.js delete mode 100644 automl/vision/object-detection/get-model-evaluations.v1beta1.js delete mode 100644 automl/vision/object-detection/get-model.v1beta1.js delete mode 100644 automl/vision/object-detection/import-data.v1beta1.js delete mode 100644 automl/vision/object-detection/list-datasets.v1beta1.js delete mode 100644 automl/vision/object-detection/list-model-evaluations.v1beta1.js delete mode 100644 automl/vision/object-detection/list-models.v1beta1.js delete mode 100644 automl/vision/object-detection/list-operation-status.v1beta1.js delete mode 100644 automl/vision/object-detection/predict.v1beta1.js delete mode 100644 automl/vision/object-detection/undeploy-model.v1beta1.js diff --git a/automl/language/entity-extraction/create-dataset.v1beta1.js b/automl/language/entity-extraction/create-dataset.v1beta1.js deleted file mode 100644 index 616793cef5..0000000000 --- a/automl/language/entity-extraction/create-dataset.v1beta1.js +++ /dev/null @@ -1,67 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - datasetName = 'YOUR_DATASET_NAME' -) { - // [START automl_language_entity_create_dataset] - const automl = require('@google-cloud/automl'); - const util = require('util'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to create a dataset - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetName = '[DATASET_NAME]' e.g., "myDataset"; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // Set dataset name and metadata. - const myDataset = { - displayName: datasetName, - textExtractionDatasetMetadata: {}, - }; - - // Create a dataset with the dataset metadata in the region. - client - .createDataset({parent: projectLocation, dataset: myDataset}) - .then(responses => { - const dataset = responses[0]; - - // Display the dataset information. - console.log(`Dataset name: ${dataset.name}`); - 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 extraction dataset metadata: ${util.inspect( - dataset.textExtractionDatasetMetadata, - false, - null - )}` - ); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_create_dataset] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/entity-extraction/create-model.v1beta1.js b/automl/language/entity-extraction/create-model.v1beta1.js deleted file mode 100644 index 3b34100462..0000000000 --- a/automl/language/entity-extraction/create-model.v1beta1.js +++ /dev/null @@ -1,58 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - datasetId = 'YOUR_DATASET_NAME', - modelName = 'YOUR_MODEL_NAME' -) { - // [START automl_language_entity_create_model] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to create a model. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetId = '[DATASET_ID]' e.g., "TEN8051890775971069952"; - // const modelName = '[MODEL_NAME]' e.g., "myModel"; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // Set datasetId, model name and model metadata for the dataset. - const myModel = { - displayName: modelName, - datasetId: datasetId, - textExtractionModelMetadata: {}, - }; - - // Create a model with the model metadata in the region. - client - .createModel({parent: projectLocation, model: myModel}) - .then(responses => { - const initialApiResponse = responses[1]; - console.log(`Training operation name: ${initialApiResponse.name}`); - console.log(`Training started...`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_create_model] -} -main(...process.argv.slice(2)).catch(console.error); diff --git a/automl/language/entity-extraction/delete-dataset.v1beta1.js b/automl/language/entity-extraction/delete-dataset.v1beta1.js deleted file mode 100644 index 23c401b2ad..0000000000 --- a/automl/language/entity-extraction/delete-dataset.v1beta1.js +++ /dev/null @@ -1,58 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - datasetId = 'YOUR_DATASET_ID' -) { - // [START automl_language_entity_delete_dataset] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to delete a dataset. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetId = '[DATASET_ID]' e.g., "TEN8051890775971069952"; - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId); - - // Delete a dataset. - client - .deleteDataset({name: datasetFullId}) - .then(responses => { - const operation = responses[0]; - return operation.promise(); - }) - .then(responses => { - // The final result of the operation. - const operationDetails = responses[2]; - - // Get the Dataset delete details. - console.log('Dataset delete details:'); - console.log(`\tOperation details:`); - console.log(`\t\tName: ${operationDetails.name}`); - console.log(`\t\tDone: ${operationDetails.done}`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_delete_dataset] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/entity-extraction/delete-model.v1beta1.js b/automl/language/entity-extraction/delete-model.v1beta1.js deleted file mode 100644 index e8ce4bb1ec..0000000000 --- a/automl/language/entity-extraction/delete-model.v1beta1.js +++ /dev/null @@ -1,59 +0,0 @@ -// 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 -// -// https://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'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'YOUR_MODEL_ID' -) { - // [START automl_language_entity_delete_model] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to delete a model. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656"; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Delete a model. - client - .deleteModel({name: modelFullId}) - .then(responses => { - const operation = responses[0]; - return operation.promise(); - }) - .then(responses => { - // The final result of the operation. - const operationDetails = responses[2]; - - // Get the Model delete details. - console.log('Model delete details:'); - console.log(`\tOperation details:`); - console.log(`\t\tName: ${operationDetails.name}`); - console.log(`\tDone: ${operationDetails.done}`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_delete_model] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/entity-extraction/deploy-model.v1beta1.js b/automl/language/entity-extraction/deploy-model.v1beta1.js deleted file mode 100644 index 74da4cb73f..0000000000 --- a/automl/language/entity-extraction/deploy-model.v1beta1.js +++ /dev/null @@ -1,52 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'YOUR_MODEL_ID' -) { - // [START automl_language_entity_deploy_model] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to deploy model. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656"; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Deploy a model with the deploy model request. - client - .deployModel({name: modelFullId}) - .then(responses => { - const response = responses[0]; - console.log(`Deployment Details:`); - console.log(`\tName: ${response.name}`); - console.log(`\tMetadata:`); - console.log(`\t\tType Url: ${response.metadata.typeUrl}`); - console.log(`\tDone: ${response.done}`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_deploy_model] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/entity-extraction/display-evaluation.v1beta1.js b/automl/language/entity-extraction/display-evaluation.v1beta1.js deleted file mode 100644 index aa14f91729..0000000000 --- a/automl/language/entity-extraction/display-evaluation.v1beta1.js +++ /dev/null @@ -1,112 +0,0 @@ -// 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 -// -// https://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'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'YOUR_MODEL_ID', - filter = 'YOUR_FILTER_EXPRESSION' -) { - // [START automl_language_entity_display_evaluation] - const automl = require('@google-cloud/automl'); - const math = require('mathjs'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to display model evaluation. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656"; - // const filter_ = '[FILTER_EXPRESSIONS]' - // e.g., "textExtractionModelMetadata:*"; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // List all the model evaluations in the model by applying filter. - client - .listModelEvaluations({parent: modelFullId, filter: filter}) - .then(respond => { - const response = respond[0]; - // Iterate through the results. - let modelEvaluationId = ``; - for (const element of response) { - // There is evaluation for each class in a model and for overall model. - // Get only the evaluation of overall model. - if (!element.annotationSpecId) { - modelEvaluationId = element.name.split(`/`).pop(-1); - } - } - console.log(`Model Evaluation ID: ${modelEvaluationId}`); - - // Resource name for the model evaluation. - const modelEvaluationFullId = client.modelEvaluationPath( - projectId, - computeRegion, - modelId, - modelEvaluationId - ); - - // Get a model evaluation. - client - .getModelEvaluation({name: modelEvaluationFullId}) - .then(responses => { - const modelEvaluation = responses[0]; - const extractMetrics = - modelEvaluation.textExtractionEvaluationMetrics; - const confidenceMetricsEntries = - extractMetrics.confidenceMetricsEntries; - - // Showing model score based on threshold of 0.5 - for (const confidenceMetricsEntry of confidenceMetricsEntries) { - if (confidenceMetricsEntry.confidenceThreshold === 0.5) { - console.log( - `Precision and recall are based ` + - `on a score threshold of 0.5 ` - ); - console.log( - `Model precision: ${math.round( - confidenceMetricsEntry.precision * 100, - 2 - )} %` - ); - console.log( - `Model recall: ${math.round( - confidenceMetricsEntry.recall * 100, - 2 - )} %` - ); - console.log( - `Model f1 score: ${math.round( - confidenceMetricsEntry.f1Score * 100, - 2 - )} %` - ); - } - } - }) - .catch(err => { - console.error(err); - }); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_display_evaluation] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/entity-extraction/export-data.v1beta1.js b/automl/language/entity-extraction/export-data.v1beta1.js deleted file mode 100644 index 9efc5639f3..0000000000 --- a/automl/language/entity-extraction/export-data.v1beta1.js +++ /dev/null @@ -1,71 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - datasetId = 'YOUR_DATASET_ID', - gcsOutputUri = 'GCS_OUTPUT_URI' -) { - // [START automl_language_entity_export_data] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to export a dataset to a - * Google Cloud Storage bucket. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetId = '[DATASET_ID]' e.g., "TEN8051890775971069952"; - // const gcsOutputUri = '[GCS_OUTPUT_URI]' - // e.g., "gs:///", - // `Google Cloud Storage URI for the export directory`; - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId); - - // Set the output URI - const outputConfig = { - gcsDestination: { - outputUriPrefix: gcsOutputUri, - }, - }; - - // Export the data to the output URI. - client - .exportData({name: datasetFullId, outputConfig: outputConfig}) - .then(responses => { - const operation = responses[0]; - console.log(`Processing export...`); - return operation.promise(); - }) - .then(responses => { - // The final result of the operation. - const operationDetails = responses[2]; - - // Get the data export details. - console.log('Data export details:'); - console.log(`\tOperation details:`); - console.log(`\t\tName: ${operationDetails.name}`); - console.log(`\t\tDone: ${operationDetails.done}`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_export_data] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/entity-extraction/get-dataset.v1beta1.js b/automl/language/entity-extraction/get-dataset.v1beta1.js deleted file mode 100644 index 0729914301..0000000000 --- a/automl/language/entity-extraction/get-dataset.v1beta1.js +++ /dev/null @@ -1,62 +0,0 @@ -// 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 -// -// https://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'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - datasetId = 'YOUR_DATASET_ID' -) { - // [START automl_language_entity_get_dataset] - const automl = require('@google-cloud/automl'); - const util = require('util'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to get a dataset by ID. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetId = '[DATASET_ID]' e.g., "TEN8051890775971069952"; - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId); - - // Get all the information about a given dataset. - client - .getDataset({name: datasetFullId}) - .then(responses => { - const dataset = responses[0]; - - // Display the dataset information. - console.log(`Dataset name: ${dataset.name}`); - 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 extraction dataset metadata: ${util.inspect( - dataset.textExtractionDatasetMetadata, - false, - null - )}` - ); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_get_dataset] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/entity-extraction/get-model-evaluation.v1beta1.js b/automl/language/entity-extraction/get-model-evaluation.v1beta1.js deleted file mode 100644 index cce6f40f29..0000000000 --- a/automl/language/entity-extraction/get-model-evaluation.v1beta1.js +++ /dev/null @@ -1,105 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'YOUR_MODEL_ID', - modelEvaluationId = 'YOUR_MODEL_EVALUATION_ID' -) { - // [START automl_language_entity_get_model_evaluation] - const automl = require('@google-cloud/automl'); - const math = require('mathjs'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to get model evaluations. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656"; - // const modelEvaluationId = '[MODEL_EVALUATION_ID]' - // e.g., "3806191078210741236"; - - // Get the full path of the model evaluation. - const modelEvaluationFullId = client.modelEvaluationPath( - projectId, - computeRegion, - modelId, - modelEvaluationId - ); - - // Get complete detail of the model evaluation. - client - .getModelEvaluation({name: modelEvaluationFullId}) - .then(responses => { - const response = responses[0]; - - const extractMetrics = response.textExtractionEvaluationMetrics; - const confidenceMetricsEntries = extractMetrics.confidenceMetricsEntries; - - // Display the model evaluations information. - console.log(`\nModel evaluation name: ${response.name}`); - console.log( - `Model evaluation Id: ${response.name - .split(`/`) - .slice(-1) - .pop()}` - ); - console.log( - `Model evaluation annotation spec Id: ${response.annotationSpecId}` - ); - console.log(`Model evaluation display name: ${response.displayName}`); - console.log( - `Model evaluation example count: ${response.evaluatedExampleCount}` - ); - console.log(`Text extraction evaluation metrics:`); - console.log(`\tModel AuPrc: ${math.round(extractMetrics.auPrc, 2)}`); - console.log(`\tConfidence metrics entries:`); - - for (const confidenceMetricsEntry of confidenceMetricsEntries) { - console.log( - `\t\tModel confidence threshold: ${math.round( - confidenceMetricsEntry.confidenceThreshold, - 2 - )}` - ); - console.log( - `\t\tModel recall: ${math.round( - confidenceMetricsEntry.recall * 100, - 2 - )} %` - ); - console.log( - `\t\tModel precision: ${math.round( - confidenceMetricsEntry.precision * 100, - 2 - )} %` - ); - console.log( - `\t\tModel f1 score: ${math.round( - confidenceMetricsEntry.f1Score * 100, - 2 - )} % \n` - ); - } - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_get_model_evaluation] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/entity-extraction/get-model.v1beta1.js b/automl/language/entity-extraction/get-model.v1beta1.js deleted file mode 100644 index 9d1644268a..0000000000 --- a/automl/language/entity-extraction/get-model.v1beta1.js +++ /dev/null @@ -1,66 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'YOUR_MODEL_ID' -) { - // [START automl_language_entity_get_model] - const automl = require('@google-cloud/automl'); - const util = require('util'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to get model details. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656"; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Get complete detail of the model. - client - .getModel({name: modelFullId}) - .then(responses => { - const model = responses[0]; - - // Display the model information. - console.log(`Model name: ${model.name}`); - console.log(`Model Id: ${model.name.split(`/`).pop(-1)}`); - console.log(`Model display name: ${model.displayName}`); - console.log(`Dataset Id: ${model.datasetId}`); - - if (model.modelMetadata === `textExtractionModelMetadata`) { - console.log( - `TextExtractionModelMetadata: ${util.inspect( - model.textExtractionModelMetadata, - false, - null - )}` - ); - } - - console.log(`Model deployment state: ${model.deploymentState}`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_get_model] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/entity-extraction/get-operation-status.v1beta1.js b/automl/language/entity-extraction/get-operation-status.v1beta1.js deleted file mode 100644 index 9890e925c8..0000000000 --- a/automl/language/entity-extraction/get-operation-status.v1beta1.js +++ /dev/null @@ -1,56 +0,0 @@ -// 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 -// -// https://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'; -async function main(operationFullId = 'OPERATION_FULL_ID') { - // [START automl_language_entity_get_operation_status] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to get operation status. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const operationFullId = '[OPERATION_FULL_ID]' - // eg., "projects//locations/us-central1/operations/", - // `Full name of an operation`; - - // Get the latest state of a long-running operation. - client.operationsClient - .getOperation({name: operationFullId}) - .then(responses => { - const response = responses[0]; - console.log(`Operation details:`); - console.log(`\tName: ${response.name}`); - console.log(`\tMetadata:`); - console.log(`\t\tType Url: ${response.metadata.typeUrl}`); - console.log(`\tDone: ${response.done}`); - - if (response.response) { - console.log(`\tResponse:`); - console.log(`\t\tType Url: ${response.response.typeUrl}`); - } - - if (response.error) { - console.log(`\tResponse:`); - console.log(`\t\tError code: ${response.error.code}`); - console.log(`\t\tError message: ${response.error.message}`); - } - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_get_operation_status] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/entity-extraction/import-data.v1beta1.js b/automl/language/entity-extraction/import-data.v1beta1.js deleted file mode 100644 index 1a1cf3f10a..0000000000 --- a/automl/language/entity-extraction/import-data.v1beta1.js +++ /dev/null @@ -1,70 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - datasetId = 'YOUR_DATASET_ID', - gcsPath = 'GCS_PATH' -) { - // [START automl_language_entity_import_data] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to import labeled items. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetId = '[DATASET_ID]' e.g., "TEN8051890775971069952"; - // const gcsPath = '[GCS_PATH]' e.g., "gs:///", - // `.csv paths in AutoML Natural Language Entity CSV format`; - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId); - - // Get the multiple Google Cloud Storage URIs. - const inputUris = gcsPath.split(`,`); - const inputConfig = { - gcsSource: { - inputUris: inputUris, - }, - }; - - // Import the data from the input URI. - client - .importData({name: datasetFullId, inputConfig: inputConfig}) - .then(responses => { - const operation = responses[0]; - console.log(`Processing import...`); - return operation.promise(); - }) - .then(responses => { - // The final result of the operation. - const operationDetails = responses[2]; - - // Get the data import details. - console.log('Data import details:'); - console.log(`\tOperation details:`); - console.log(`\t\tName: ${operationDetails.name}`); - console.log(`\t\tDone: ${operationDetails.done}`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_import_data] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/entity-extraction/list-datasets.v1beta1.js b/automl/language/entity-extraction/list-datasets.v1beta1.js deleted file mode 100644 index 289fa6bf7d..0000000000 --- a/automl/language/entity-extraction/list-datasets.v1beta1.js +++ /dev/null @@ -1,65 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - filter = 'YOUR_FILTER_EXPRESSION' -) { - // [START automl_language_entity_list_datasets] - const automl = require('@google-cloud/automl'); - const util = require('util'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to list all datasets. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const filter_ = '[FILTER_EXPRESSIONS]' - // e.g., "textExtractionDatasetMetadata:*"; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // List all the datasets available in the region by applying filter. - client - .listDatasets({parent: projectLocation, filter: filter}) - .then(responses => { - const dataset = responses[0]; - - // Display the dataset information. - console.log(`List of datasets:`); - for (let i = 0; i < dataset.length; i++) { - console.log(`\nDataset name: ${dataset[i].name}`); - console.log(`Dataset Id: ${dataset[i].name.split(`/`).pop(-1)}`); - console.log(`Dataset display name: ${dataset[i].displayName}`); - console.log(`Dataset example count: ${dataset[i].exampleCount}`); - console.log( - `Text extraction dataset metadata: ${util.inspect( - dataset[i].textExtractionDatasetMetadata, - false, - null - )}` - ); - } - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_list_datasets] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/entity-extraction/list-model-evaluations.v1beta1.js b/automl/language/entity-extraction/list-model-evaluations.v1beta1.js deleted file mode 100644 index 2b0b6778c2..0000000000 --- a/automl/language/entity-extraction/list-model-evaluations.v1beta1.js +++ /dev/null @@ -1,103 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'YOUR_MODEL_ID', - filter = 'YOUR_FILTER_EXPRESSION' -) { - // [START automl_language_entity_list_model_evaluations] - const automl = require('@google-cloud/automl'); - const math = require('mathjs'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to list model evaluations. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656"; - // const filter_ = '[FILTER_EXPRESSIONS]' - // e.g., "textExtractionModelMetadata:*"; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // List all the model evaluations in the model by applying filter. - client - .listModelEvaluations({parent: modelFullId, filter: filter}) - .then(responses => { - const element = responses[0]; - console.log(`List of model evaluations:`); - for (let i = 0; i < element.length; i++) { - const extractMetrics = element[i].textExtractionEvaluationMetrics; - const confidenceMetricsEntries = - extractMetrics.confidenceMetricsEntries; - - // Display the model evaluations information. - console.log(`\nModel evaluation name: ${element[i].name}`); - console.log( - `Model evaluation Id: ${element[i].name - .split(`/`) - .slice(-1) - .pop()}` - ); - console.log( - `Model evaluation annotation spec Id: ${element[i].annotationSpecId}` - ); - console.log(`Model evaluation display name: ${element[i].displayName}`); - console.log( - `Model evaluation example count: ${element[i].evaluatedExampleCount}` - ); - console.log(`Text extraction evaluation metrics:`); - console.log(`\tModel AuPrc: ${math.round(extractMetrics.auPrc, 2)}`); - console.log(`\tConfidence metrics entries:`); - - for (const confidenceMetricsEntry of confidenceMetricsEntries) { - console.log( - `\t\tModel confidence threshold: ${math.round( - confidenceMetricsEntry.confidenceThreshold, - 2 - )}` - ); - console.log( - `\t\tModel recall: ${math.round( - confidenceMetricsEntry.recall * 100, - 2 - )} %` - ); - console.log( - `\t\tModel precision: ${math.round( - confidenceMetricsEntry.precision * 100, - 2 - )} %` - ); - console.log( - `\t\tModel f1 score: ${math.round( - confidenceMetricsEntry.f1Score * 100, - 2 - )} % \n` - ); - } - } - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_list_model_evaluations] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/entity-extraction/list-models.v1beta1.js b/automl/language/entity-extraction/list-models.v1beta1.js deleted file mode 100644 index dec2c3218f..0000000000 --- a/automl/language/entity-extraction/list-models.v1beta1.js +++ /dev/null @@ -1,69 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - filter = 'YOUR_FILTER_EXPRESSION' -) { - // [START automl_language_entity_list_models] - const automl = require('@google-cloud/automl'); - const util = require('util'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to list all models. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const filter_ = '[FILTER_EXPRESSIONS]' - // e.g., "textExtractionModelMetadata:*"; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // List all the models available in the region by applying filter. - client - .listModels({parent: projectLocation, filter: filter}) - .then(responses => { - const model = responses[0]; - - // Display the model information. - console.log(`List of models:`); - for (let i = 0; i < model.length; i++) { - console.log(`\nModel name: ${model[i].name}`); - console.log(`Model Id: ${model[i].name.split(`/`).pop(-1)}`); - console.log(`Model display name: ${model[i].displayName}`); - console.log(`Dataset Id: ${model[i].datasetId}`); - - if (model[i].modelMetadata === `textExtractionModelMetadata`) { - console.log( - `TextExtractionModelMetadata: ${util.inspect( - model[i].textExtractionModelMetadata, - false, - null - )}` - ); - } - console.log(`Model deployment state: ${model[i].deploymentState}`); - } - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_list_models] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/entity-extraction/list-operations-status.v1beta1.js b/automl/language/entity-extraction/list-operations-status.v1beta1.js deleted file mode 100644 index 06288c90a4..0000000000 --- a/automl/language/entity-extraction/list-operations-status.v1beta1.js +++ /dev/null @@ -1,68 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - filter = 'YOUR_FILTER_EXPRESSION' -) { - // [START automl_language_entity_list_operations_status] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const filter_ = '[FILTER_EXPRESSIONS]'; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // List all the operations available in the region by applying filter. - client.operationsClient - .listOperations({ - name: projectLocation, - filter: filter, - }) - .then(responses => { - const response = responses[0]; - console.log(`List of operations:`); - for (let i = 0; i < response.length; i++) { - console.log(`\n\tOperation details:`); - console.log(`\t\tName: ${response[i].name}`); - console.log(`\t\tMetadata:`); - console.log(`\t\t\tType Url: ${response[i].metadata.typeUrl}`); - console.log(`\t\tDone: ${response[i].done}`); - - if (response[i].response) { - console.log(`\t\tResponse:`); - console.log(`\t\t\tType Url: ${response[i].response.typeUrl}`); - } - - if (response[i].error) { - console.log(`\t\tResponse:`); - console.log(`\t\t\tError code: ${response[i].error.code}`); - console.log(`\t\t\tError message: ${response[i].error.message}`); - } - } - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_list_operations_status] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/entity-extraction/predict.v1beta1.js b/automl/language/entity-extraction/predict.v1beta1.js deleted file mode 100644 index 2c9b826a3e..0000000000 --- a/automl/language/entity-extraction/predict.v1beta1.js +++ /dev/null @@ -1,82 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'YOUR_MODEL_ID', - filePath = 'YOUR_LOCAL_FILE_PATH' -) { - // [START automl_language_entity_predict] - const automl = require('@google-cloud/automl'); - const fs = require('fs'); - - // Create client for prediction service. - const client = new automl.v1beta1.PredictionServiceClient(); - - /** - * Demonstrates using the AutoML client to Extract the text content - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656"; - // const filePath = '[LOCAL_FILE_PATH]' e.g., "./resource/test.txt", - // `local text file path of content to be extracted`; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Read the file content for prediction. - 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`, - }, - }; - - // Params is additional domain-specific parameters. - // Currently there is no additional parameters supported. - client - .predict({name: modelFullId, payload: payload, params: {}}) - .then(responses => { - console.log(`Prediction results:`); - for (const result of responses[0].payload) { - console.log( - `\tPredicted text extract entity type: ${result.displayName}` - ); - console.log( - `\tPredicted text extract entity content: ${result.textExtraction.textSegment.content}` - ); - console.log( - `\tPredicted text start offset: ${result.textExtraction.textSegment.startOffset}` - ); - console.log( - `\tPredicted text end offset: ${result.textExtraction.textSegment.endOffset}` - ); - console.log( - `\tPredicted text score: ${result.textExtraction.score} \n` - ); - } - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_entity_predict] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/entity-extraction/undeploy-model.v1beta1.js b/automl/language/entity-extraction/undeploy-model.v1beta1.js deleted file mode 100644 index 85fc0a4a0b..0000000000 --- a/automl/language/entity-extraction/undeploy-model.v1beta1.js +++ /dev/null @@ -1,52 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'YOUR_MODEL_ID' -) { - // [START automl_language_entity_undeploy_model] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to undeploy model. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656"; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Deploy a model with the deploy model request. - client - .undeployModel({name: modelFullId}) - .then(responses => { - const response = responses[0]; - console.log(`Undeployment Details:`); - console.log(`\tName: ${response.name}`); - console.log(`\tMetadata:`); - console.log(`\t\tType Url: ${response.metadata.typeUrl}`); - console.log(`\tDone: ${response.done}`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_enitity_undeploy_model] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/create-dataset.v1beta1.js b/automl/language/sentiment-analysis/create-dataset.v1beta1.js deleted file mode 100644 index 093bb45ec7..0000000000 --- a/automl/language/sentiment-analysis/create-dataset.v1beta1.js +++ /dev/null @@ -1,67 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - datasetName = 'YOUR_DATASET_NAME', - sentimentMax = '' -) { - // [START automl_language_sentiment_create_dataset] - const automl = require('@google-cloud/automl'); - const util = require('util'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to create a dataset - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetName = '[DATASET_NAME]' e.g., "myDataset"; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - const datasetMetadata = {sentimentMax: sentimentMax}; - - // Set dataset name and metadata. - const myDataset = { - displayName: datasetName, - textSentimentDatasetMetadata: datasetMetadata, - }; - - // Create a dataset with the dataset metadata in the region. - client - .createDataset({parent: projectLocation, dataset: myDataset}) - .then(responses => { - const dataset = responses[0]; - - // Display the dataset information. - console.log(`Dataset name: ${dataset.name}`); - console.log(`Dataset Id: ${dataset.name.split(`/`).pop(-1)}`); - console.log(`Dataset display name: ${dataset.displayName}`); - console.log(`Text sentiment dataset metadata:`); - console.log( - `\t${util.inspect(dataset.textSentimentDatasetMetadata, false, null)}` - ); - console.log(`Dataset example count: ${dataset.exampleCount}`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_create_dataset] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/create-model.v1beta1.js b/automl/language/sentiment-analysis/create-model.v1beta1.js deleted file mode 100644 index dc430a23bc..0000000000 --- a/automl/language/sentiment-analysis/create-model.v1beta1.js +++ /dev/null @@ -1,58 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - datasetId = 'YOUR_DATASET_ID', - modelName = 'YOUR_MODEL_NAME' -) { - // [START automl_language_sentiment_create_model] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to create a model. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetId = '[DATASET_ID]' e.g., "TST8051890775971069952"; - // const modelName = '[MODEL_NAME]' e.g., "myModel"; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // Set model name, dataset Id and model metadata for the dataset. - const myModel = { - displayName: modelName, - datasetId: datasetId, - textSentimentModelMetadata: {}, - }; - - // Create a model with the model metadata in the region. - client - .createModel({parent: projectLocation, model: myModel}) - .then(responses => { - const initialApiResponse = responses[1]; - console.log(`Training operation name: ${initialApiResponse.name}`); - console.log(`Training started...`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_create_model] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/delete-dataset.v1beta1.js b/automl/language/sentiment-analysis/delete-dataset.v1beta1.js deleted file mode 100644 index a37032fba5..0000000000 --- a/automl/language/sentiment-analysis/delete-dataset.v1beta1.js +++ /dev/null @@ -1,58 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - datasetId = 'YOUR_DATASET_ID' -) { - // [START automl_language_sentiment_delete_dataset] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to delete a dataset. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetId = '[DATASET_ID]' e.g., "TST8051890775971069952"; - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId); - - // Delete a dataset. - client - .deleteDataset({name: datasetFullId}) - .then(responses => { - const operation = responses[0]; - return operation.promise(); - }) - .then(responses => { - // The final result of the operation. - const operationDetails = responses[2]; - - // Get the Dataset delete details. - console.log('Dataset delete details:'); - console.log(`\tOperation details:`); - console.log(`\t\tName: ${operationDetails.name}`); - console.log(`\t\tDone: ${operationDetails.done}`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_delete_dataset] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/delete-model.v1beta1.js b/automl/language/sentiment-analysis/delete-model.v1beta1.js deleted file mode 100644 index d2175c84e3..0000000000 --- a/automl/language/sentiment-analysis/delete-model.v1beta1.js +++ /dev/null @@ -1,58 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'YOUR_MODEL_ID' -) { - // [START automl_language_sentiment_delete_model] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to delete a model. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TST5200971474357190656"; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Delete a model. - client - .deleteModel({name: modelFullId}) - .then(responses => { - const operation = responses[0]; - return operation.promise(); - }) - .then(responses => { - // The final result of the operation. - const operationDetails = responses[2]; - - // Get the Model delete details. - console.log('Model delete details:'); - console.log(`\tOperation details:`); - console.log(`\t\tName: ${operationDetails.name}`); - console.log(`\t\tDone: ${operationDetails.done}`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_delete_model] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/deploy-model.v1beta1.js b/automl/language/sentiment-analysis/deploy-model.v1beta1.js deleted file mode 100644 index f5bfed0dd1..0000000000 --- a/automl/language/sentiment-analysis/deploy-model.v1beta1.js +++ /dev/null @@ -1,52 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'MODEL_ID' -) { - // [START automl_language_sentiment_deploy_model] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to deploy model. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TST5200971474357190656"; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Deploy a model with the deploy model request. - client - .deployModel({name: modelFullId}) - .then(responses => { - const response = responses[0]; - console.log(`Deployment Details:`); - console.log(`\tName: ${response.name}`); - console.log(`\tMetadata:`); - console.log(`\t\tType Url: ${response.metadata.typeUrl}`); - console.log(`\tDone: ${response.done}`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_deploy_model] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/display-evaluation.v1beta1.js b/automl/language/sentiment-analysis/display-evaluation.v1beta1.js deleted file mode 100644 index 917fea1525..0000000000 --- a/automl/language/sentiment-analysis/display-evaluation.v1beta1.js +++ /dev/null @@ -1,143 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'MODEL_ID', - filter = 'FILTER_EXPRESSION' -) { - // [START automl_language_sentiment_display_evaluation] - const automl = require('@google-cloud/automl'); - const math = require('mathjs'); - const util = require('util'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to display model evaluation. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656"; - // const filter_ = '[FILTER_EXPRESSIONS]' - // e.g., "textSentimentModelMetadata:*"; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // List all the model evaluations in the model by applying filter. - client - .listModelEvaluations({parent: modelFullId, filter: filter}) - .then(respond => { - const response = respond[0]; - // Iterate through the results. - let modelEvaluationId = ``; - for (const element of response) { - // There is evaluation for each class in a model and for overall model. - // Get only the evaluation of overall model. - if (!element.annotationSpecId) { - modelEvaluationId = element.name.split(`/`).pop(-1); - } - } - console.log(`Model Evaluation ID:`, modelEvaluationId); - - // Resource name for the model evaluation. - const modelEvaluationFullId = client.modelEvaluationPath( - projectId, - computeRegion, - modelId, - modelEvaluationId - ); - - // Get a model evaluation. - client - .getModelEvaluation({name: modelEvaluationFullId}) - .then(responses => { - const modelEvaluation = responses[0]; - - const sentimentMetrics = - modelEvaluation.textSentimentEvaluationMetrics; - const confusionMatrix = sentimentMetrics.confusionMatrix; - - console.log( - `Model precision: ${math.round( - sentimentMetrics.precision * 100, - 2 - )} %` - ); - console.log( - `Model recall: ${math.round(sentimentMetrics.recall * 100, 2)} %` - ); - console.log( - `Model f1 score: ${math.round(sentimentMetrics.f1Score * 100, 2)} %` - ); - console.log( - `Model mean absolute error: ${math.round( - sentimentMetrics.meanAbsoluteError * 100, - 2 - )} %` - ); - console.log( - `Model mean squared error: ${math.round( - sentimentMetrics.meanSquaredError * 100, - 2 - )} %` - ); - console.log( - `Model linear kappa: ${math.round( - sentimentMetrics.linearKappa * 100, - 2 - )} %` - ); - console.log( - `Model quadratic kappa: ${math.round( - sentimentMetrics.quadraticKappa * 100, - 2 - )} %` - ); - - console.log(`Model confusion matrix:`); - const annotationSpecIdList = confusionMatrix.annotationSpecId; - - for (const annotationSpecId of annotationSpecIdList) { - console.log(`\tAnnotation spec Id: ${annotationSpecId}`); - } - const rowList = confusionMatrix.row; - - for (const row of rowList) { - console.log(`\tRow:`); - const exampleCountList = row.exampleCount; - - for (const exampleCount of exampleCountList) { - console.log( - `\t\tExample count: ${util.inspect(exampleCount, false, null)}` - ); - } - } - console.log( - `Annotation spec Id: ${sentimentMetrics.annotationSpecId}` - ); - }) - .catch(err => { - console.error(err); - }); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_display_evaluation] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/export-data.v1beta1.js b/automl/language/sentiment-analysis/export-data.v1beta1.js deleted file mode 100644 index 0742f03d42..0000000000 --- a/automl/language/sentiment-analysis/export-data.v1beta1.js +++ /dev/null @@ -1,71 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - datasetId = 'YOUR_DATASET_ID', - gcsOutputUri = '' -) { - // [START automl_language_sentiment_export_data] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to export a dataset to a - * Google Cloud Storage bucket. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetId = '[DATASET_ID]' e.g., "TST8051890775971069952"; - // const gcsOutputUri = '[GCS_OUTPUT_URI]' - // e.g., "gs:///", - // `Google Cloud Storage URI for the export directory`; - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId); - - // Set the output URI - const outputConfig = { - gcsDestination: { - outputUriPrefix: gcsOutputUri, - }, - }; - - // Export the data to the output URI. - client - .exportData({name: datasetFullId, outputConfig: outputConfig}) - .then(responses => { - const operation = responses[0]; - console.log(`Processing export...`); - return operation.promise(); - }) - .then(responses => { - // The final result of the operation. - const operationDetails = responses[2]; - - // Get the data export details. - console.log('Data export details:'); - console.log(`\tOperation details:`); - console.log(`\t\tName: ${operationDetails.name}`); - console.log(`\t\tDone: ${operationDetails.done}`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_export_data] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/get-dataset.v1beta1.js b/automl/language/sentiment-analysis/get-dataset.v1beta1.js deleted file mode 100644 index 53958ba612..0000000000 --- a/automl/language/sentiment-analysis/get-dataset.v1beta1.js +++ /dev/null @@ -1,58 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - datasetId = 'YOUR_DATASET_ID' -) { - // [START automl_language_sentiment_get_dataset] - const automl = require('@google-cloud/automl'); - const util = require('util'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to get a dataset by ID. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetId = '[DATASET_ID]' e.g., "TST8051890775971069952"; - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId); - - // Get all the information about a given dataset. - client - .getDataset({name: datasetFullId}) - .then(responses => { - const dataset = responses[0]; - - // Display the dataset information. - console.log(`Dataset name: ${dataset.name}`); - console.log(`Dataset Id: ${dataset.name.split(`/`).pop(-1)}`); - console.log(`Dataset display name: ${dataset.displayName}`); - console.log(`Text sentiment dataset metadata:`); - console.log( - `\t${util.inspect(dataset.textSentimentDatasetMetadata, false, null)}` - ); - console.log(`Dataset example count: ${dataset.exampleCount}`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_get_dataset] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/get-model-evaluation.v1beta1.js b/automl/language/sentiment-analysis/get-model-evaluation.v1beta1.js deleted file mode 100644 index 01b279ca35..0000000000 --- a/automl/language/sentiment-analysis/get-model-evaluation.v1beta1.js +++ /dev/null @@ -1,138 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'MODEL_ID', - modelEvaluationId = 'MODEL_EVALUATION_ID' -) { - // [START automl_language_sentiment_get_model_evaluation] - const automl = require('@google-cloud/automl'); - const math = require('mathjs'); - const util = require('util'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to get model evaluations. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656"; - // const modelEvaluationId = '[MODEL_EVALUATION_ID]' - // e.g., "3806191078210741236"; - - // Get the full path of the model evaluation. - const modelEvaluationFullId = client.modelEvaluationPath( - projectId, - computeRegion, - modelId, - modelEvaluationId - ); - - // Get complete detail of the model evaluation. - client - .getModelEvaluation({name: modelEvaluationFullId}) - .then(responses => { - const response = responses[0]; - - const sentimentMetrics = response.textSentimentEvaluationMetrics; - const confusionMatrix = sentimentMetrics.confusionMatrix; - - // Display the model evaluations information. - console.log(`\nModel evaluation name: ${response.name}`); - console.log( - `Model evaluation Id: ${response.name - .split(`/`) - .slice(-1) - .pop()}` - ); - console.log( - `Model evaluation annotation spec Id: ${response.annotationSpecId}` - ); - console.log(`Model evaluation display name: ${response.displayName}`); - console.log( - `Model evaluation example count: ${response.evaluatedExampleCount}` - ); - console.log(`Text sentiment evaluation metrics:`); - console.log( - `\tModel precision: ${math.round( - sentimentMetrics.precision * 100, - 2 - )} %` - ); - console.log( - `\tModel recall: ${math.round(sentimentMetrics.recall * 100, 2)} %` - ); - console.log( - `\tModel f1 score: ${math.round(sentimentMetrics.f1Score * 100, 2)} %` - ); - - if (!response.annotationSpecId) { - console.log( - `\tModel mean absolute error: ${math.round( - sentimentMetrics.meanAbsoluteError * 100, - 2 - )} %` - ); - console.log( - `\tModel mean squared error: ${math.round( - sentimentMetrics.meanSquaredError * 100, - 2 - )} %` - ); - console.log( - `\tModel linear kappa: ${math.round( - sentimentMetrics.linearKappa * 100, - 2 - )} %` - ); - console.log( - `\tModel quadratic kappa: ${math.round( - sentimentMetrics.quadraticKappa * 100, - 2 - )} %` - ); - - console.log(`\tModel confusion matrix:`); - const annotationSpecIdList = confusionMatrix.annotationSpecId; - - for (const annotationSpecId of annotationSpecIdList) { - console.log(`\t\tAnnotation spec Id: ${annotationSpecId}`); - } - const rowList = confusionMatrix.row; - - for (const row of rowList) { - console.log(`\t\tRow:`); - const exampleCountList = row.exampleCount; - - for (const exampleCount of exampleCountList) { - console.log( - `\t\t\tExample count: ${util.inspect(exampleCount, false, null)}` - ); - } - } - console.log( - `\tAnnotation spec Id: ${sentimentMetrics.annotationSpecId}` - ); - } - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_get_model_evaluation] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/get-model.v1beta1.js b/automl/language/sentiment-analysis/get-model.v1beta1.js deleted file mode 100644 index 9ac2473d60..0000000000 --- a/automl/language/sentiment-analysis/get-model.v1beta1.js +++ /dev/null @@ -1,66 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'YOUR_MODEL_ID' -) { - // [START automl_language_sentiment_get_model] - const automl = require('@google-cloud/automl'); - const util = require('util'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to get model details. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TST5200971474357190656"; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Get complete detail of the model. - client - .getModel({name: modelFullId}) - .then(responses => { - const model = responses[0]; - - // Display the model information. - console.log(`Model name: ${model.name}`); - console.log(`Model Id: ${model.name.split(`/`).pop(-1)}`); - console.log(`Model display name: ${model.displayName}`); - console.log(`Dataset Id: ${model.datasetId}`); - - if (model.modelMetadata === `textSentimentModelMetadata`) { - console.log( - `TextSentimentModelMetadata: ${util.inspect( - model.textSentimentModelMetadata, - false, - null - )}` - ); - } - - console.log(`Model deployment state: ${model.deploymentState}`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_get_model] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/get-operation-status.v1beta1.js b/automl/language/sentiment-analysis/get-operation-status.v1beta1.js deleted file mode 100644 index a857bcb5e1..0000000000 --- a/automl/language/sentiment-analysis/get-operation-status.v1beta1.js +++ /dev/null @@ -1,56 +0,0 @@ -// 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 -// -// https://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'; -async function main(operationFullId = 'OPERATION_FULL_ID') { - // [START automl_language_sentiment_get_operation_status] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to get operation status. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const operationFullId = '[OPERATION_FULL_ID]' - // eg., "projects//locations/us-central1/operations/", - // `Full name of an operation`; - - // Get the latest state of a long-running operation. - client.operationsClient - .getOperation({name: operationFullId}) - .then(responses => { - const response = responses[0]; - console.log(`Operation details:`); - console.log(`\tName: ${response.name}`); - console.log(`\tMetadata:`); - console.log(`\t\tType Url: ${response.metadata.typeUrl}`); - console.log(`\tDone: ${response.done}`); - - if (response.response) { - console.log(`\tResponse:`); - console.log(`\t\tType Url: ${response.response.typeUrl}`); - } - - if (response.error) { - console.log(`\tResponse:`); - console.log(`\t\tError code: ${response.error.code}`); - console.log(`\t\tError message: ${response.error.message}`); - } - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_get_operation_status] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/import-data.v1beta1.js b/automl/language/sentiment-analysis/import-data.v1beta1.js deleted file mode 100644 index 9e7689f1d0..0000000000 --- a/automl/language/sentiment-analysis/import-data.v1beta1.js +++ /dev/null @@ -1,70 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - datasetId = 'YOUR_DATASET_ID', - gcsPath = 'YOUR_GCS_PATH' -) { - // [START automl_language_sentiment_importData] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to import labeled items. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetId = '[DATASET_ID]' e.g., "TST8051890775971069952"; - // const gcsPath = '[GCS_PATH]' e.g., "gs:///", - // `.csv paths in AutoML Natural Language Sentiment CSV format`; - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId); - - // Get the multiple Google Cloud Storage URIs. - const inputUris = gcsPath.split(`,`); - const inputConfig = { - gcsSource: { - inputUris: inputUris, - }, - }; - - // Import the data from the input URI. - client - .importData({name: datasetFullId, inputConfig: inputConfig}) - .then(responses => { - const operation = responses[0]; - console.log(`Processing import...`); - return operation.promise(); - }) - .then(responses => { - // The final result of the operation. - const operationDetails = responses[2]; - - // Get the data import details. - console.log('Data import details:'); - console.log(`\tOperation details:`); - console.log(`\t\tName: ${operationDetails.name}`); - console.log(`\t\tDone: ${operationDetails.done}`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_importData] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/list-datasets.v1beta1.js b/automl/language/sentiment-analysis/list-datasets.v1beta1.js deleted file mode 100644 index 373c224f46..0000000000 --- a/automl/language/sentiment-analysis/list-datasets.v1beta1.js +++ /dev/null @@ -1,66 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - filter = 'YOUR_FILTER_EXPRESSION' -) { - // [START automl_language_sentiment_listDatasets] - const automl = require('@google-cloud/automl'); - const util = require('util'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to list all datasets. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const filter = '[FILTER_EXPRESSIONS]' - // e.g., "textSentimentDatasetMetadata:*"; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // List all the datasets available in the region by applying filter. - client - .listDatasets({parent: projectLocation, filter: filter}) - .then(responses => { - const dataset = responses[0]; - - // Display the dataset information. - console.log(`List of datasets:`); - for (let i = 0; i < dataset.length; i++) { - console.log(`\nDataset name: ${dataset[i].name}`); - console.log(`Dataset Id: ${dataset[i].name.split(`/`).pop(-1)}`); - console.log(`Dataset display name: ${dataset[i].displayName}`); - console.log(`Text sentiment dataset metadata:`); - console.log( - `\t${util.inspect( - dataset[i].textSentimentDatasetMetadata, - false, - null - )}` - ); - console.log(`Dataset example count: ${dataset[i].exampleCount}`); - } - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_listDatasets] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/list-model-evaluations.v1beta1.js b/automl/language/sentiment-analysis/list-model-evaluations.v1beta1.js deleted file mode 100644 index 8752d1c31d..0000000000 --- a/automl/language/sentiment-analysis/list-model-evaluations.v1beta1.js +++ /dev/null @@ -1,138 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'YOUR_MODEL_ID', - filter = 'FILTER_EXPRESSION' -) { - // [START automl_language_sentiment_list_model_evaluations] - const automl = require('@google-cloud/automl'); - const math = require('mathjs'); - const util = require('util'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to list model evaluations. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TST5200971474357190656"; - // const filter_ = '[FILTER_EXPRESSIONS]' - // e.g., "textSentimentModelMetadata:*"; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // List all the model evaluations in the model by applying filter. - client - .listModelEvaluations({parent: modelFullId, filter: filter}) - .then(responses => { - const element = responses[0]; - console.log(`List of model evaluations:`); - for (let i = 0; i < element.length; i++) { - const sentimentMetrics = element[i].textSentimentEvaluationMetrics; - const confusionMatrix = sentimentMetrics.confusionMatrix; - - // Display the model evaluations information. - console.log(`\nModel evaluation name: ${element[i].name}`); - console.log( - `Model evaluation Id: ${element[i].name - .split(`/`) - .slice(-1) - .pop()}` - ); - console.log( - `Model evaluation annotation spec Id: ${element[i].annotationSpecId}` - ); - console.log(`Model evaluation display name: ${element[i].displayName}`); - console.log( - `Model evaluation example count: ${element[i].evaluatedExampleCount}` - ); - console.log(`Text sentiment evaluation metrics:`); - console.log( - `\tModel precision: ${math.round( - sentimentMetrics.precision * 100, - 2 - )} %` - ); - console.log( - `\tModel recall: ${math.round(sentimentMetrics.recall * 100, 2)} %` - ); - console.log( - `\tModel f1 score: ${math.round(sentimentMetrics.f1Score * 100, 2)} %` - ); - if (!element[i].annotationSpecId) { - console.log( - `\tModel mean absolute error: ${math.round( - sentimentMetrics.meanAbsoluteError * 100, - 2 - )} %` - ); - console.log( - `\tModel mean squared error: ${math.round( - sentimentMetrics.meanSquaredError * 100, - 2 - )} %` - ); - console.log( - `\tModel linear kappa: ${math.round( - sentimentMetrics.linearKappa * 100, - 2 - )} %` - ); - console.log( - `\tModel quadratic kappa: ${math.round( - sentimentMetrics.quadraticKappa * 100, - 2 - )} %` - ); - - console.log(`\tModel confusion matrix:`); - const annotationSpecIdList = confusionMatrix.annotationSpecId; - - for (const annotationSpecId of annotationSpecIdList) { - console.log(`\t\tAnnotation spec Id: ${annotationSpecId}`); - } - const rowList = confusionMatrix.row; - - for (const row of rowList) { - console.log(`\t\tRow:`); - const exampleCountList = row.exampleCount; - - for (const exampleCount of exampleCountList) { - console.log( - `\t\t\tExample count: ${util.inspect( - exampleCount, - false, - null - )}` - ); - } - } - console.log( - `\tAnnotation spec Id: ${sentimentMetrics.annotationSpecId}` - ); - } - } - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_list_model_evaluations] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/list-models.v1beta1.js b/automl/language/sentiment-analysis/list-models.v1beta1.js deleted file mode 100644 index c10a700b79..0000000000 --- a/automl/language/sentiment-analysis/list-models.v1beta1.js +++ /dev/null @@ -1,69 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - filter = 'FILTER_EXPRESSIONS' -) { - // [START automl_language_sentiment_list_models] - const automl = require('@google-cloud/automl'); - const util = require('util'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to list all models. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const filter_ = '[FILTER_EXPRESSIONS]' - // e.g., "textSentimentModelMetadata:*"; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // List all the models available in the region by applying filter. - client - .listModels({parent: projectLocation, filter: filter}) - .then(responses => { - const model = responses[0]; - - // Display the model information. - console.log(`List of models:`); - for (let i = 0; i < model.length; i++) { - console.log(`\nModel name: ${model[i].name}`); - console.log(`Model Id: ${model[i].name.split(`/`).pop(-1)}`); - console.log(`Model display name: ${model[i].displayName}`); - console.log(`Dataset Id: ${model[i].datasetId}`); - - if (model[i].modelMetadata === `textSentimentModelMetadata`) { - console.log( - `TextSentimentModelMetadata: ${util.inspect( - model[i].textSentimentModelMetadata, - false, - null - )}` - ); - } - console.log(`Model deployment state: ${model[i].deploymentState}`); - } - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_list_models] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/list-operation-status.v1beta1.js b/automl/language/sentiment-analysis/list-operation-status.v1beta1.js deleted file mode 100644 index 091c796f40..0000000000 --- a/automl/language/sentiment-analysis/list-operation-status.v1beta1.js +++ /dev/null @@ -1,65 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - filter = 'FILTER_EXPRESSIONS' -) { - // [START automl_language_sentiment_list_operations_status] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const filter = '[FILTER_EXPRESSIONS]'; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // List all the operations available in the region by applying filter. - client.operationsClient - .listOperations({name: projectLocation, filter: filter}) - .then(responses => { - const response = responses[0]; - console.log(`List of operations:`); - for (let i = 0; i < response.length; i++) { - console.log(`\n\tOperation details:`); - console.log(`\t\tName: ${response[i].name}`); - console.log(`\t\tMetadata:`); - console.log(`\t\t\tType Url: ${response[i].metadata.typeUrl}`); - console.log(`\t\tDone: ${response[i].done}`); - - if (response[i].response) { - console.log(`\t\tResponse:`); - console.log(`\t\t\tType Url: ${response[i].response.typeUrl}`); - } - - if (response[i].error) { - console.log(`\t\tResponse:`); - console.log(`\t\t\tError code: ${response[i].error.code}`); - console.log(`\t\t\tError message: ${response[i].error.message}`); - } - } - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_list_operations_status] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/predict.v1beta1.js b/automl/language/sentiment-analysis/predict.v1beta1.js deleted file mode 100644 index 368a9a46cd..0000000000 --- a/automl/language/sentiment-analysis/predict.v1beta1.js +++ /dev/null @@ -1,75 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'YOUR_MODEL_ID', - filePath = 'LOCAL_FILE_PATH' -) { - // [START automl_language_sentiment_predict] - const automl = require('@google-cloud/automl'); - const fs = require('fs'); - - // Create client for prediction service. - const client = new automl.v1beta1.PredictionServiceClient(); - - /** - * Demonstrates using the AutoML client to detect the content sentiment. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TST5200971474357190656"; - // const filePath = '[LOCAL_FILE_PATH]' e.g., "./resource/sentimentInput.txt", - // `local text file path of content to be predicted`; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Read the file content for prediction. - 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`, - }, - }; - - // Params is additional domain-specific parameters. - // Currently there is no additional parameters supported. - client - .predict({name: modelFullId, payload: payload, params: {}}) - .then(responses => { - console.log(`Prediction results:`); - for (const result of responses[0].payload) { - console.log( - `\tPredicted sentiment label: ${result.textSentiment.sentiment}` - ); - } - if (responses[0].metadata.sentiment_score) { - console.log( - `\tNormalized sentiment score: ${responses[0].metadata.sentiment_score}` - ); - } - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_predict] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/language/sentiment-analysis/undeploy-model.v1beta1.js b/automl/language/sentiment-analysis/undeploy-model.v1beta1.js deleted file mode 100644 index 75038e2a40..0000000000 --- a/automl/language/sentiment-analysis/undeploy-model.v1beta1.js +++ /dev/null @@ -1,52 +0,0 @@ -// 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 -// -// https://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'; -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'MODEL_ID' -) { - // [START automl_language_sentiment_undeploy_model] - const automl = require('@google-cloud/automl'); - const client = new automl.v1beta1.AutoMlClient(); - - /** - * Demonstrates using the AutoML client to undeploy model. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TST5200971474357190656"; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Undeploy a model with the undeploy model request. - client - .undeployModel({name: modelFullId}) - .then(responses => { - const response = responses[0]; - console.log(`Undeployment Details:`); - console.log(`\tName: ${response.name}`); - console.log(`\tMetadata:`); - console.log(`\t\tType Url: ${response.metadata.typeUrl}`); - console.log(`\tDone: ${response.done}`); - }) - .catch(err => { - console.error(err); - }); - // [END automl_language_sentiment_undeploy_model] -} -main(...process.argv.slice(2)).catch(console.error()); diff --git a/automl/test/automlLangaugeSentimentDataSet.v1beta1.test.js b/automl/test/automlLangaugeSentimentDataSet.v1beta1.test.js deleted file mode 100644 index e7eeb69c74..0000000000 --- a/automl/test/automlLangaugeSentimentDataSet.v1beta1.test.js +++ /dev/null @@ -1,74 +0,0 @@ -// 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 -// -// https://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 {describe, it} = require('mocha'); -const {execSync} = require('child_process'); - -/** Tests for AutoML Natural Language Sentiment Analysis "Dataset API" sample.*/ -const cmdDataset = 'node automlNaturalLanguageSentimentDataset.js'; - -// TODO(developer): Before running the test cases, -// set the environment variables PROJECT_ID, REGION_NAME and -// change the value of datasetId, datasetName, sentimentMax and importDataCsv. -const projectId = process.env.PROJECT_ID; -//const computeRegion = process.env.REGION_NAME; -const bucket = projectId + '-lcm'; -const datasetName = 'test_language_dataset'; -const filter = 'textSentimentDatasetMetadata:*'; -const sentimentMax = 4; -const datasetId = 'TST1814315223123098195'; -const importDataCsv = 'gs://' + projectId + '-lcm/automl-sentiment/train.csv'; - -const exec = cmd => execSync(cmd, {encoding: 'utf8'}); - -describe.skip('Language Sentiment DatasetAPI', () => { - it(`should create, import and delete a dataset`, async () => { - // Create dataset - let output = exec( - `${cmdDataset} create-dataset "${datasetName}" "${sentimentMax}"` - ); - const parsedOut = output.split('\n'); - const outputDatasetId = parsedOut[1].split(':')[1].trim(); - assert.match(output, /Dataset display name:/); - - // Import Data - output = exec( - `${cmdDataset} import-data "${outputDatasetId}" "${importDataCsv}"` - ); - assert.match(output, /Processing import.../); - - // Delete dataset - output = exec(`${cmdDataset} delete-dataset "${outputDatasetId}"`); - assert.match(output, /Dataset delete details:/); - }); - - it(`should list datasets`, async () => { - const output = exec(`${cmdDataset} list-datasets "${filter}"`); - assert.match(output, /List of datasets:/); - }); - - it(`should get preexisting dataset`, async () => { - const output = exec(`${cmdDataset} get-dataset "${datasetId}"`); - assert.match(output, /Dataset display name:/); - }); - - it(`should export dataset`, async () => { - const outputUri = 'gs://' + bucket + '/' + datasetId; - const output = exec(`${cmdDataset} export-data ${datasetId} ${outputUri}`); - assert.match(output, /Processing export.../); - }); -}); diff --git a/automl/test/automlLanguageEntityDataSet.v1beta1.test.js b/automl/test/automlLanguageEntityDataSet.v1beta1.test.js deleted file mode 100644 index 6279644030..0000000000 --- a/automl/test/automlLanguageEntityDataSet.v1beta1.test.js +++ /dev/null @@ -1,82 +0,0 @@ -// 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 -// -// https://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 {describe, it} = require('mocha'); -const {execSync} = require('child_process'); - -/** Tests for AutoML Natural Language Entity Extraction - Dataset Operations */ -// TODO(developer): Before running the test cases, -// set the environment variables PROJECT_ID, REGION_NAME and -// change the value of datasetId -const projectId = process.env.PROJECT_ID; -const computeRegion = process.env.REGION_NAME; -const bucket = projectId + '-entity'; -const datasetName = 'test_language_dataset'; -const filter = 'textExtractionDatasetMetadata:*'; -const datasetId = 'TEN1866654084614848512'; -const importDataCsv = 'gs://cloud-ml-data/NL-entity/dataset.csv'; - -const exec = cmd => execSync(cmd, {encoding: 'utf8'}); - -describe.skip(`Language Entity DatasetAPI`, () => { - it(`should create, import and delete a dataset`, async () => { - // Create dataset - let output = exec( - `node create-dataset.v1beta1.js "${projectId}" "${computeRegion}" "${datasetName}"` - ); - const parsedOut = output.split('\n'); - const outputDatasetId = parsedOut[1].split(':')[1].trim(); - assert.match(output, /Dataset display name:/); - - // Import data - output = exec( - `node import-data.v1beta1.js "${projectId}" "${computeRegion}" "${outputDatasetId}" "${importDataCsv}"` - ); - assert.match(output, /Processing import.../); - - // Delete dataset - output = exec( - `node delete-dataset.v1beta1.js "${projectId}" "${computeRegion}" "${outputDatasetId}"` - ); - assert.match(output, /Dataset delete details:/); - }); - - it(`should list datasets`, async () => { - // List datasets - const output = exec( - `node list-datasets.v1beta1.js "${projectId}" "${computeRegion}" "${filter}"` - ); - assert.match(output, /List of datasets:/); - }); - - it(`should get preexisting dataset`, async () => { - // Get dataset - const output = exec( - `node get-dataset.v1beta1.js "${projectId}" "${computeRegion}" "${datasetId}"` - ); - assert.match(output, /Dataset display name:/); - }); - - it(`should export dataset`, async () => { - // Export data - const outputUri = 'gs://' + bucket + '/' + datasetId; - const output = exec( - `node export-data.v1beta1.js "${projectId}" "${computeRegion}" "${datasetId}" "${outputUri}"` - ); - assert.match(output, /Processing export../); - }); -}); diff --git a/automl/test/automlLanguageEntityModel.v1beta1.test.js b/automl/test/automlLanguageEntityModel.v1beta1.test.js deleted file mode 100644 index dc4e440948..0000000000 --- a/automl/test/automlLanguageEntityModel.v1beta1.test.js +++ /dev/null @@ -1,125 +0,0 @@ -// 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 -// -// https://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 {describe, it} = require('mocha'); -const {execSync} = require('child_process'); - -/** Tests for AutoML Natural Language Entity Extraction "Model API" sample. */ - -// TODO(developer): Before running the test cases, -// set the environment variables PROJECT_ID, REGION_NAME and -// change the value of datasetId, deployModelId and undeployModelId -const projectId = process.env.PROJECT_ID; -const computeRegion = process.env.REGION_NAME; -const filter = 'textExtractionModelMetadata:*'; -const datasetId = 'TEN1795159440530341888'; -const testModelName = 'test_entity_model'; -const deployModelId = 'TEN8143123852797411328'; -const undeployModelId = 'TEN4279035372513525760'; - -const exec = cmd => execSync(cmd, {encoding: 'utf8'}); - -describe.skip(`Language Entity ModelAPI`, () => { - it(`should create a model`, async () => { - // Create model - let output = exec( - `node create-model.v1beta1.js "${projectId}" "${computeRegion}" "${datasetId}" "${testModelName}"` - ); - const operationName = output - .split('\n')[0] - .split(':')[1] - .trim(); - assert.match(output, /Training started.../); - - // Get operation status - // Poll operation status, here confirming that operation is not complete yet - output = exec(`node get-operation-status.v1beta1.js "${operationName}"`); - assert.match(output, /Operation details:/); - }); - - it(`should list models, get and delete a model. list, get and display model - evaluations from preexisting models`, async () => { - // List models - let output = exec( - `node list-models.v1beta1.js "${projectId}" "${computeRegion}" "${filter}"` - ); - const parsedOut = output.split('\n'); - const outputModelId = parsedOut[3].split(':')[1].trim(); - assert.match(output, /List of models:/); - - // Get model - output = exec(`node get-model.v1beta1.js "${outputModelId}"`); - assert.match(output, /Model name:/); - - // List model evaluations - output = exec( - `node list-model-evaluations.v1beta1.js "${projectId}" "${computeRegion}" "${outputModelId}"` - ); - const parsedModelEvaluation = output.split('\n'); - const modelEvaluationId = parsedModelEvaluation[3].split(':')[1].trim(); - assert.match(output, /Model evaluation Id:/); - - // Get model evaluation - output = exec( - `node get-model-evaluation.v1beta1.js "${projectId}" "${computeRegion}" "${outputModelId}" ` + - `"${modelEvaluationId}"` - ); - assert.match(output, /Model evaluation Id:/); - - // Display evaluation - output = exec( - `node display-evaluation.v1beta1.js "${projectId}" "${computeRegion}" "${outputModelId}"` - ); - assert.match(output, /Model Evaluation ID:/); - - // Delete Model - output = exec( - `node delete-model.v1beta1.js "${projectId}" "${computeRegion}" "${outputModelId}"` - ); - assert.match(output, /Model delete details:/); - }); - - it(`should list and get operation status`, async () => { - // List operation status - let output = exec( - `node list-operations-status.v1beta1.js "${projectId}" "${computeRegion}"` - ); - const parsedOut = output.split('\n'); - const operationFullId = parsedOut[3].split(':')[1].trim(); - - // Get operation status - // Poll operation status, here confirming that operation is not complete yet - output = exec(`node get-operation-status.v1beta1.js "${operationFullId}"`); - assert.match(output, /Operation details:/); - }); - - it(`should deploy the model`, async () => { - // Deploy the model - const output = exec( - `node deploy-model.v1beta1.js "${projectId}" "${computeRegion}" "${deployModelId}"` - ); - assert.match(output, /Name:/); - }); - - it(`should undeploy the model`, async () => { - // Undeploy the model - const output = exec( - `node undeploy-model.v1beta1.js "${projectId}" "${computeRegion}" "${undeployModelId}"` - ); - assert.match(output, /Name:/); - }); -}); diff --git a/automl/test/automlLanguageEntityPrediction.v1beta1.test.js b/automl/test/automlLanguageEntityPrediction.v1beta1.test.js deleted file mode 100644 index 6c15e6d6bc..0000000000 --- a/automl/test/automlLanguageEntityPrediction.v1beta1.test.js +++ /dev/null @@ -1,42 +0,0 @@ -// 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 -// -// https://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 {describe, it} = require('mocha'); -const {execSync} = require('child_process'); - -/** Tests for AutoML Natural Language Entity Extraction "Prediction API" sample. - */ - -const cmdPredict = 'node automlNaturalLanguageEntityPrediction.js'; - -// TODO(developer): Before running the test cases, -// set the environment variables PROJECT_ID, REGION_NAME and -// change the value of modelId -//const projectId = process.env.PROJECT_ID; -//const computeRegion = process.env.REGION_NAME; -const modelId = 'TEN5215784095006588928'; -const filePath = './resource/entityInput.txt'; - -const exec = cmd => execSync(cmd, {encoding: 'utf8'}); - -describe.skip(`Language Entity PredictionAPI`, () => { - it(`should run prediction from preexisting model`, async () => { - // Run prediction on 'entityInput.txt' in resource folder - const output = exec(`${cmdPredict} predict "${modelId}" "${filePath}"`); - assert.match(output, /Predicted text extract entity type:/); - }); -}); diff --git a/automl/test/automlLanguageSentimentModel.v1beta1.test.js b/automl/test/automlLanguageSentimentModel.v1beta1.test.js deleted file mode 100644 index a18c1175c9..0000000000 --- a/automl/test/automlLanguageSentimentModel.v1beta1.test.js +++ /dev/null @@ -1,114 +0,0 @@ -// 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 -// -// https://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 {describe, it} = require('mocha'); -const {execSync} = require('child_process'); - -/** Tests for AutoML Natural Language Sentiment Analysis "Model API" sample. */ - -const cmdModel = 'node automlNaturalLanguageSentimentModel.js'; - -// TODO(developer): Before running the test cases, -// set the environment variables PROJECT_ID, REGION_NAME and -// change the value of datasetId, testModelName, deployModelId and -// undeployModelId. -//const projectId = process.env.PROJECT_ID; -//const computeRegion = process.env.REGION_NAME; -const filter = 'textSentimentModelMetadata:*'; -const datasetId = 'TST8371835764813564945'; -const testModelName = 'test_sentiment_model'; -const deployModelId = 'TST1554691861054799974'; -const undeployModelId = 'TST5013860858145102878'; - -const exec = cmd => execSync(cmd, {encoding: 'utf8'}); - -describe.skip('Language Sentiment ModelAPI', () => { - it(`should create a model`, async () => { - // Create model - let output = exec( - `${cmdModel} create-model "${datasetId}" "${testModelName}"` - ); - const operationName = output - .split('\n')[0] - .split(':')[1] - .trim(); - assert.match(output, /Training started.../); - - // Get operation status - // Poll operation status, here confirming that operation is not complete yet - output = exec(`${cmdModel} get-operation-status "${operationName}"`); - assert.match(output, /Operation details:/); - }); - - it(`should list models, get and delete a model. list, get and display model - evaluations from preexisting models`, async () => { - // List models - let output = exec(`${cmdModel} list-models "${filter}"`); - const parsedOut = output.split('\n'); - const outputModelId = parsedOut[3].split(':')[1].trim(); - assert.match(output, /List of models:/); - - // Get Model - output = exec(`${cmdModel} get-model "${outputModelId}"`); - assert.match(output, /Model name:/); - - // List model evaluations - output = exec(`${cmdModel} list-model-evaluations` + ` "${outputModelId}"`); - const parsedModelEvaluation = output.split('\n'); - const modelEvaluationId = parsedModelEvaluation[3].split(':')[1].trim(); - assert.match(output, /Model evaluation Id:/); - - // Get model evaluation - output = exec( - `${cmdModel} get-model-evaluation "${outputModelId}"` + - ` "${modelEvaluationId}"` - ); - assert.match(output, /Model evaluation Id:/); - - // Display evaluation - output = exec(`${cmdModel} display-evaluation "${outputModelId}"`); - assert.match(output, /Model Evaluation ID:/); - - // Delete Model - output = exec(`${cmdModel} delete-model "${outputModelId}"`); - assert.match(output, /Model delete details:/); - }); - - it(`should deploy the model`, async () => { - // Deploy the model - const output = exec(`${cmdModel} deploy-model ${deployModelId}`); - assert.match(output, /Name:/); - }); - - it(`should undeploy the model`, async () => { - // Undeploy the model - const output = exec(`${cmdModel} undeploy-model ${undeployModelId}`); - assert.match(output, /Name:/); - }); - - it(`should list and get operation status`, async () => { - // List operation status - let output = exec(`${cmdModel} list-operations-status`); - const parsedOut = output.split('\n'); - const operationFullId = parsedOut[3].split(':')[1].trim(); - - // Get operation status - // Poll operation status, here confirming that operation is not complete yet - output = exec(`${cmdModel} get-operation-status "${operationFullId}"`); - assert.match(output, /Operation details:/); - }); -}); diff --git a/automl/test/automlLanguageSentimentPrediction.v1beta1.test.js b/automl/test/automlLanguageSentimentPrediction.v1beta1.test.js deleted file mode 100644 index 19006622c7..0000000000 --- a/automl/test/automlLanguageSentimentPrediction.v1beta1.test.js +++ /dev/null @@ -1,45 +0,0 @@ -// 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 -// -// https://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 {describe, it} = require('mocha'); -const {execSync} = require('child_process'); - -/** Tests for AutoML Natural Language Sentiment Analysis "Prediction API" - * sample. - */ - -const cmdPredict = 'node automlNaturalLanguageSentimentPrediction.js'; - -// TODO(developer): Before running the test cases, -// set the environment variables PROJECT_ID, REGION_NAME and -// change the value of modelId. -const projectId = process.env.PROJECT_ID; -const computeRegion = process.env.REGION_NAME; -const modelId = 'TST237689009065453820'; -const filePath = './resource/sentimentInput.txt'; - -const exec = cmd => execSync(cmd, {encoding: 'utf8'}); - -describe.skip('Language Sentiment PredictionAPI', () => { - it(`should run prediction from preexisting model`, async () => { - // Run prediction on 'test.txt' in resources folder - const output = exec( - `${cmdPredict} predict "${projectId}" "${computeRegion}" "${modelId}" "${filePath}"` - ); - assert.match(output, /Predicted sentiment label:/); - }); -}); diff --git a/automl/test/automlVisionObjectDetectionDataset.v1beta1.test.js b/automl/test/automlVisionObjectDetectionDataset.v1beta1.test.js deleted file mode 100644 index 5f2a171ac0..0000000000 --- a/automl/test/automlVisionObjectDetectionDataset.v1beta1.test.js +++ /dev/null @@ -1,82 +0,0 @@ -// 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 -// -// https://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 {describe, it} = require('mocha'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -/** Tests for AutoML Vision Object Detection "Dataset API" sample. */ -// TODO(developer): Before running the test cases, -// set the environment variables PROJECT_ID, REGION_NAME and -// change the value of datasetId -const projectId = 'nodejs-docs-samples'; -const computeRegion = 'us-central1'; -const outputPath = 'gs://nodejs-docs-samples/VISION_OBJECT_DETECTION/'; -const datasetName = 'test_vision_create_dataset'; -const filter = 'imageObjectDetectionDatasetMetadata:*'; -const datasetId = 'ICN3946265060617537378'; -const importDataCsv = 'gs://nodejs-docs-samples-vcm/flowerTraindata20lines.csv'; - -describe('Vision Object Detection DatasetAPI', () => { - it.skip(`should create, import and delete a dataset`, async () => { - // Create dataset - let output = await execSync( - `node vision/object-detection/create-dataset.v1beta1.js "${projectId}" "${computeRegion}" "${datasetName}"` - ); - const parsedOut = output.split('\n'); - const outputDatasetId = parsedOut[1].split(':')[1].trim(); - assert.match(output, /Dataset display name:/); - - // Import data - output = await execSync( - `node vision/object-detection/import-data.v1beta1.js "${projectId}" "${computeRegion}" "${outputDatasetId}" "${importDataCsv}"` - ); - assert.match(output, /Processing import.../); - - // Delete dataset - output = await execSync( - `node vision/object-detection/delete-dataset.v1beta1.js "${projectId}" "${computeRegion}" "${outputDatasetId}"` - ); - assert.match(output, /Dataset delete details:/); - }); - - it.skip(`should list datasets`, async () => { - // List datasets - const output = await execSync( - `node vision/object-detection/list-datasets.v1beta1.js "${projectId}" "${computeRegion}" "${filter}"` - ); - assert.match(output, /List of datasets:/); - }); - - it.skip(`should get preexisting dataset`, async () => { - // Get dataset - const output = await execSync( - `node vision/object-detection/get-dataset.v1beta1.js "${projectId}" "${computeRegion}" "${datasetId}"` - ); - assert.match(output, /Dataset display name:/); - }); - - it.skip(`should export dataset`, async () => { - // Export data - const outputUri = outputPath + datasetId; - const output = await execSync( - `node vision/object-detection/export-data.v1beta1.js "${projectId}" "${computeRegion}" "${datasetId}" "${outputUri}"` - ); - assert.match(output, /Processing export.../); - }); -}); diff --git a/automl/test/automlVisionObjectDetectionModel.v1beta1.test.js b/automl/test/automlVisionObjectDetectionModel.v1beta1.test.js deleted file mode 100644 index d976dc023d..0000000000 --- a/automl/test/automlVisionObjectDetectionModel.v1beta1.test.js +++ /dev/null @@ -1,127 +0,0 @@ -// 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 -// -// https://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 {describe, it} = require('mocha'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -/** Tests for AutoML Vision Object Detection "Model API" sample. */ -// TODO(developer): Before running the test cases, -// set the environment variables PROJECT_ID, REGION_NAME and -// change the value of datasetId, deployModelId and undeployModelId -const projectId = 'nodejs-docs-samples'; -const computeRegion = 'us-central1'; -const filter = 'imageObjectDetectionModelMetadata:*'; -const datasetId = 'ICN3217071205693347964'; -const testModelName = 'birds2_201804101601_base'; -const deployModelId = 'IOD1728502647608049664'; -const undeployModelId = 'IOD3348109663601164288'; - -describe(' Vision Object Detection ModelAPI', () => { - it.skip(`should create a model`, async () => { - let output = await execSync( - `node vision/object-detection/create-model.v1beta1.js "${projectId}" "${computeRegion}" "${datasetId}" "${testModelName}"` - ); - const operationName = output - .split('\n')[0] - .split(':')[1] - .trim(); - assert.match(output, /Training started.../); - - output = await execSync( - `node vision/object-detection/get-operation-status.v1beta1.js "${operationName}"` - ); - assert.match(output, /Operation details:/); - }); - - it.skip(`should list models, get and delete a model. list, get and display model - evaluations from preexisting models`, async () => { - // List models - let output = await execSync( - `node vision/object-detection/list-models.v1beta1.js "${projectId}" "${computeRegion}" "${filter}"` - ); - const parsedOut = output.split('\n'); - const outputModelId = parsedOut[3].split(':')[1].trim(); - assert.match(output, /List of models:/); - - // Get Model - output = await execSync( - `node vision/object-detection/get-model.v1beta1.js "${projectId}" "${computeRegion}" "${outputModelId}"` - ); - assert.match(output, /Model name:/); - - // List model evaluation - output = await execSync( - `node vision/object-detection/list-model-evaluations.v1beta1.js "${projectId}" "${computeRegion}" "${outputModelId}"` - ); - const parsedModelEvaluation = output.split('\n'); - const modelEvaluationId = parsedModelEvaluation[3].split(':')[1].trim(); - assert.match(output, /Model evaluation Id:/); - - // Get model evaluation - output = await execSync( - `node vision/object-detection/get-model-evaluation.v1beta1.js "${projectId}" "${computeRegion}" "${outputModelId}"` + - ` "${modelEvaluationId}"` - ); - assert.match(output, /Model evaluation Id:/); - - // Display evaluation - output = await execSync( - `node vision/object-detection/display-evaluation.v1beta1.js "${projectId}" "${computeRegion}" "${outputModelId}" ` - ); - assert.match(output, /Model Evaluation ID:/); - - // Delete Model - output = await execSync( - `node vision/object-detection/delete-model.v1beta1.js "${projectId}" "${computeRegion}" "${outputModelId}"` - ); - assert.match(output, /Model delete details:/); - }); - - it.skip(`should list and get operation status`, async () => { - // List operation status - let output = await execSync( - `node vision/object-detection/list-operations-status.v1beta1.js` - ); - const parsedOut = output.split('\n'); - const operationFullId = parsedOut[3].split(':')[1].trim(); - - // Get operation status - // Poll operation status, here confirming that operation is not complete yet - output = await execSync( - `node vision/object-detection/get-operation-status.v1beta1.js "${operationFullId}"` - ); - assert.match(output, /Operation details:/); - }); - - it.skip(`should deploy the model`, async () => { - // Deploy the model - const output = await execSync( - `node vision/object-detection/deploy-model.v1beta1.js "${projectId}" "${computeRegion}" ${deployModelId}` - ); - assert.match(output, /Name:/); - }); - - it.skip(`should undeploy the model`, async () => { - // Undeploy the model - const output = await execSync( - `node vision/object-detection/undeploy-model.v1beta1.js "${projectId}" "${computeRegion}" ${undeployModelId}` - ); - assert.match(output, /Name:/); - }); -}); diff --git a/automl/test/automlVisionObjectDetectionPredict.v1beta1.test.js b/automl/test/automlVisionObjectDetectionPredict.v1beta1.test.js deleted file mode 100644 index 8a4b6ec70b..0000000000 --- a/automl/test/automlVisionObjectDetectionPredict.v1beta1.test.js +++ /dev/null @@ -1,40 +0,0 @@ -// 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 -// -// https://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 {describe, it} = require('mocha'); -const {execSync} = require('child_process'); - -/** Tests for AutoML Vision Object Detection "Prediction API" sample. */ - -// TODO(developer): Before running the test cases, -// set the environment variables PROJECT_ID, REGION_NAME and change the value of modelId -const projectId = 'nodejs-docs-samples'; -const computeRegion = 'us-central1'; -const modelId = ''; -const filePath = './resource/songbird.jpg'; - -const exec = cmd => execSync(cmd, {encoding: 'utf8'}); - -describe.skip('Vision Object Detection PredictionAPI', () => { - it(`should run prediction from preexisting model`, async () => { - // Run prediction on 'salad.jpg' in resource folder - const output = exec( - `node vision/object-detection/predict.v1beta1.js "${projectId}" "${computeRegion}" "${modelId}" "${filePath}"` - ); - assert.match(output, /Prediction results:/); - }); -}); diff --git a/automl/translate/datasets/create-dataset.v1beta1.js b/automl/translate/datasets/create-dataset.v1beta1.js deleted file mode 100644 index 9e65a45b80..0000000000 --- a/automl/translate/datasets/create-dataset.v1beta1.js +++ /dev/null @@ -1,66 +0,0 @@ -// 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 -// -// https://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'; - -async function main(projectId = 'YOUR_PROJECT_ID') { - // [START automl_translation_create_dataset] - const automl = require('@google-cloud/automl'); - - const client = new automl.AutoMlClient(); - const computeRegion = 'us-central1'; - const datasetName = 'myDataset'; - const source = 'en'; - const target = 'ja'; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // Specify the source and target language. - const datasetSpec = { - sourceLanguageCode: source, - targetLanguageCode: target, - }; - - // Set dataset name and dataset specification. - const datasetInfo = { - displayName: datasetName, - translationDatasetMetadata: datasetSpec, - }; - - // Create a dataset with the dataset specification in the region. - const [dataset] = await client.createDataset({ - parent: projectLocation, - dataset: datasetInfo, - }); - - // Display the dataset information - console.log(`Dataset name: ${dataset.name}`); - 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(`Translation dataset specification:`); - console.log( - `\tSource language code: ${dataset.translationDatasetMetadata.sourceLanguageCode}` - ); - console.log( - `\tTarget language code: ${dataset.translationDatasetMetadata.targetLanguageCode}` - ); - console.log(`Dataset create time:`); - console.log(`\tseconds: ${dataset.createTime.seconds}`); - console.log(`\tnanos: ${dataset.createTime.nanos}`); - // [END automl_translation_create_dataset] -} - -main(...process.argv.slice(2)).catch(err => console.error(err)); diff --git a/automl/translate/datasets/delete-dataset.v1beta1.js b/automl/translate/datasets/delete-dataset.v1beta1.js deleted file mode 100644 index fba606f4c7..0000000000 --- a/automl/translate/datasets/delete-dataset.v1beta1.js +++ /dev/null @@ -1,45 +0,0 @@ -// 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 -// -// https://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'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION', - datasetId = 'YOUR_DATASET' -) { - // [START automl_translation_delete_dataset] - const automl = require('@google-cloud/automl'); - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const datasetId = `Id of the dataset`; - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId); - - // Delete a dataset. - const [operations] = await client.deleteDataset({name: datasetFullId}); - const operationResponses = await operations.promise(); - // The final result of the operation. - if (operationResponses[2].done === true) console.log(`Dataset deleted.`); - - // [END automl_translation_delete_dataset] -} - -main(...process.argv.slice(2)).catch(err => console.error(err)); diff --git a/automl/translate/datasets/get-dataset.v1beta1.js b/automl/translate/datasets/get-dataset.v1beta1.js deleted file mode 100644 index 279e19d860..0000000000 --- a/automl/translate/datasets/get-dataset.v1beta1.js +++ /dev/null @@ -1,58 +0,0 @@ -// 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 -// -// https://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'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION', - datasetId = 'YOUR_DATASET' -) { - // [START automl_translation_get_dataset] - const automl = require('@google-cloud/automl'); - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const datasetId = `Id of the dataset`; - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId); - - // Get complete detail of the dataset. - 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 display name: ${dataset.displayName}`); - console.log(`Dataset example count: ${dataset.exampleCount}`); - console.log(`Translation dataset specification:`); - console.log( - `\tSource language code: ${dataset.translationDatasetMetadata.sourceLanguageCode}` - ); - console.log( - `\tTarget language code: ${dataset.translationDatasetMetadata.targetLanguageCode}` - ); - console.log(`Dataset create time:`); - console.log(`\tseconds: ${dataset.createTime.seconds}`); - console.log(`\tnanos: ${dataset.createTime.nanos}`); - - // [END automl_translation_get_dataset] -} - -main(...process.argv.slice(2)).catch(err => console.error(err)); diff --git a/automl/translate/datasets/import-data.v1beta1.js b/automl/translate/datasets/import-data.v1beta1.js deleted file mode 100644 index 57bd6b1a05..0000000000 --- a/automl/translate/datasets/import-data.v1beta1.js +++ /dev/null @@ -1,62 +0,0 @@ -// 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 -// -// https://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'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION', - datasetId = 'YOUR_DATASET', - path = 'YOUR_PATH' -) { - // [START automl_translation_import_data] - const automl = require('@google-cloud/automl'); - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const datasetId = `Id of the dataset`; - // const path = `string or array of .csv paths in AutoML Vision CSV format, e.g. “gs://myproject/mytraindata.csv”;` - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath(projectId, computeRegion, datasetId); - - // Get the multiple Google Cloud Storage URIs. - const inputUris = path.split(`,`); - const inputConfig = { - gcsSource: { - inputUris: inputUris, - }, - }; - - // Import data from the input URI. - const [operation] = await client.importData({ - name: datasetFullId, - inputConfig: inputConfig, - }); - console.log(`Processing import...`); - const operationResponses = await operation.promise(); - // The final result of the operation. - if (operationResponses[2].done === true) { - console.log(`Data imported.`); - } - - // [END automl_translation_import_data] -} - -main(...process.argv.slice(2)).catch(err => console.error(err)); diff --git a/automl/translate/datasets/list-datasets.v1beta1.js b/automl/translate/datasets/list-datasets.v1beta1.js deleted file mode 100644 index 781f02e24c..0000000000 --- a/automl/translate/datasets/list-datasets.v1beta1.js +++ /dev/null @@ -1,67 +0,0 @@ -// 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 -// -// https://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'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION_NAME', - filter = 'YOUR_FILTER' -) { - // [START automl_translation_list_datasets] - const automl = require('@google-cloud/automl'); - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const filter = `filter expressions, must specify field e.g. “imageClassificationModelMetadata:*”`; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // List all the datasets available in the region by applying filter. - const [datasets] = await client.listDatasets({ - parent: projectLocation, - filter: filter, - }); - - // Display the dataset information. - if (datasets.length === 0) { - console.log('No datasets found!'); - return; - } - 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 display name: ${dataset.displayName}`); - console.log(`Dataset example count: ${dataset.exampleCount}`); - console.log(`Translation dataset specification:`); - console.log( - `\tSource language code: ${dataset.translationDatasetMetadata.sourceLanguageCode}` - ); - console.log( - `\tTarget language code: ${dataset.translationDatasetMetadata.targetLanguageCode}` - ); - console.log(`Dataset create time:`); - console.log(`\tseconds: ${dataset.createTime.seconds}`); - console.log(`\tnanos: ${dataset.createTime.nanos}`); - }); - // [END automl_translation_list_datasets] -} - -main(...process.argv.slice(2)).catch(err => console.error(err)); diff --git a/automl/translate/models/create-model.v1beta1.js b/automl/translate/models/create-model.v1beta1.js deleted file mode 100644 index 41ade8e44e..0000000000 --- a/automl/translate/models/create-model.v1beta1.js +++ /dev/null @@ -1,77 +0,0 @@ -// 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 -// -// https://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'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION', - datasetId = 'YOUR_DATASET', - modelName = 'YOUR_MODEL' -) { - // [START automl_translation_create_model] - const automl = require('@google-cloud/automl'); - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const datasetId = `Id of the dataset`; - // const modelName = `Name of the model, e.g. "myModel"`; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // Set model name and dataset. - const myModel = { - displayName: modelName, - datasetId: datasetId, - translationModelMetadata: {}, - }; - - // Create a model with the model metadata in the region. - const [operation, response] = await client.createModel({ - parent: projectLocation, - model: myModel, - }); - const initialApiResponse = response; - console.log(`Training operation name: `, initialApiResponse.name); - console.log(`Training started...`); - const [model] = await operation.promise(); - // The final result of the operation. - console.log(model); - // Retrieve deployment state. - let deploymentState = ``; - if (model.deploymentState === 1) { - deploymentState = `deployed`; - } else if (model.deploymentState === 2) { - deploymentState = `undeployed`; - } - - // Display the model information. - console.log(`Model name: ${model.name}`); - console.log(`Model id: ${model.name.split(`/`).pop(-1)}`); - console.log(`Model display name: ${model.displayName}`); - console.log(`Model create time:`); - console.log(`\tseconds: ${model.createTime.seconds}`); - console.log(`\tnanos: ${model.createTime.nanos}`); - console.log(`Model deployment state: ${deploymentState}`); - - // [END automl_translation_create_model] -} - -main(...process.argv.slice(2)).catch(err => console.error(err)); diff --git a/automl/translate/models/delete-model.v1beta1.js b/automl/translate/models/delete-model.v1beta1.js deleted file mode 100644 index fdca32314d..0000000000 --- a/automl/translate/models/delete-model.v1beta1.js +++ /dev/null @@ -1,46 +0,0 @@ -// 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 -// -// https://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'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION', - modelId = 'YOUR_MODEL' -) { - // [START automl_translation_delete_model] - const automl = require('@google-cloud/automl'); - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const modelId = `id of the model, e.g. “ICN12345”`; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Delete a model. - const [operation] = await client.deleteModel({name: modelFullId}); - const operationResponse = await operation.promise(); - // The final result of the operation. - if (operationResponse[2].done === true) console.log(`Model deleted.`); - - // [END automl_translation_delete_model] -} - -main(...process.argv.slice(2)).catch(err => console.error(err)); diff --git a/automl/translate/models/get-model-evaluation.v1beta1.js b/automl/translate/models/get-model-evaluation.v1beta1.js deleted file mode 100644 index d42cc8e163..0000000000 --- a/automl/translate/models/get-model-evaluation.v1beta1.js +++ /dev/null @@ -1,52 +0,0 @@ -// 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 -// -// https://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'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION', - modelId = 'YOUR_MODEL', - modelEvaluationId = 'YOUR_EVALUATION_ID' -) { - // [START automl_translation_get_model_evaluation] - const automl = require('@google-cloud/automl'); - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const modelId = `id of the model, e.g. “ICN12345”`; - // const modelEvaluationId = `Id of your model evaluation, e.g “ICN12345” - - // Get the full path of the model evaluation. - const modelEvaluationFullId = client.modelEvaluationPath( - projectId, - computeRegion, - modelId, - modelEvaluationId - ); - - // Get complete detail of the model evaluation. - const [response] = await client.getModelEvaluation({ - name: modelEvaluationFullId, - }); - console.log(response); - - // [END automl_translation_get_model_evaluation] -} - -main(...process.argv.slice(2)).catch(err => console.error(err)); diff --git a/automl/translate/models/get-model.v1beta1.js b/automl/translate/models/get-model.v1beta1.js deleted file mode 100644 index 4678a31581..0000000000 --- a/automl/translate/models/get-model.v1beta1.js +++ /dev/null @@ -1,84 +0,0 @@ -// 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 -// -// https://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'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION', - modelId = 'YOUR_MODEL' -) { - // [START automl_translation_get_model] - const automl = require('@google-cloud/automl'); - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const modelId = `id of the model, e.g. “ICN12345”`; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Get complete detail of the model. - const [model] = await client.getModel({name: modelFullId}); - - // Display the model information. - console.log(`Model name: ${model.name}`); - 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:`); - console.log(`\tBase model: ${model.translationModelMetadata.baseModel}`); - console.log( - `\tSource language code: ${model.translationModelMetadata.sourceLanguageCode}` - ); - console.log( - `\tTarget language code: ${model.translationModelMetadata.targetLanguageCode}` - ); - } else if (model.modelMetadata === `textClassificationModelMetadata`) { - console.log( - `Text classification model metadata: ${model.textClassificationModelMetadata}` - ); - } else if (model.modelMetadata === `imageClassificationModelMetadata`) { - console.log(`Image classification model metadata:`); - console.log( - `\tBase model id: ${model.imageClassificationModelMetadata.baseModelId}` - ); - console.log( - `\tTrain budget: ${model.imageClassificationModelMetadata.trainBudget}` - ); - console.log( - `\tTrain cost: ${model.imageClassificationModelMetadata.trainCost}` - ); - console.log( - `\tStop reason: ${model.imageClassificationModelMetadata.stopReason}` - ); - } - console.log(`Model create time:`); - console.log(`\tseconds: ${model.createTime.seconds}`); - console.log(`\tnanos: ${model.createTime.nanos}`); - console.log(`Model update time:`); - console.log(`\tseconds: ${model.updateTime.seconds}`); - console.log(`\tnanos: ${model.updateTime.nanos}`); - console.log(`Model deployment state: ${model.deploymentState}`); - - // [END automl_translation_get_model] -} - -main(...process.argv.slice(2)).catch(err => console.error(err)); diff --git a/automl/translate/models/get-operation-status.v1beta1.js b/automl/translate/models/get-operation-status.v1beta1.js deleted file mode 100644 index 23c04f458d..0000000000 --- a/automl/translate/models/get-operation-status.v1beta1.js +++ /dev/null @@ -1,36 +0,0 @@ -// 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 -// -// https://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'; - -async function main(operationFullId = 'YOUR_OPERATION_ID') { - // [START automl_translation_get_operation_status] - const automl = require('@google-cloud/automl'); - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const operationFullId = `Full name of an operation, eg. “Projects//locations/us-central1/operations/ - - // Get the latest state of a long-running operation. - const [responses] = await client.operationsClient.getOperation( - operationFullId - ); - console.log(`Operation status: ${responses}`); - // [END automl_translation_get_operation_status] -} - -main(...process.argv.slice(2)).catch(err => console.error(err)); diff --git a/automl/translate/models/list-model-evaluations.v1beta1.js b/automl/translate/models/list-model-evaluations.v1beta1.js deleted file mode 100644 index 5338703aa1..0000000000 --- a/automl/translate/models/list-model-evaluations.v1beta1.js +++ /dev/null @@ -1,52 +0,0 @@ -// 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 -// -// https://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'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION', - modelId = 'YOUR_MODEL', - filter = 'YOUR_FILTER' -) { - // [START automl_translation_list_model_evaluations] - const automl = require('@google-cloud/automl'); - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const modelId = `id of the model, e.g. “ICN12345”`; - // const filter = `filter expressions, must specify field, e.g. “imageClassificationModelMetadata:*”`; - - // Get the full path of the model. - const modelFullId = await client.modelPath(projectId, computeRegion, modelId); - - // List all the model evaluations in the model by applying filter. - const [elements] = client.listModelEvaluations({ - parent: modelFullId, - filter: filter, - }); - console.log(`List of model evaluations:`); - elements.forEach(element => { - console.log(element); - }); - - // [END automl_translation_list_model_evaluations] -} - -main(...process.argv.slice(2)).catch(err => console.error(err)); diff --git a/automl/translate/models/list-models.v1beta1.js b/automl/translate/models/list-models.v1beta1.js deleted file mode 100644 index a7eea18079..0000000000 --- a/automl/translate/models/list-models.v1beta1.js +++ /dev/null @@ -1,63 +0,0 @@ -// 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 -// -// https://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'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION', - filter = 'YOUR_FILTER' -) { - // [START automl_translation_list_models] - const automl = require('@google-cloud/automl'); - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const filter = `filter expressions, must specify field, e.g. "translationDatasetMetadata:*”`; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // List all the models available in the region by applying filter. - const [models] = await client.listModels({ - parent: projectLocation, - filter: filter, - }); - - // Display the model information. - 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 display name: ${model.displayName}`); - console.log(`Model dataset id: ${model.datasetId}`); - console.log(`Model create time:`); - console.log(`\tseconds: ${model.createTime.seconds}`); - console.log(`\tnanos: ${model.createTime.nanos}`); - 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`); - }); - - // [END automl_translation_list_models] -} - -main(...process.argv.slice(2)).catch(err => console.error(err)); diff --git a/automl/translate/prediction/predict.v1beta1.js b/automl/translate/prediction/predict.v1beta1.js deleted file mode 100644 index a101a94701..0000000000 --- a/automl/translate/prediction/predict.v1beta1.js +++ /dev/null @@ -1,77 +0,0 @@ -// 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 -// -// https://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'; - -async function main( - projectId = 'YOUR_PROJECT_ID', - computeRegion = 'YOUR_REGION', - modelId = 'YOUR_MODEL', - filePath = 'YOUR_FILE', - translationAllowFallback = false -) { - // [START automl_translation_predict] - const automl = require('@google-cloud/automl'); - const fs = require('fs'); - - // Create client for prediction service. - const client = new automl.PredictionServiceClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const modelId = `id of the model, e.g. “ICN12345”`; - // const filePath = `local text file path of content to be classified, e.g. "./resources/test.txt"`; - // const translationAllowFallback = `use Google translation model as fallback, e.g. "False" or "True"`; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Read the file content for translation. - const content = fs.readFileSync(filePath, `utf8`); - - // Set the payload by giving the content of the file. - const payload = { - textSnippet: { - content: content, - }, - }; - - // Params is additional domain-specific parameters. - // TranslationAllowFallback allows to use Google translation model. - let params = {}; - if (translationAllowFallback) { - params = { - translationAllowFallback: true, - }; - } - - const responses = await client.predict({ - name: modelFullId, - payload: payload, - params: params, - }); - - const response = responses[0]; - console.log( - `Translated Content: `, - response.payload[0].translation.translatedContent.content - ); - - // [END automl_translation_predict] -} - -main(...process.argv.slice(2)).catch(err => console.error(err)); diff --git a/automl/vision/automlVisionDataset.js b/automl/vision/automlVisionDataset.js index 055a69367e..b995a2f209 100644 --- a/automl/vision/automlVisionDataset.js +++ b/automl/vision/automlVisionDataset.js @@ -123,46 +123,6 @@ function listDatasets(projectId, computeRegion, filter) { // [END automl_vision_list_datasets] } -function getDataset(projectId, computeRegion, datasetId) { - // [START automl_vision_get_dataset] - async function automlVisionGetDataset() { - const automl = require(`@google-cloud/automl`).v1beta1; - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const datasetId = `Id of the dataset`; - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath( - projectId, - computeRegion, - datasetId - ); - - // Get complete detail of the dataset. - 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 display name: ${dataset.displayName}`); - console.log(`Dataset example count: ${dataset.exampleCount}`); - console.log( - `Classification type: ${dataset.imageClassificationDatasetMetadata.classificationType}` - ); - console.log(`Dataset create time: `); - console.log(`\tseconds: ${dataset.createTime.seconds}`); - console.log(`\tnanos: ${dataset.createTime.nanos}`); - } - - automlVisionGetDataset().catch(console.error); - // [END automl_vision_get_dataset] -} - function importData(projectId, computeRegion, datasetId, path) { // [START automl_vision_import_data] async function automlVisionImportData() { @@ -212,52 +172,6 @@ function importData(projectId, computeRegion, datasetId, path) { // [END automl_vision_import_data] } -function exportData(projectId, computeRegion, datasetId, outputUri) { - // [START automl_vision_export_data] - async function automlVisionExportData() { - const automl = require(`@google-cloud/automl`).v1beta1; - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const datasetId = `Id of the dataset`; - // const outputUri = `Google Cloud Storage URI for the export directory, e.g. “gs://myproject/output”;` - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath( - projectId, - computeRegion, - datasetId - ); - - // Set the output URI - const outputConfig = { - gcsDestination: { - outputUriPrefix: outputUri, - }, - }; - - // Export the data to the output URI. - const [operation] = await client.exportData({ - name: datasetFullId, - outputConfig: outputConfig, - }); - const [, , response] = await operation.promise(); - - // The final result of the operation. - if (response.done) { - console.log(`Data exported.`); - } - } - - automlVisionExportData().catch(console.error); - // [END automl_vision_export_data] -} - function deleteDataset(projectId, computeRegion, datasetId) { // [START automl_vision_delete_dataset] async function automlVisionDeleteDataset() { @@ -331,12 +245,6 @@ require(`yargs`) // eslint-disable-line `Type of the classification problem, ` + `False - MULTICLASS, True - MULTILABEL.`, }, - outputUri: { - alias: `o`, - type: `string`, - requiresArg: true, - description: `URI (or local path) to export dataset`, - }, path: { alias: `p`, type: `string`, @@ -364,37 +272,18 @@ require(`yargs`) // eslint-disable-line .command(`list-datasets`, `list all Datasets`, {}, opts => listDatasets(opts.projectId, opts.computeRegion, opts.filter) ) - .command(`get-dataset`, `Get a Dataset`, {}, opts => - getDataset(opts.projectId, opts.computeRegion, opts.datasetId) - ) .command(`delete-dataset`, `Delete a dataset`, {}, opts => deleteDataset(opts.projectId, opts.computeRegion, opts.datasetId) ) .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`, - {}, - opts => - exportData( - opts.projectId, - opts.computeRegion, - opts.datasetId, - opts.outputUri - ) - ) .example(`node $0 create-dataset -n "newDataSet"`) .example(`node $0 list-datasets -f "image_classification_dataset_metadata:*"`) - .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"` ) - .example( - `node $0 export-data -i "dataSetId" -o "gs://myproject/outputdestination.csv"` - ) .wrap(120) .recommendCommands() .help() diff --git a/automl/vision/automlVisionModel.js b/automl/vision/automlVisionModel.js index 9764321d99..5e682c39ef 100644 --- a/automl/vision/automlVisionModel.js +++ b/automl/vision/automlVisionModel.js @@ -92,29 +92,6 @@ function createModel( // [END automl_vision_create_model] } -function getOperationStatus(operationFullId) { - // [START automl_vision_get_operation_status] - async function automlVisionGetOperationStatus() { - const automl = require(`@google-cloud/automl`).v1beta1; - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const operationFullId = `Full name of an operation, eg. “Projects//locations/us-central1/operations/ - - // Get the latest state of a long-running operation. - const [response] = await client.operationsClient.getOperation( - operationFullId - ); - console.log(`Operation status: `, response); - } - - automlVisionGetOperationStatus().catch(console.error); - // [END automl_vision_get_operation_status] -} - function listModels(projectId, computeRegion, filter) { // [START automl_vision_list_models] async function automlVisinListModels() { @@ -289,42 +266,6 @@ function listModelEvaluations(projectId, computeRegion, modelId, filter) { // [END automl_vision_list_model_evaluations] } -async function getModelEvaluation( - projectId, - computeRegion, - modelId, - modelEvaluationId -) { - // [START automl_vision_get_model_evaluation] - const automl = require(`@google-cloud/automl`).v1beta1; - const util = require('util'); - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const modelId = `id of the model, e.g. “ICN12345”`; - // const modelEvaluationId = `Id of your model evaluation, e.g “ICN12345” - - // Get the full path of the model evaluation. - const modelEvaluationFullId = client.modelEvaluationPath( - projectId, - computeRegion, - modelId, - modelEvaluationId - ); - - // Get complete detail of the model evaluation. - const [response] = await client.getModelEvaluation({ - name: modelEvaluationFullId, - }); - console.log(util.inspect(response, false, null)); - // [END automl_vision_get_model_evaluation] -} - function displayEvaluation(projectId, computeRegion, modelId, filter) { // [START automl_vision_display_evaluation] async function automlVisionDisplayEvalution() { @@ -487,13 +428,6 @@ require(`yargs`) // eslint-disable-line requiresArg: true, description: `Id of the model evaluation`, }, - operationFullId: { - alias: `o`, - type: `string`, - default: ``, - requiresArg: true, - description: `Full name of an operation`, - }, projectId: { alias: `z`, type: `string`, @@ -518,12 +452,6 @@ require(`yargs`) // eslint-disable-line opts.trainBudget ) ) - .command( - `get-operation-status`, - `Gets status of current operation`, - {}, - opts => getOperationStatus(opts.operationFullId) - ) .command(`list-models`, `list all Models`, {}, opts => listModels(opts.projectId, opts.computeRegion, opts.filter) ) @@ -538,14 +466,6 @@ require(`yargs`) // eslint-disable-line opts.filter ) ) - .command(`get-model-evaluation`, `Get model evaluation`, {}, opts => - getModelEvaluation( - opts.projectId, - opts.computeRegion, - opts.modelId, - opts.modelEvaluationId - ) - ) .command(`display-evaluation`, `Display evaluation`, {}, opts => displayEvaluation( opts.projectId, @@ -558,11 +478,9 @@ require(`yargs`) // eslint-disable-line 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 "image_classification_dataset_metadata:*"`) .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) diff --git a/automl/vision/object-detection/create-dataset.v1beta1.js b/automl/vision/object-detection/create-dataset.v1beta1.js deleted file mode 100644 index 32d09a4a2c..0000000000 --- a/automl/vision/object-detection/create-dataset.v1beta1.js +++ /dev/null @@ -1,70 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - datasetName = 'YOUR_DATASET_NAME' -) { - // [START automl_vision_object_detection_create_dataset] - /** - * Demonstrates using the AutoML client to create a dataset. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetName = '[DATASET_NAME]' e.g., "myDataset"; - - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - const util = require('util'); - - async function createDataset() { - // A resource that represents Google Cloud Platform location. - const projectLocation = automlClient.locationPath(projectId, computeRegion); - - // Set dataset name and metadata. - const myDataset = { - displayName: datasetName, - imageObjectDetectionDatasetMetadata: {}, - }; - - // Create a dataset with the dataset metadata in the region. - const [response] = await automlClient.createDataset({ - parent: projectLocation, - dataset: myDataset, - }); - - //const dataset = response[0]; - // Display the dataset information. - console.log(`Dataset name: ${response.name}`); - console.log(`Dataset Id: ${response.name.split(`/`).pop(-1)}`); - console.log(`Dataset display name: ${response.displayName}`); - console.log(`Dataset example count: ${response.exampleCount}`); - console.log( - `Image object detection dataset metadata: ${util.inspect( - response.imageObjectDetectionDatasetMetadata, - false, - null - )}` - ); - } - createDataset(); - // [END automl_vision_object_detection_create_dataset] -} -main(...process.argv.slice(2)); diff --git a/automl/vision/object-detection/create-model.v1beta1.js b/automl/vision/object-detection/create-model.v1beta1.js deleted file mode 100644 index 55caa4edce..0000000000 --- a/automl/vision/object-detection/create-model.v1beta1.js +++ /dev/null @@ -1,60 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - datasetId = 'YOUR_DATASET_ID', - modelName = 'MODEL_NAME' -) { - // [START automl_vision_object_detection_create_model] - /** - * Demonstrates using the AutoML client to create a model. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetId = '[DATASET_ID]' e.g., "IOD34216801856389120"; - // const modelName = '[MODEL_NAME]' e.g., "myModel"; - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - async function createModel() { - // A resource that represents Google Cloud Platform location. - const projectLocation = automlClient.locationPath(projectId, computeRegion); - - // Set datasetId, model name and model metadata for the dataset. - const myModel = { - displayName: modelName, - datasetId: datasetId, - imageObjectDetectionModelMetadata: {}, - }; - - // Create a model with the model metadata in the region. - const [response] = await automlClient.createModel({ - parent: projectLocation, - model: myModel, - }); - - const initialApiResponse = response[1]; - console.log(`Training operation name: ${initialApiResponse.name}`); - console.log(`Training started...`); - } - createModel(); - // [END automl_vision_object_detection_create_model] -} -main(...process.argv.slice(2)); diff --git a/automl/vision/object-detection/delete-dataset.v1beta1.js b/automl/vision/object-detection/delete-dataset.v1beta1.js deleted file mode 100644 index bc5b18910a..0000000000 --- a/automl/vision/object-detection/delete-dataset.v1beta1.js +++ /dev/null @@ -1,59 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - datasetId = 'YOUR_DATASET_ID' -) { - // [START automl_vision_object_detection_delete_dsataset] - /** - * Demonstrates using the AutoML client to delete a dataset. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetId = '[DATASET_ID]' e.g., "IOD34216801856389120"; - - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - - async function deleteDataset() { - // Get the full path of the dataset. - const datasetFullId = automlClient.datasetPath( - projectId, - computeRegion, - datasetId - ); - - // Delete a dataset. - const [operation] = await automlClient.deleteDataset({name: datasetFullId}); - - const [response] = await operation.promise(); - const operationDetails = response[2]; - - // Get the Dataset delete details. - console.log('Dataset delete details:'); - console.log(` Operation details:`); - console.log(` Name: ${operationDetails.name}`); - console.log(` Done: ${operationDetails.done}`); - } - deleteDataset(); - // [END automl_vision_object_detection_delete_dataset] -} -main(...process.argv.slice(2)); diff --git a/automl/vision/object-detection/delete-model.v1beta1.js b/automl/vision/object-detection/delete-model.v1beta1.js deleted file mode 100644 index 100efe5cd9..0000000000 --- a/automl/vision/object-detection/delete-model.v1beta1.js +++ /dev/null @@ -1,58 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'YOUR_MODEL_ID' -) { - // [START automl_vision_object_detection_delete_model] - /** - * Demonstrates using the AutoML client to delete a model. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "IOD1187015161160925184"; - - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - async function deleteModel() { - // Get the full path of the model. - const modelFullId = automlClient.modelPath( - projectId, - computeRegion, - modelId - ); - - // Delete a model. - const [operation] = await automlClient.deleteModel({name: modelFullId}); - - const [response] = await operation.promise(); - const operationDetails = response[2]; - - // Get the Model delete details. - console.log('Model delete details:'); - console.log(` Operation details:`); - console.log(` Name: ${operationDetails.name}`); - console.log(` Done: ${operationDetails.done}`); - } - deleteModel(); - // [END automl_vision_object_detection_delete_model] -} -main(...process.argv.slice(2)); diff --git a/automl/vision/object-detection/deploy-model.v1beta1.js b/automl/vision/object-detection/deploy-model.v1beta1.js deleted file mode 100644 index ba3271961e..0000000000 --- a/automl/vision/object-detection/deploy-model.v1beta1.js +++ /dev/null @@ -1,57 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'MODEL_ID' -) { - // [START automl_vision_object_detection_deploy_model] - - /** - * Demonstrates using the AutoML client to deploy model. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656"; - - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - async function deployModel() { - // Get the full path of the model. - const modelFullId = automlClient.modelPath( - projectId, - computeRegion, - modelId - ); - - // Deploy a model with the deploy model request. - const [operation] = await automlClient.deployModel({name: modelFullId}); - - const [response] = await operation.promise(); - console.log(`Deployment Details:`); - console.log(` Name: ${response.name}`); - console.log(` Metadata:`); - console.log(` Type Url: ${response.metadata.typeUrl}`); - console.log(` Done: ${response.done}`); - } - deployModel(); - // [END automl_vision_object_detection_deploy_model] -} -main(...process.argv.slice(2)); diff --git a/automl/vision/object-detection/display-evaluation.v1beta1.js b/automl/vision/object-detection/display-evaluation.v1beta1.js deleted file mode 100644 index 36da1cb0d4..0000000000 --- a/automl/vision/object-detection/display-evaluation.v1beta1.js +++ /dev/null @@ -1,118 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'MODEL_ID', - filter = 'FILTER_EXPRESSION' -) { - // [START automl_vision_object_detection_display_evaluation] - /** - * Demonstrates using the AutoML client to display model evaluation. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "IOD2122286140026257408"; - // const filter = '[FILTER_EXPRESSIONS]' - // e.g., "imageObjectDetectionModelMetadata:*"; - - const math = require('mathjs'); - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - - // Get the full path of the model. - const modelFullId = automlClient.modelPath(projectId, computeRegion, modelId); - - // List all the model evaluations in the model by applying filter. - automlClient - .listModelEvaluations({parent: modelFullId, filter: filter}) - .then(respond => { - const response = respond[0]; - // Iterate through the results. - let modelEvaluationId = ``; - for (const element of response) { - // There is evaluation for each class in a model and for overall model. - // Get only the evaluation of overall model. - if (!element.annotationSpecId) { - modelEvaluationId = element.name.split(`/`).pop(-1); - } - } - console.log(`Model Evaluation ID: ${modelEvaluationId}`); - - // Resource name for the model evaluation. - const modelEvaluationFullId = automlClient.modelEvaluationPath( - projectId, - computeRegion, - modelId, - modelEvaluationId - ); - - // Get a model evaluation. - automlClient - .getModelEvaluation({name: modelEvaluationFullId}) - .then(responses => { - const modelEvaluation = responses[0]; - const classMetrics = - modelEvaluation.imageObjectDetectionEvaluationMetrics; - const boundingBoxMetricsEntries = - classMetrics.boundingBoxMetricsEntries; - - for (const boundingBoxMetricsEntry of boundingBoxMetricsEntries) { - const confidenceMetricsEntries = - boundingBoxMetricsEntry.confidenceMetricsEntries; - // Showing model score based on threshold of 0.5 - for (const confidenceMetricsEntry of confidenceMetricsEntries) { - if (confidenceMetricsEntry.confidenceThreshold === 0.5) { - console.log( - `Precision and recall are based on a score ` + - `threshold of 0.5` - ); - console.log( - `Model precision: ${math.round( - confidenceMetricsEntry.precision * 100, - 2 - )} %` - ); - console.log( - `Model recall: ${math.round( - confidenceMetricsEntry.recall * 100, - 2 - )} %` - ); - console.log( - `Model f1 score: ${math.round( - confidenceMetricsEntry.f1Score * 100, - 2 - )} %` - ); - } - } - } - }) - .catch(err => { - console.error(err); - }); - }) - .catch(err => { - console.error(err); - }); - // [END automl_vision_object_detection_display_evaluation] -} -main(...process.argv.slice(2)); diff --git a/automl/vision/object-detection/export-data.v1beta1.js b/automl/vision/object-detection/export-data.v1beta1.js deleted file mode 100644 index a7a7efaffe..0000000000 --- a/automl/vision/object-detection/export-data.v1beta1.js +++ /dev/null @@ -1,73 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - datasetId = 'YOUR_DATASET_ID', - gcsOutputUri = 'GCS_DIRECTORY' -) { - // [START automl_vision_object_detection_export_data] - /** - * Demonstrates using the AutoML client to export a dataset to a - * Google Cloud Storage bucket. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetId = '[DATASET_ID]' e.g.,"IOD34216801856389120"; - // const gcsOutputUri = '[GCS_OUTPUT_URI]' e.g., "gs:///", - // `Google Cloud Storage URI for the export directory`; - - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - - async function exportData() { - // Get the full path of the dataset. - const datasetFullId = automlClient.datasetPath( - projectId, - computeRegion, - datasetId - ); - - // Set the output URI - const outputConfig = { - gcsDestination: { - outputUriPrefix: gcsOutputUri, - }, - }; - - // Set the request - const request = { - name: datasetFullId, - outputConfig: outputConfig, - }; - - // Export the data to the output URI. - const [operation] = await automlClient.exportData(request); - - const [response] = await operation.promise(); - console.log('Data export details:'); - console.log(` Operation details:`); - console.log(` Name: ${response.name}`); - console.log(` Done: ${response.done}`); - } - exportData(); - // [END automl_vision_object_detection_export_data] -} -main(...process.argv.slice(2)); diff --git a/automl/vision/object-detection/get-dataset.v1beta1.js b/automl/vision/object-detection/get-dataset.v1beta1.js deleted file mode 100644 index 5676c7d2f0..0000000000 --- a/automl/vision/object-detection/get-dataset.v1beta1.js +++ /dev/null @@ -1,61 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - datasetId = 'YOUR_DATASET_ID' -) { - // [START automl_vision_object_detection_get_dataset] - /** - * Demonstrates using the AutoML client to get a dataset by ID. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetId = '[DATASET_ID]' e.g.,"IOD34216801856389120"; - - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - const util = require('util'); - async function getDataset() { - // Get the full path of the dataset. - const datasetFullId = automlClient.datasetPath( - projectId, - computeRegion, - datasetId - ); - - // Get a dataset. - const [response] = await automlClient.getDataset({name: datasetFullId}); - console.log(`Got dataset: ${response.name}`); - console.log(`Dataset Id: ${response.name.split(`/`).pop(-1)}`); - console.log(`Dataset display name: ${response.displayName}`); - console.log(`Dataset example count: ${response.exampleCount}`); - console.log( - `Image object detection dataset metadata: ${util.inspect( - response.imageObjectDetectionDatasetMetadata, - false, - null - )}` - ); - } - getDataset(); - // [END automl_vision_object_detection_get_dataset] -} -main(...process.argv.slice(2)); diff --git a/automl/vision/object-detection/get-model-evaluations.v1beta1.js b/automl/vision/object-detection/get-model-evaluations.v1beta1.js deleted file mode 100644 index 80fa52945b..0000000000 --- a/automl/vision/object-detection/get-model-evaluations.v1beta1.js +++ /dev/null @@ -1,133 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'MODEL_ID', - modelEvaluationId = 'MODEL_EVALUATION_ID' -) { - // [START automl_vision_object_detection_get_model_evaluation] - /** - * Demonstrates using the AutoML client to get model evaluations. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "IOD2122286140026257408"; - // const modelEvaluationId = '[MODEL_EVALUATION_ID]' - // e.g., "3806191078210741236"; - - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - - const math = require('mathjs'); - - async function getModelEvaluations() { - // Get the full path of the model evaluation. - const modelEvaluationFullId = automlClient.modelEvaluationPath( - projectId, - computeRegion, - modelId, - modelEvaluationId - ); - - // Get complete detail of the model evaluation. - const [response] = await automlClient.getModelEvaluation({ - name: modelEvaluationFullId, - }); - - const detectMetrics = response.imageObjectDetectionEvaluationMetrics; - const boundingBoxMetricsEntries = detectMetrics.boundingBoxMetricsEntries; - - // Display the model evaluations information. - console.log(`\nModel evaluation name: ${response.name}`); - console.log( - `Model evaluation Id: ${response.name - .split(`/`) - .slice(-1) - .pop()}` - ); - console.log( - `Model evaluation annotation spec Id: ${response.annotationSpecId}` - ); - console.log(`Model evaluation display name: ${response.displayName}`); - console.log( - `Model evaluation example count: ${response.evaluatedExampleCount}` - ); - console.log(`Image object detection evaluation metrics:`); - console.log( - ` Evaluated bounding box count: ${detectMetrics.evaluatedBoundingBoxCount}` - ); - console.log( - ` Bounding box mean average precision: ${math.round( - detectMetrics.boundingBoxMeanAveragePrecision, - 6 - )}` - ); - - for (const boundingBoxMetricsEntry of boundingBoxMetricsEntries) { - console.log(`\tBounding box metrics entries:`); - console.log( - ` Iou threshold: ${math.round( - boundingBoxMetricsEntry.iouThreshold, - 2 - )}` - ); - console.log( - ` Mean average precision: ${math.round( - boundingBoxMetricsEntry.meanAveragePrecision, - 6 - )}` - ); - console.log(` Confidence metrics entries:`); - const confidenceMetricsEntries = - boundingBoxMetricsEntry.confidenceMetricsEntries; - - for (const confidenceMetricsEntry of confidenceMetricsEntries) { - console.log( - ` Model confidence threshold: ${math.round( - confidenceMetricsEntry.confidenceThreshold * 100, - 6 - )}` - ); - console.log( - ` Model recall: ${math.round( - confidenceMetricsEntry.recall * 100, - 2 - )} %` - ); - console.log( - `\t\t\tModel precision: ${math.round( - confidenceMetricsEntry.precision * 100, - 2 - )} %` - ); - console.log( - ` Model f1 score: ${math.round( - confidenceMetricsEntry.f1Score * 100, - 2 - )} % \n` - ); - } - } - } - getModelEvaluations(); - // [END automl_vision_object_detection_get_model_evaluation] -} -main(...process.argv.slice(2)); diff --git a/automl/vision/object-detection/get-model.v1beta1.js b/automl/vision/object-detection/get-model.v1beta1.js deleted file mode 100644 index 204bf35b73..0000000000 --- a/automl/vision/object-detection/get-model.v1beta1.js +++ /dev/null @@ -1,93 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'MODEL_ID' -) { - // [START automl_vision_object_detection_get_model] - /** - * Demonstrates using the AutoML client to get model details. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "IOD1187015161160925184"; - - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - - async function getModel() { - // Get the full path of the model. - const modelFullId = automlClient.modelPath( - projectId, - computeRegion, - modelId - ); - - // Get complete detail of the model. - const [response] = await automlClient.getModel({name: modelFullId}); - - // Display the model information. - console.log(`Model name: ${response.name}`); - console.log(`Model Id: ${response.name.split(`/`).pop(-1)}`); - console.log(`Model display name: ${response.displayName}`); - console.log(`Dataset Id: ${response.datasetId}`); - - if (response.modelMetadata === `translationModelMetadata`) { - console.log(`Translation model metadata:`); - console.log( - `\tBase model: ${response.translationModelMetadata.baseModel}` - ); - console.log( - `\tSource language code: ${response.translationModelMetadata.sourceLanguageCode}` - ); - console.log( - `\tTarget language code: ${response.translationModelMetadata.targetLanguageCode}` - ); - } else if (response.modelMetadata === `textClassificationModelMetadata`) { - console.log( - `Text classification model metadata: , ${response.textClassificationModelMetadata}` - ); - } else if (response.modelMetadata === `imageClassificationModelMetadata`) { - console.log(`Image classification model metadata:`); - console.log( - `\tBase model Id: ${response.imageClassificationModelMetadata.baseModelId}` - ); - console.log( - `\tTrain budget: ${response.imageClassificationModelMetadata.trainBudget}` - ); - console.log( - `\tTrain cost: ${response.imageClassificationModelMetadata.trainCost}` - ); - console.log( - `\tStop reason: ${response.imageClassificationModelMetadata.stopReason}` - ); - } else if (response.modelMetadata === `imageObjectDetectionModelMetadata`) { - console.log(`Image Object Detection Model metadata:`); - console.log( - `\tModel Type: ${response.imageObjectDetectionModelMetadata.modelType}` - ); - } - console.log(`Model deployment state: ${response.deploymentState}`); - } - getModel(); - // [END automl_vision_object_detection_get_model] -} -main(...process.argv.slice(2)); diff --git a/automl/vision/object-detection/import-data.v1beta1.js b/automl/vision/object-detection/import-data.v1beta1.js deleted file mode 100644 index 28f69941ba..0000000000 --- a/automl/vision/object-detection/import-data.v1beta1.js +++ /dev/null @@ -1,69 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - datasetId = 'YOUR_DATASET_ID', - gcsPath = 'GCS_PATH' -) { - // [START automl_vision_object_detection_import_data] - /** - * Demonstrates using the AutoML client to import labeled items. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const datasetId = '[DATASET_ID]' e.g.,"IOD34216801856389120"; - // const gcsPath = '[GCS_PATH]' e.g., "gs:///", - // `.csv paths in AutoML Vision Object Detection CSV format`; - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - async function importData() { - // Get the full path of the dataset. - const datasetFullId = automlClient.datasetPath( - projectId, - computeRegion, - datasetId - ); - - // Get the multiple Google Cloud Storage URIs. - const inputUris = gcsPath.split(`,`); - const inputConfig = { - gcsSource: { - inputUris: inputUris, - }, - }; - - // Import the data from the input URI. - const [operation] = await automlClient.importData({ - name: datasetFullId, - inputConfig: inputConfig, - }); - - const [response] = await operation.promise(); - // Get the data import details. - console.log('Data import details:'); - console.log(` Operation details:`); - console.log(` Name: ${response.name}`); - console.log(` Done: ${response.done}`); - } - importData(); - // [END automl_vision_object_detection_import_data] -} -main(...process.argv.slice(2)); diff --git a/automl/vision/object-detection/list-datasets.v1beta1.js b/automl/vision/object-detection/list-datasets.v1beta1.js deleted file mode 100644 index 703dbd292e..0000000000 --- a/automl/vision/object-detection/list-datasets.v1beta1.js +++ /dev/null @@ -1,64 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - filter = 'FILTER_EXPRESSION' -) { - // [START automl_vision_object_detection_list_datasets] - /** - * Demonstrates using the AutoML client to list all Datasets. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const filter_ = '[FILTER_EXPRESSIONS]' - // e.g., "imageObjectDetectionDatasetMetadata:*"; - - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - const util = require('util'); - - async function listDatasets() { - const projectLocation = automlClient.locationPath(projectId, computeRegion); - - // List all the datasets available in the region by applying filter. - const [response] = await automlClient.listDatasets({ - parent: projectLocation, - filter: filter, - }); - console.log('List of datasets:'); - for (const dataset of response) { - console.log(`\nDataset name: ${dataset.name}`); - 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( - `Image object detection dataset metadata: ${util.inspect( - dataset.imageObjectDetectionDatasetMetadata, - false, - null - )}` - ); - } - } - listDatasets(); - // [END automl_vision_object_detection_list_datasets] -} -main(...process.argv.slice(2)); diff --git a/automl/vision/object-detection/list-model-evaluations.v1beta1.js b/automl/vision/object-detection/list-model-evaluations.v1beta1.js deleted file mode 100644 index a84f98ce47..0000000000 --- a/automl/vision/object-detection/list-model-evaluations.v1beta1.js +++ /dev/null @@ -1,135 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'MODEL_ID', - filter = 'FILTER_EXPRESSION' -) { - // [START automl_vision_object_detection_list_model_evaluations] - /** - * Demonstrates using the AutoML client to list model evaluations. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "IOD1187015161160925184"; - // const filter_ = '[FILTER_EXPRESSIONS]' - // e.g., "imageObjectDetectionModelMetadata:*"; - - const math = require('mathjs'); - - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - - async function listModelEvaluations() { - // Get the full path of the model. - const modelFullId = automlClient.modelPath( - projectId, - computeRegion, - modelId - ); - - // List all the model evaluations in the model by applying filter. - const [response] = await automlClient.listModelEvaluations({ - parent: modelFullId, - filter: filter, - }); - console.log(`List of model evaluations:`); - for (const element of response) { - const detectMetrics = element.imageObjectDetectionEvaluationMetrics; - const boundingBoxMetricsEntries = detectMetrics.boundingBoxMetricsEntries; - - // Display the model evaluations information. - console.log(`\nModel evaluation name: ${element.name}`); - console.log( - `Model evaluation Id: ${element.name - .split(`/`) - .slice(-1) - .pop()}` - ); - console.log( - `Model evaluation annotation spec Id: ${element.annotationSpecId}` - ); - console.log(`Model evaluation display name: ${element.displayName}`); - console.log( - `Model evaluation example count: ${element.evaluatedExampleCount}` - ); - console.log(`Image object detection evaluation metrics:`); - console.log( - `Evaluated bounding box count: ${detectMetrics.evaluatedBoundingBoxCount}` - ); - console.log( - `Bounding box mean average precision: ${math.round( - detectMetrics.boundingBoxMeanAveragePrecision, - 6 - )}` - ); - - for (const boundingBoxMetricsEntry of boundingBoxMetricsEntries) { - console.log(`\tBounding box metrics entries:`); - console.log( - `Iou threshold: ${math.round( - boundingBoxMetricsEntry.iouThreshold, - 2 - )}` - ); - console.log( - `Mean average precision: ${math.round( - boundingBoxMetricsEntry.meanAveragePrecision, - 6 - )}` - ); - console.log(`Confidence metrics entries:`); - const confidenceMetricsEntries = - boundingBoxMetricsEntry.confidenceMetricsEntries; - - for (const confidenceMetricsEntry of confidenceMetricsEntries) { - console.log( - `Model confidence threshold: ${math.round( - confidenceMetricsEntry.confidenceThreshold * 100, - 6 - )}` - ); - console.log( - `\t\t\tModel recall: ${math.round( - confidenceMetricsEntry.recall * 100, - 2 - )} %` - ); - console.log( - `Model precision: ${math.round( - confidenceMetricsEntry.precision * 100, - 2 - )} %` - ); - console.log( - `Model f1 score: ${math.round( - confidenceMetricsEntry.f1Score * 100, - 2 - )} % \n` - ); - } - } - } - } - listModelEvaluations(); - // [END automl_vision_object_detection_list_model_evaluations] -} -main(...process.argv.slice(2)); diff --git a/automl/vision/object-detection/list-models.v1beta1.js b/automl/vision/object-detection/list-models.v1beta1.js deleted file mode 100644 index 7af2490777..0000000000 --- a/automl/vision/object-detection/list-models.v1beta1.js +++ /dev/null @@ -1,92 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - filter = 'FILTER_EXPRESSION' -) { - // [START automl_vision_object_detection_list_models] - /** - * Demonstrates using the AutoML client to list all models. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const filter_ = '[FILTER_EXPRESSIONS]' - // e.g., "imageObjectDetectionModelMetadata:*"; - - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - async function listModels() { - // A resource that represents Google Cloud Platform location. - const projectLocation = automlClient.locationPath(projectId, computeRegion); - - // List all the models available in the region by applying filter. - const [response] = await automlClient.listModels({ - parent: projectLocation, - filter: filter, - }); - console.log(`List of models:`); - for (const model of response) { - console.log(`\nModel name: ${model.name}`); - console.log(`Model Id: ${model.name.split(`/`).pop(-1)}`); - console.log(`Model display name: ${model.displayName}`); - console.log(`Dataset Id: ${model.datasetId}`); - - if (model.modelMetadata === `translationModelMetadata`) { - console.log(`Translation model metadata:`); - console.log(`Base model: ${model.translationModelMetadata.baseModel}`); - console.log( - `Source language code: ${model.translationModelMetadata.sourceLanguageCode}` - ); - console.log( - `Target language code: ${model.translationModelMetadata.targetLanguageCode}` - ); - } else if (model.modelMetadata === `textClassificationModelMetadata`) { - console.log( - `Text classification model metadata: , ${model.textClassificationModelMetadata}` - ); - } else if (model.modelMetadata === `imageClassificationModelMetadata`) { - console.log(`Image classification model metadata:`); - console.log( - `Base model Id: ${model.imageClassificationModelMetadata.baseModelId}` - ); - console.log( - `Train budget: ${model.imageClassificationModelMetadata.trainBudget}` - ); - console.log( - `Train cost: ${model.imageClassificationModelMetadata.trainCost}` - ); - console.log( - `Stop reason: ${model.imageClassificationModelMetadata.stopReason}` - ); - } else if (model.modelMetadata === `imageObjectDetectionModelMetadata`) { - console.log(`Image Object Detection Model metadata:`); - console.log( - `Model Type: ${model.imageObjectDetectionModelMetadata.modelType}` - ); - } - - console.log(`Model deployment state: ${model.deploymentState}`); - } - } - listModels(); - // [END automl_vision_object_detection_list_models] -} -main(...process.argv.slice(2)); diff --git a/automl/vision/object-detection/list-operation-status.v1beta1.js b/automl/vision/object-detection/list-operation-status.v1beta1.js deleted file mode 100644 index 36e5de9701..0000000000 --- a/automl/vision/object-detection/list-operation-status.v1beta1.js +++ /dev/null @@ -1,55 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - filter = 'FILTER_EXPRESSION' -) { - // [START automl_vision_object_detection_list_operations_status] - - /** - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const filter = '[FILTER_EXPRESSIONS]'; - - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - async function listOperationStatus() { - // A resource that represents Google Cloud Platform location. - const projectLocation = automlClient.locationPath(projectId, computeRegion); - - // List all the operations available in the region by applying filter. - const [operations] = await automlClient.operationsClient.listOperations({ - name: projectLocation, - filter: filter, - }); - for (const element of operations) { - console.log(`\nOperation details:`); - console.log(`Name: ${element.name}`); - console.log(`Metadata:`); - console.log(`Type Url: ${element.metadata.typeUrl}`); - console.log(`Done: ${element.done}`); - } - } - listOperationStatus(); - // [END automl_vision_object_detection_list_operations_status] -} -main(...process.argv.slice(2)); diff --git a/automl/vision/object-detection/predict.v1beta1.js b/automl/vision/object-detection/predict.v1beta1.js deleted file mode 100644 index 6c02c1b8a7..0000000000 --- a/automl/vision/object-detection/predict.v1beta1.js +++ /dev/null @@ -1,87 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'YOUR_MODEL_ID', - filePath = 'GCS_PATH', - scoreThreshold = 'SCORE_THRESHOLD' -) { - // [START automl_vision_object_detection_predict] - - /** - * Demonstrates using the AutoML client to detect the object in an image. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "IOD1187015161160925184"; - // const filePath = '[GCS_PATH]' e.g., "/home/ubuntu/salad.jpg", - // `local text file path of content to be extracted`; - // const scoreThreshold = '[SCORE_THRESHOLD]', e.g, 0.50 , - // `Set the score threshold for Prediction of the created model`; - - //Imports the Google Cloud Automl library - const {PredictionServiceClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const predictionServiceClient = new PredictionServiceClient(); - - const fs = require('fs'); - - async function predict() { - // Get the full path of the model. - const modelFullId = predictionServiceClient.modelPath( - projectId, - computeRegion, - modelId - ); - - // Read the file content for prediction. - const content = fs.readFileSync(filePath, `base64`); - let params = {}; - if (scoreThreshold) { - params = { - score_threshold: scoreThreshold, - }; - } - - // Set the payload by giving the content and type of the file. - const payload = { - image: { - imageBytes: content, - }, - }; - - // params is additional domain-specific parameters. - // currently there is no additional parameters supported. - const [response] = await predictionServiceClient.predict({ - name: modelFullId, - payload: payload, - params: params, - }); - console.log(`Prediction results:`); - for (const result of response[0].payload) { - console.log(`\nPredicted class name: ${result.displayName}`); - console.log( - `Predicted class score: ${result.imageObjectDetection.score}` - ); - } - } - predict(); - // [END automl_vision_object_detection_predict] -} -main(...process.argv.slice(2)); diff --git a/automl/vision/object-detection/undeploy-model.v1beta1.js b/automl/vision/object-detection/undeploy-model.v1beta1.js deleted file mode 100644 index a1facb250c..0000000000 --- a/automl/vision/object-detection/undeploy-model.v1beta1.js +++ /dev/null @@ -1,58 +0,0 @@ -// 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 -// -// https://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', - computeRegion = 'YOUR_REGION_NAME', - modelId = 'MODEL_ID' -) { - // [START automl_vision_object_detection_undeploy_model] - /** - * Demonstrates using the AutoML client to undeploy model. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; - // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; - // const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656"; - - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - - async function undeployModel() { - // Get the full path of the model. - const modelFullId = automlClient.modelPath( - projectId, - computeRegion, - modelId - ); - - // Deploy a model with the deploy model request. - const [operation] = await automlClient.undeployModel({name: modelFullId}); - const [response] = await operation.promise(); - for (const element of response) { - console.log(`Undeployment Details:`); - console.log(`\tName: ${element.name}`); - console.log(`\tMetadata:`); - console.log(`\t\tType Url: ${element.metadata.typeUrl}`); - console.log(`\tDone: ${element.done}`); - } - } - undeployModel(); - // [END automl_vision_object_detection_undeploy_model] -} -main(...process.argv.slice(2));