我只是能够运行测试而没有任何错误。以下是我采取的步骤:
1. 创建一个新的 IBM Watson Tone Analyzer 实例:
2. 查看服务凭证页面:(
在本示例中,我已将用户名更改为“abcuser”,密码更改为“abcpass”。)
3. 我运行了这个 curl 命令来测试我的服务:
curl -u "{username}":"{password}" -H "Content-Type: application/json" -d "{\"text\": \"Hi Team, I know the times are difficult! Our sales have been disappointing for the past three quarters for our data analytics product suite. We have a competitive data analytics product suite in the industry. But we need to do our job selling it! \"}" "https://gateway.watsonplatform.net/tone-analyzer/api/v3/tone?version=2016-05-19"
所以替换用户名和密码,我得到......
curl -u "abcuser":"abcpass" -H "Content-Type: application/json" -d "{\"text\": \"Hi Team, I know the times are difficult! Our sales have been disappointing for the past three quarters for our data analytics product suite. We have a competitive data analytics product suite in the industry. But we need to do our job selling it! \"}" "https://gateway.watsonplatform.net/tone-analyzer/api/v3/tone?version=2016-05-19"
4. 最后,我得到了这样的回应:
{
"document_tone":{
"tone_categories":[
{
"tones":[
{
"score":0.455891,
"tone_id":"anger",
"tone_name":"Anger"
},
{
"score":0.156707,
"tone_id":"disgust",
"tone_name":"Disgust"
},
{
"score":0.17315,
"tone_id":"fear",
"tone_name":"Fear"
},
{
"score":0.190073,
"tone_id":"joy",
"tone_nam e":"Joy"
},
{
"score":0.291627,
"tone_id":"sadness",
"tone_name":"Sadness"
}
],
"category_id":"emotion_tone",
"category_name":"Emotion Tone"
},
{
"tones":[
{
"score":0.459,
"tone_id":"analytical",
"tone_name":"Analytical"
},
{
"score":0.0,
"tone_id":"confident",
"tone_name":"Confide nt"
},
{
"score":0.0,
"tone_id":"tentative",
"tone_name":"Tentative"
}
],
"category_id":"language_tone",
"category_name":"Language Tone"
},
{
"tones":[
{
"score":0.03,
"tone_id":"openness_big5",
"tone_name":"Openness"
},
{
"score":0.188,
"tone_id":"conscientiousness_big5",
"tone_nam e":"Conscientiousness"
},
{
"score":0.405,
"tone_id":"extraversion_big5",
"tone_name":"Extraversion"
},
{
"score":0.879,
"tone_id":"agreeableness_big5",
"tone_name":"Agreeableness"
},
{
"score":0.962,
"tone_id":"emotional_range_big5",
"tone_name":"Emotional Range"
}
],
"category_ id":"social_tone",
"category_name":"Social Tone"
}
]
}
}
编辑:
如果您在使用 Python SDK 时遇到问题,请尝试以下操作:
import json
from watson_developer_cloud import ToneAnalyzerV3Beta
tone_analyzer = ToneAnalyzerV3Beta(
url='https://gateway.watsonplatform.net/tone-analyzer/api',
username='USERNAME',
password='PASSWORD',
version='2016-02-11')
print(json.dumps(tone_analyzer.tone(text='I am very happy'), indent=2))