@@ -95,14 +95,11 @@ def entities_text(text):
95
95
# document.type == enums.Document.Type.HTML
96
96
entities = client .analyze_entities (document ).entities
97
97
98
- # entity types from enums.Entity.Type
99
- entity_type = ('UNKNOWN' , 'PERSON' , 'LOCATION' , 'ORGANIZATION' ,
100
- 'EVENT' , 'WORK_OF_ART' , 'CONSUMER_GOOD' , 'OTHER' )
101
-
102
98
for entity in entities :
99
+ entity_type = enums .Entity .Type (entity .type )
103
100
print ('=' * 20 )
104
101
print (u'{:<16}: {}' .format ('name' , entity .name ))
105
- print (u'{:<16}: {}' .format ('type' , entity_type [ entity . type ] ))
102
+ print (u'{:<16}: {}' .format ('type' , entity_type . name ))
106
103
print (u'{:<16}: {}' .format ('metadata' , entity .metadata ))
107
104
print (u'{:<16}: {}' .format ('salience' , entity .salience ))
108
105
print (u'{:<16}: {}' .format ('wikipedia_url' ,
@@ -125,14 +122,11 @@ def entities_file(gcs_uri):
125
122
# document.type == enums.Document.Type.HTML
126
123
entities = client .analyze_entities (document ).entities
127
124
128
- # entity types from enums.Entity.Type
129
- entity_type = ('UNKNOWN' , 'PERSON' , 'LOCATION' , 'ORGANIZATION' ,
130
- 'EVENT' , 'WORK_OF_ART' , 'CONSUMER_GOOD' , 'OTHER' )
131
-
132
125
for entity in entities :
126
+ entity_type = enums .Entity .Type (entity .type )
133
127
print ('=' * 20 )
134
128
print (u'{:<16}: {}' .format ('name' , entity .name ))
135
- print (u'{:<16}: {}' .format ('type' , entity_type [ entity . type ] ))
129
+ print (u'{:<16}: {}' .format ('type' , entity_type . name ))
136
130
print (u'{:<16}: {}' .format ('metadata' , entity .metadata ))
137
131
print (u'{:<16}: {}' .format ('salience' , entity .salience ))
138
132
print (u'{:<16}: {}' .format ('wikipedia_url' ,
@@ -158,12 +152,9 @@ def syntax_text(text):
158
152
# document.type == enums.Document.Type.HTML
159
153
tokens = client .analyze_syntax (document ).tokens
160
154
161
- # part-of-speech tags from enums.PartOfSpeech.Tag
162
- pos_tag = ('UNKNOWN' , 'ADJ' , 'ADP' , 'ADV' , 'CONJ' , 'DET' , 'NOUN' , 'NUM' ,
163
- 'PRON' , 'PRT' , 'PUNCT' , 'VERB' , 'X' , 'AFFIX' )
164
-
165
155
for token in tokens :
166
- print (u'{}: {}' .format (pos_tag [token .part_of_speech .tag ],
156
+ part_of_speech_tag = enums .PartOfSpeech .Tag (token .part_of_speech .tag )
157
+ print (u'{}: {}' .format (part_of_speech_tag .name ,
167
158
token .text .content ))
168
159
# [END language_python_migration_syntax_text]
169
160
# [END language_syntax_text]
@@ -183,12 +174,9 @@ def syntax_file(gcs_uri):
183
174
# document.type == enums.Document.Type.HTML
184
175
tokens = client .analyze_syntax (document ).tokens
185
176
186
- # part-of-speech tags from enums.PartOfSpeech.Tag
187
- pos_tag = ('UNKNOWN' , 'ADJ' , 'ADP' , 'ADV' , 'CONJ' , 'DET' , 'NOUN' , 'NUM' ,
188
- 'PRON' , 'PRT' , 'PUNCT' , 'VERB' , 'X' , 'AFFIX' )
189
-
190
177
for token in tokens :
191
- print (u'{}: {}' .format (pos_tag [token .part_of_speech .tag ],
178
+ part_of_speech_tag = enums .PartOfSpeech .Tag (token .part_of_speech .tag )
179
+ print (u'{}: {}' .format (part_of_speech_tag .name ,
192
180
token .text .content ))
193
181
# [END language_syntax_gcs]
194
182
0 commit comments