Feature Request: add support for accessing display name of enum values
For example:
fromgoogle.cloudimportlanguagefromgoogle.cloud.languageimportenumsfromgoogle.cloud.languageimporttypesclient=language.LanguageServiceClient()
document=types.Document(content=text, type=enums.Document.Type.PLAIN_TEXT)
tokens=client.analyze_syntax(document).tokensfortokenintokens:
print(token.part_of_speech.tag) # <-- tag is an enum field.# link below to RPC reference for Tag.
Expected result, based on all of the other languages' GAPIC clients:
Actual result:
I get the expected result when using GAPIC client libraries in all of the other languages.
I would characterize the current behavior as: surprising
The current developer experience, if you want to access the enum values:
- Find the relevant enum, eg. Natural Language Part of Speech Tag (noun, verb, pronoun, etc)
- Copy the display names into an indexed list in your program,
tag_names = ('UNKNOWN', 'ADJ', 'ADP', 'ADV', 'CONJ', 'DET', 'NOUN', 'NUM', 'PRON', 'PRT', 'PUNCT', 'VERB', 'X', 'AFFIX') - Access the display name using the enum index
int value available on the pb object - Check back on the .proto occasionally incase new enum values have been appended
There may be a better way, but this is the process we use to author our Python samples.
Example: sample for analyzing syntax of text (natural-language/docs/analyzing-syntax)
defsyntax_text(text):
"""Detects syntax in the text."""client=language.LanguageServiceClient()
ifisinstance(text, six.binary_type):
text=text.decode('utf-8')
# Instantiates a plain text document.document=types.Document(
content=text,
type=enums.Document.Type.PLAIN_TEXT)
# Detects syntax in the document. You can also analyze HTML with:# document.type == enums.Document.Type.HTMLtokens=client.analyze_syntax(document).tokens# part-of-speech tags from enums.PartOfSpeech.Tagpos_tag= ('UNKNOWN', 'ADJ', 'ADP', 'ADV', 'CONJ', 'DET', 'NOUN', 'NUM',
'PRON', 'PRT', 'PUNCT', 'VERB', 'X', 'AFFIX')
fortokenintokens:
print(u'{}: {}'.format(pos_tag[token.part_of_speech.tag],
token.text.content))/cc @lukesneeringer
/fyi @vchudnov-g@pongad@theacodes
Feature Request: add support for accessing display name of enum values
For example:
Expected result, based on all of the other languages' GAPIC clients:
Actual result:
I get the expected result when using GAPIC client libraries in all of the other languages.
I would characterize the current behavior as: surprising
The current developer experience, if you want to access the enum values:
tag_names = ('UNKNOWN', 'ADJ', 'ADP', 'ADV', 'CONJ', 'DET', 'NOUN', 'NUM', 'PRON', 'PRT', 'PUNCT', 'VERB', 'X', 'AFFIX')intvalue available on the pb objectThere may be a better way, but this is the process we use to author our Python samples.
Example: sample for analyzing syntax of text (natural-language/docs/analyzing-syntax)
/cc @lukesneeringer
/fyi @vchudnov-g@pongad@theacodes