From eb777904f352ce3972aaf84a1e114998da560310 Mon Sep 17 00:00:00 2001 From: Rebecca Taylor Date: Fri, 5 Oct 2018 14:20:17 -0700 Subject: [PATCH 1/5] Get display name of enums using IntEnum Requires updating google-cloud-language to 1.1.0 --- language/cloud-client/v1/requirements.txt | 2 +- language/cloud-client/v1/snippets.py | 28 +++++++---------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/language/cloud-client/v1/requirements.txt b/language/cloud-client/v1/requirements.txt index 2cbc37eb15b..7029093e951 100644 --- a/language/cloud-client/v1/requirements.txt +++ b/language/cloud-client/v1/requirements.txt @@ -1 +1 @@ -google-cloud-language==1.0.2 +google-cloud-language==1.1.0 diff --git a/language/cloud-client/v1/snippets.py b/language/cloud-client/v1/snippets.py index a41c7cb3ccc..826c28c54f1 100644 --- a/language/cloud-client/v1/snippets.py +++ b/language/cloud-client/v1/snippets.py @@ -95,14 +95,11 @@ def entities_text(text): # document.type == enums.Document.Type.HTML entities = client.analyze_entities(document).entities - # entity types from enums.Entity.Type - entity_type = ('UNKNOWN', 'PERSON', 'LOCATION', 'ORGANIZATION', - 'EVENT', 'WORK_OF_ART', 'CONSUMER_GOOD', 'OTHER') - for entity in entities: + entity_type = enums.Entity.Type(entity.type) print('=' * 20) print(u'{:<16}: {}'.format('name', entity.name)) - print(u'{:<16}: {}'.format('type', entity_type[entity.type])) + print(u'{:<16}: {}'.format('type', entity_type.name)) print(u'{:<16}: {}'.format('metadata', entity.metadata)) print(u'{:<16}: {}'.format('salience', entity.salience)) print(u'{:<16}: {}'.format('wikipedia_url', @@ -125,14 +122,11 @@ def entities_file(gcs_uri): # document.type == enums.Document.Type.HTML entities = client.analyze_entities(document).entities - # entity types from enums.Entity.Type - entity_type = ('UNKNOWN', 'PERSON', 'LOCATION', 'ORGANIZATION', - 'EVENT', 'WORK_OF_ART', 'CONSUMER_GOOD', 'OTHER') - for entity in entities: + entity_type = enums.Entity.Type(entity.type) print('=' * 20) print(u'{:<16}: {}'.format('name', entity.name)) - print(u'{:<16}: {}'.format('type', entity_type[entity.type])) + print(u'{:<16}: {}'.format('type', entity_type.name)) print(u'{:<16}: {}'.format('metadata', entity.metadata)) print(u'{:<16}: {}'.format('salience', entity.salience)) print(u'{:<16}: {}'.format('wikipedia_url', @@ -158,12 +152,9 @@ def syntax_text(text): # document.type == enums.Document.Type.HTML tokens = client.analyze_syntax(document).tokens - # part-of-speech tags from enums.PartOfSpeech.Tag - pos_tag = ('UNKNOWN', 'ADJ', 'ADP', 'ADV', 'CONJ', 'DET', 'NOUN', 'NUM', - 'PRON', 'PRT', 'PUNCT', 'VERB', 'X', 'AFFIX') - for token in tokens: - print(u'{}: {}'.format(pos_tag[token.part_of_speech.tag], + part_of_speech_tag = enums.PartOfSpeech.Tag(token.part_of_speech.tag) + print(u'{}: {}'.format(part_of_speech_tag.name, token.text.content)) # [END language_python_migration_syntax_text] # [END language_syntax_text] @@ -183,12 +174,9 @@ def syntax_file(gcs_uri): # document.type == enums.Document.Type.HTML tokens = client.analyze_syntax(document).tokens - # part-of-speech tags from enums.PartOfSpeech.Tag - pos_tag = ('UNKNOWN', 'ADJ', 'ADP', 'ADV', 'CONJ', 'DET', 'NOUN', 'NUM', - 'PRON', 'PRT', 'PUNCT', 'VERB', 'X', 'AFFIX') - for token in tokens: - print(u'{}: {}'.format(pos_tag[token.part_of_speech.tag], + part_of_speech_tag = enums.PartOfSpeech.Tag(token.part_of_speech.tag) + print(u'{}: {}'.format(part_of_speech_tag.name, token.text.content)) # [END language_syntax_gcs] From 39d9bfff03201f7c6dcb38fee3856dd537ab4b62 Mon Sep 17 00:00:00 2001 From: Rebecca Taylor Date: Fri, 5 Oct 2018 14:36:07 -0700 Subject: [PATCH 2/5] Add note about gs://demomaker for video test files --- video/cloud-client/analyze/analyze_test.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/video/cloud-client/analyze/analyze_test.py b/video/cloud-client/analyze/analyze_test.py index 60a01789a1d..221c366bfa5 100644 --- a/video/cloud-client/analyze/analyze_test.py +++ b/video/cloud-client/analyze/analyze_test.py @@ -22,6 +22,9 @@ BUCKET = os.environ['CLOUD_STORAGE_BUCKET'] + + +# Videos used for these tests can be found in the gs://demomaker/ public bucket LABELS_FILE_PATH = '/video/cat.mp4' EXPLICIT_CONTENT_FILE_PATH = '/video/cat.mp4' SHOTS_FILE_PATH = '/video/gbikes_dinosaur.mp4' From 751a0b1552aad6f6dac626de4a958044129b66eb Mon Sep 17 00:00:00 2001 From: Rebecca Taylor Date: Fri, 5 Oct 2018 15:04:23 -0700 Subject: [PATCH 3/5] Get display name of enums using IntEnum --- video/cloud-client/analyze/analyze.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/video/cloud-client/analyze/analyze.py b/video/cloud-client/analyze/analyze.py index 1905c0e712f..5a13d01c823 100644 --- a/video/cloud-client/analyze/analyze.py +++ b/video/cloud-client/analyze/analyze.py @@ -30,6 +30,7 @@ import io from google.cloud import videointelligence +from google.cloud.videointelligence import enums def analyze_explicit_content(path): @@ -44,15 +45,12 @@ def analyze_explicit_content(path): result = operation.result(timeout=90) print('\nFinished processing.') - likely_string = ("Unknown", "Very unlikely", "Unlikely", "Possible", - "Likely", "Very likely") - # first result is retrieved because a single video was processed for frame in result.annotation_results[0].explicit_annotation.frames: + likelihood = enums.Likelihood(frame.pornography_likelihood) frame_time = frame.time_offset.seconds + frame.time_offset.nanos / 1e9 print('Time: {}s'.format(frame_time)) - print('\tpornography: {}'.format( - likely_string[frame.pornography_likelihood])) + print('\tpornography: {}'.format(likelihood.name)) # [END video_analyze_explicit_content] From 9971fb73ac50b053b9f68f7fd823ae0cf31c880e Mon Sep 17 00:00:00 2001 From: Rebecca Taylor Date: Fri, 5 Oct 2018 15:13:20 -0700 Subject: [PATCH 4/5] Get display name of enums using IntEnum --- texttospeech/cloud-client/list_voices.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/texttospeech/cloud-client/list_voices.py b/texttospeech/cloud-client/list_voices.py index 3f43499c674..a2da5a17852 100644 --- a/texttospeech/cloud-client/list_voices.py +++ b/texttospeech/cloud-client/list_voices.py @@ -25,6 +25,7 @@ def list_voices(): """Lists the available voices.""" from google.cloud import texttospeech + from google.cloud.texttospeech import enums client = texttospeech.TextToSpeechClient() # Performs the list voices request @@ -38,13 +39,10 @@ def list_voices(): for language_code in voice.language_codes: print('Supported language: {}'.format(language_code)) - # SSML Voice Gender values from google.cloud.texttospeech.enums - ssml_voice_genders = ['SSML_VOICE_GENDER_UNSPECIFIED', 'MALE', - 'FEMALE', 'NEUTRAL'] + ssml_gender = enums.SsmlVoiceGender(voice.ssml_gender) # Display the SSML Voice Gender - print('SSML Voice Gender: {}'.format( - ssml_voice_genders[voice.ssml_gender])) + print('SSML Voice Gender: {}'.format(ssml_gender.name)) # Display the natural sample rate hertz for this voice. Example: 24000 print('Natural Sample Rate Hertz: {}\n'.format( From eda7ecad8af9430d389d67a37c2cbad6b2e73bf1 Mon Sep 17 00:00:00 2001 From: Rebecca Taylor Date: Tue, 9 Oct 2018 15:02:51 -0700 Subject: [PATCH 5/5] Revert "Add note about gs://demomaker for video test files" This reverts commit 39d9bfff03201f7c6dcb38fee3856dd537ab4b62. --- video/cloud-client/analyze/analyze_test.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/video/cloud-client/analyze/analyze_test.py b/video/cloud-client/analyze/analyze_test.py index 221c366bfa5..60a01789a1d 100644 --- a/video/cloud-client/analyze/analyze_test.py +++ b/video/cloud-client/analyze/analyze_test.py @@ -22,9 +22,6 @@ BUCKET = os.environ['CLOUD_STORAGE_BUCKET'] - - -# Videos used for these tests can be found in the gs://demomaker/ public bucket LABELS_FILE_PATH = '/video/cat.mp4' EXPLICIT_CONTENT_FILE_PATH = '/video/cat.mp4' SHOTS_FILE_PATH = '/video/gbikes_dinosaur.mp4'