@@ -95,14 +95,11 @@ def entities_text(text):
9595 # document.type == enums.Document.Type.HTML
9696 entities = client .analyze_entities (document ).entities
9797
98- # entity types from enums.Entity.Type
99- entity_type = ('UNKNOWN' , 'PERSON' , 'LOCATION' , 'ORGANIZATION' ,
100- 'EVENT' , 'WORK_OF_ART' , 'CONSUMER_GOOD' , 'OTHER' )
101-
10298 for entity in entities :
99+ entity_type = enums .Entity .Type (entity .type )
103100 print ('=' * 20 )
104101 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 ))
106103 print (u'{:<16}: {}' .format ('metadata' , entity .metadata ))
107104 print (u'{:<16}: {}' .format ('salience' , entity .salience ))
108105 print (u'{:<16}: {}' .format ('wikipedia_url' ,
@@ -125,14 +122,11 @@ def entities_file(gcs_uri):
125122 # document.type == enums.Document.Type.HTML
126123 entities = client .analyze_entities (document ).entities
127124
128- # entity types from enums.Entity.Type
129- entity_type = ('UNKNOWN' , 'PERSON' , 'LOCATION' , 'ORGANIZATION' ,
130- 'EVENT' , 'WORK_OF_ART' , 'CONSUMER_GOOD' , 'OTHER' )
131-
132125 for entity in entities :
126+ entity_type = enums .Entity .Type (entity .type )
133127 print ('=' * 20 )
134128 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 ))
136130 print (u'{:<16}: {}' .format ('metadata' , entity .metadata ))
137131 print (u'{:<16}: {}' .format ('salience' , entity .salience ))
138132 print (u'{:<16}: {}' .format ('wikipedia_url' ,
@@ -158,12 +152,9 @@ def syntax_text(text):
158152 # document.type == enums.Document.Type.HTML
159153 tokens = client .analyze_syntax (document ).tokens
160154
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-
165155 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 ,
167158 token .text .content ))
168159 # [END language_python_migration_syntax_text]
169160# [END language_syntax_text]
@@ -183,12 +174,9 @@ def syntax_file(gcs_uri):
183174 # document.type == enums.Document.Type.HTML
184175 tokens = client .analyze_syntax (document ).tokens
185176
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-
190177 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 ,
192180 token .text .content ))
193181# [END language_syntax_gcs]
194182
0 commit comments