我是Python新手,有以下代码:
def doSentimentAnalysisAndPrint(keyval):
import urllib
data = urllib.urlencode(keyval)
u = urllib.urlopen("http://text-processing.com/api/sentiment/", data)
json_string = u.read()
parsed_json = json.loads(json_string)
# print the various key:values
print(parsed_json['probability'])
print ">>", parsed_json['label']
打印结果为:
{u'neg': 0.24087437946650492, u'neutral': 0.19184084028194423, u'pos': 0.7591256205334951}
>> pos
我只想打印出实际结果?例如,在这种情况下,“肯定:0.7591256205334951”,但不知道如何实现这一点
使用时请务必阅读API documentation。
'label'
键指向'probability'
字典中的关键是确定的情绪:所以您已经有了一个标签,相应的值只是一个键查找。将标签值映射到要打印的字符串(如
pos
映射到Positive
),并将两者结合起来:相关问题 更多 >
编程相关推荐