Google Cloud Natural Language API(使用Python):实体情感得分和幅度始终为0

时间:2019-08-09 14:24:00

标签: python google-cloud-platform nlp entity sentiment-analysis

我正在尝试使用google.cloud实体情感分析。我已经设法设置好一切;实体分析和情绪分析正在工作。但是,如果我尝试进行实体情感分析,则无论我分析的是什么文本,它总是返回值0(表示分数和大小)。

from google.cloud import language
client = language.LanguageServiceClient()
document = language.types.Document(content='This is a terrible         
example. It is not such a good idea.', type='PLAIN_TEXT')
response = client.analyze_sentiment(document=document, 
encoding_type='UTF32')

response = client.analyze_entities(
           document=document,
           encoding_type='UTF32')
for entity in response.entities:
    print('=' * 20)
    print(' name: {0}'.format(entity.name))
    print(' type: {0}'.format(entity.type))
    print(' metadata: {0}'.format(entity.metadata))
    print(' salience: {0}'.format(entity.salience))
    print(' sentiment score: {0}'.format(entity.sentiment.score))
    print(' sentiment magnitude: {0}'.format(entity.sentiment.magnitude))

当前返回:

===================

     name: example
 type: 7
 metadata: {}
 salience: 0.9236434102058411
 sentiment score: 0.0
 sentiment magnitude: 0.0

===================

     name: idea
 type: 7
 metadata: {}
 salience: 0.07635658979415894
 sentiment score: 0.0
 sentiment magnitude: 0.0

我希望更改代码,以便呈现情感得分和幅度,而不是始终显示0。感谢您的帮助!

0 个答案:

没有答案