From 85716fa82a3dfccacb2f74314294134293772932 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 8 Aug 2017 12:14:55 -0700 Subject: [PATCH 1/3] show entity type name --- language/cloud-client/v1/snippets.py | 12 ++++++++++-- language/cloud-client/v1beta2/snippets.py | 8 ++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/language/cloud-client/v1/snippets.py b/language/cloud-client/v1/snippets.py index d485752b09c5..e452fbfa2c6b 100644 --- a/language/cloud-client/v1/snippets.py +++ b/language/cloud-client/v1/snippets.py @@ -94,10 +94,14 @@ 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: print('=' * 20) print(u'{:<16}: {}'.format('name', entity.name)) - print(u'{:<16}: {}'.format('type', entity.type)) + print(u'{:<16}: {}'.format('type', entity_type[entity.type])) print(u'{:<16}: {}'.format('metadata', entity.metadata)) print(u'{:<16}: {}'.format('salience', entity.salience)) print(u'{:<16}: {}'.format('wikipedia_url', @@ -120,10 +124,14 @@ 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: print('=' * 20) print(u'{:<16}: {}'.format('name', entity.name)) - print(u'{:<16}: {}'.format('type', entity.type)) + print(u'{:<16}: {}'.format('type', entity_type[entity.type])) print(u'{:<16}: {}'.format('metadata', entity.metadata)) print(u'{:<16}: {}'.format('salience', entity.salience)) print(u'{:<16}: {}'.format('wikipedia_url', diff --git a/language/cloud-client/v1beta2/snippets.py b/language/cloud-client/v1beta2/snippets.py index 0ea7352aeb95..6dafeba90e0d 100644 --- a/language/cloud-client/v1beta2/snippets.py +++ b/language/cloud-client/v1beta2/snippets.py @@ -85,6 +85,10 @@ 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: print('=' * 20) print(u'{:<16}: {}'.format('name', entity.name)) @@ -108,6 +112,10 @@ 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: print('=' * 20) print(u'{:<16}: {}'.format('name', entity.name)) From 811256830d985dc818dc00a753f4984e6474ad8d Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 8 Aug 2017 12:19:06 -0700 Subject: [PATCH 2/3] update v1beta2 --- language/cloud-client/v1beta2/snippets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/language/cloud-client/v1beta2/snippets.py b/language/cloud-client/v1beta2/snippets.py index 6dafeba90e0d..81609a285509 100644 --- a/language/cloud-client/v1beta2/snippets.py +++ b/language/cloud-client/v1beta2/snippets.py @@ -92,7 +92,7 @@ def entities_text(text): for entity in entities: print('=' * 20) print(u'{:<16}: {}'.format('name', entity.name)) - print(u'{:<16}: {}'.format('type', entity.type)) + print(u'{:<16}: {}'.format('type', entity_type[entity.type])) print(u'{:<16}: {}'.format('metadata', entity.metadata)) print(u'{:<16}: {}'.format('salience', entity.salience)) print(u'{:<16}: {}'.format('wikipedia_url', @@ -119,7 +119,7 @@ def entities_file(gcs_uri): for entity in entities: print('=' * 20) print(u'{:<16}: {}'.format('name', entity.name)) - print(u'{:<16}: {}'.format('type', entity.type)) + print(u'{:<16}: {}'.format('type', entity_type[entity.type])) print(u'{:<16}: {}'.format('metadata', entity.metadata)) print(u'{:<16}: {}'.format('salience', entity.salience)) print(u'{:<16}: {}'.format('wikipedia_url', From 42ad7f1f718333171471ac84cdf31392902eb2cd Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 8 Aug 2017 14:29:34 -0700 Subject: [PATCH 3/3] correct indent --- language/cloud-client/v1/snippets.py | 4 ++-- language/cloud-client/v1beta2/snippets.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/language/cloud-client/v1/snippets.py b/language/cloud-client/v1/snippets.py index e452fbfa2c6b..704c6347eac0 100644 --- a/language/cloud-client/v1/snippets.py +++ b/language/cloud-client/v1/snippets.py @@ -96,7 +96,7 @@ def entities_text(text): # entity types from enums.Entity.Type entity_type = ('UNKNOWN', 'PERSON', 'LOCATION', 'ORGANIZATION', - 'EVENT', 'WORK_OF_ART', 'CONSUMER_GOOD', 'OTHER') + 'EVENT', 'WORK_OF_ART', 'CONSUMER_GOOD', 'OTHER') for entity in entities: print('=' * 20) @@ -126,7 +126,7 @@ def entities_file(gcs_uri): # entity types from enums.Entity.Type entity_type = ('UNKNOWN', 'PERSON', 'LOCATION', 'ORGANIZATION', - 'EVENT', 'WORK_OF_ART', 'CONSUMER_GOOD', 'OTHER') + 'EVENT', 'WORK_OF_ART', 'CONSUMER_GOOD', 'OTHER') for entity in entities: print('=' * 20) diff --git a/language/cloud-client/v1beta2/snippets.py b/language/cloud-client/v1beta2/snippets.py index 81609a285509..0ea15f7fc42d 100644 --- a/language/cloud-client/v1beta2/snippets.py +++ b/language/cloud-client/v1beta2/snippets.py @@ -87,7 +87,7 @@ def entities_text(text): # entity types from enums.Entity.Type entity_type = ('UNKNOWN', 'PERSON', 'LOCATION', 'ORGANIZATION', - 'EVENT', 'WORK_OF_ART', 'CONSUMER_GOOD', 'OTHER') + 'EVENT', 'WORK_OF_ART', 'CONSUMER_GOOD', 'OTHER') for entity in entities: print('=' * 20) @@ -114,7 +114,7 @@ def entities_file(gcs_uri): # entity types from enums.Entity.Type entity_type = ('UNKNOWN', 'PERSON', 'LOCATION', 'ORGANIZATION', - 'EVENT', 'WORK_OF_ART', 'CONSUMER_GOOD', 'OTHER') + 'EVENT', 'WORK_OF_ART', 'CONSUMER_GOOD', 'OTHER') for entity in entities: print('=' * 20)