Skip to content

Commit 4cd49b3

Browse files
dizcologyJon Wayne Parrott
authored and
Jon Wayne Parrott
committed
show entity type name [(#1062)](GoogleCloudPlatform/python-docs-samples#1062)
* show entity type name * update v1beta2 * correct indent
1 parent 34a081f commit 4cd49b3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

samples/snippets/snippets.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,14 @@ def entities_text(text):
9494
# document.type == enums.Document.Type.HTML
9595
entities = client.analyze_entities(document).entities
9696

97+
# entity types from enums.Entity.Type
98+
entity_type = ('UNKNOWN', 'PERSON', 'LOCATION', 'ORGANIZATION',
99+
'EVENT', 'WORK_OF_ART', 'CONSUMER_GOOD', 'OTHER')
100+
97101
for entity in entities:
98102
print('=' * 20)
99103
print(u'{:<16}: {}'.format('name', entity.name))
100-
print(u'{:<16}: {}'.format('type', entity.type))
104+
print(u'{:<16}: {}'.format('type', entity_type[entity.type]))
101105
print(u'{:<16}: {}'.format('metadata', entity.metadata))
102106
print(u'{:<16}: {}'.format('salience', entity.salience))
103107
print(u'{:<16}: {}'.format('wikipedia_url',
@@ -120,10 +124,14 @@ def entities_file(gcs_uri):
120124
# document.type == enums.Document.Type.HTML
121125
entities = client.analyze_entities(document).entities
122126

127+
# entity types from enums.Entity.Type
128+
entity_type = ('UNKNOWN', 'PERSON', 'LOCATION', 'ORGANIZATION',
129+
'EVENT', 'WORK_OF_ART', 'CONSUMER_GOOD', 'OTHER')
130+
123131
for entity in entities:
124132
print('=' * 20)
125133
print(u'{:<16}: {}'.format('name', entity.name))
126-
print(u'{:<16}: {}'.format('type', entity.type))
134+
print(u'{:<16}: {}'.format('type', entity_type[entity.type]))
127135
print(u'{:<16}: {}'.format('metadata', entity.metadata))
128136
print(u'{:<16}: {}'.format('salience', entity.salience))
129137
print(u'{:<16}: {}'.format('wikipedia_url',

0 commit comments

Comments
 (0)