我试着运行一个情绪分析样本,遵循以下指南: https://cloud.google.com/natural-language/docs/analyzing-sentiment#language-sentiment-string-python
但是,在运行示例时,我得到以下错误:
AttributeError: 'Client' object has no attribute 'analyze_sentiment'
下面是我正在尝试的代码:
def sentiment_text(text):
"""Detects sentiment in the text."""
client = language.Client.from_service_account_json('<my_creds>')
if isinstance(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 sentiment in the document. You can also analyze HTML
with:
# document.type == enums.Document.Type.HTML
sentiment = client.analyze_sentiment(document).document_sentiment
print('Score: {}'.format(sentiment.score))
print('Magnitude: {}'.format(sentiment.magnitude))
我似乎找不到关于这个错误的任何文档-我遗漏了什么吗?在
目前没有回答
相关问题 更多 >
编程相关推荐