googleapis/python-language

AttributeError: module 'google.cloud.language_v1' has no attribute 'PartOfSpeech'

Closed this issue · 1 comments

Hi,

I'm using the sample code provided at the documentation to analyze_syntax, but the following part is not working:

response = client.analyze_syntax(request = {'document': document, 'encoding_type': encoding_type})
# Loop through tokens returned from the API
for token in response.tokens:
# Get the text content of this token. Usually a word or punctuation.
text = token.text
print(u"Token text: {}".format(text.content))
print(
u"Location of this token in overall document: {}".format(text.begin_offset)
)
# Get the part of speech information for this token.
# Parts of spech are as defined in:
# http://www.lrec-conf.org/proceedings/lrec2012/pdf/274_Paper.pdf
part_of_speech = token.part_of_speech
# Get the tag, e.g. NOUN, ADJ for Adjective, et al.
print(
u"Part of Speech tag: {}".format(
language_v1.PartOfSpeech.Tag(part_of_speech.tag).name
)
)

it returns an error: AttributeError: module 'google.cloud.language_v1' has no attribute 'PartOfSpeech'

What should I do to fix this?
Thank you.

I found out how to use it,
instead of : language_v1.PartOfSpeech.Tag(part_of_speech.tag).name
it should be: language_v1.types.PartOfSpeech.Tag.Name(part_of_speech.tag)

The documentation needs to be updated.