|
| 1 | +# Copyright 2020 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +def get_dataset(project_id, dataset_id): |
| 17 | + """Get a dataset.""" |
| 18 | + # [START automl_language_entity_extraction_get_dataset] |
| 19 | + # [START automl_language_sentiment_analysis_get_dataset] |
| 20 | + # [START automl_language_text_classification_get_dataset] |
| 21 | + # [START automl_translate_get_dataset] |
| 22 | + # [START automl_vision_classification_get_dataset] |
| 23 | + # [START automl_vision_object_detection_get_dataset] |
| 24 | + from google.cloud import automl |
| 25 | + |
| 26 | + # TODO(developer): Uncomment and set the following variables |
| 27 | + # project_id = "YOUR_PROJECT_ID" |
| 28 | + # dataset_id = "YOUR_DATASET_ID" |
| 29 | + |
| 30 | + client = automl.AutoMlClient() |
| 31 | + # Get the full path of the dataset |
| 32 | + dataset_full_id = client.dataset_path( |
| 33 | + project_id, "us-central1", dataset_id |
| 34 | + ) |
| 35 | + dataset = client.get_dataset(dataset_full_id) |
| 36 | + |
| 37 | + # Display the dataset information |
| 38 | + print("Dataset name: {}".format(dataset.name)) |
| 39 | + print("Dataset id: {}".format(dataset.name.split("/")[-1])) |
| 40 | + print("Dataset display name: {}".format(dataset.display_name)) |
| 41 | + print("Dataset create time:") |
| 42 | + print("\tseconds: {}".format(dataset.create_time.seconds)) |
| 43 | + print("\tnanos: {}".format(dataset.create_time.nanos)) |
| 44 | + # [END automl_language_sentiment_analysis_get_dataset] |
| 45 | + # [END automl_language_text_classification_get_dataset] |
| 46 | + # [END automl_translate_get_dataset] |
| 47 | + # [END automl_vision_classification_get_dataset] |
| 48 | + # [END automl_vision_object_detection_get_dataset] |
| 49 | + print( |
| 50 | + "Text extraction dataset metadata: {}".format( |
| 51 | + dataset.text_extraction_dataset_metadata |
| 52 | + ) |
| 53 | + ) |
| 54 | + # [END automl_language_entity_extraction_get_dataset] |
| 55 | + |
| 56 | + # [START automl_language_sentiment_analysis_get_dataset] |
| 57 | + print( |
| 58 | + "Text sentiment dataset metadata: {}".format( |
| 59 | + dataset.text_sentiment_dataset_metadata |
| 60 | + ) |
| 61 | + ) |
| 62 | + # [END automl_language_sentiment_analysis_get_dataset] |
| 63 | + |
| 64 | + # [START automl_language_text_classification_get_dataset] |
| 65 | + print( |
| 66 | + "Text classification dataset metadata: {}".format( |
| 67 | + dataset.text_classification_dataset_metadata |
| 68 | + ) |
| 69 | + ) |
| 70 | + # [END automl_language_text_classification_get_dataset] |
| 71 | + |
| 72 | + # [START automl_translate_get_dataset] |
| 73 | + print("Translation dataset metadata:") |
| 74 | + print( |
| 75 | + "\tsource_language_code: {}".format( |
| 76 | + dataset.translation_dataset_metadata.source_language_code |
| 77 | + ) |
| 78 | + ) |
| 79 | + print( |
| 80 | + "\ttarget_language_code: {}".format( |
| 81 | + dataset.translation_dataset_metadata.target_language_code |
| 82 | + ) |
| 83 | + ) |
| 84 | + # [END automl_translate_get_dataset] |
| 85 | + |
| 86 | + # [START automl_vision_classification_get_dataset] |
| 87 | + print( |
| 88 | + "Image classification dataset metadata: {}".format( |
| 89 | + dataset.image_classification_dataset_metadata |
| 90 | + ) |
| 91 | + ) |
| 92 | + # [END automl_vision_classification_get_dataset] |
| 93 | + |
| 94 | + # [START automl_vision_object_detection_get_dataset] |
| 95 | + print( |
| 96 | + "Image object detection dataset metadata: {}".format( |
| 97 | + dataset.image_object_detection_dataset_metadata |
| 98 | + ) |
| 99 | + ) |
| 100 | + # [END automl_vision_object_detection_get_dataset] |
0 commit comments