因为发现了阿里云的情感分析中没有python的用例子,搜到了一个在csdn中的,但是竟然还需要花钱!!!为了技术极客分享的梦想!!!
以下做一个分享。
# -*- coding: utf8 -*-
import json
import os
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
# Initialize AcsClient instance
client = AcsClient(
access_key_id,
access_key_secret,
"cn-hangzhou"
);
messages= "憎恨"
content ={"messages": messages}
# Initialize a request and set parameters
request = CommonRequest()
""# domain和version是固定值
request.set_domain('alinlp.cn-hangzhou.aliyuncs.com')
request.set_version('2020-06-29')
request.set_action_name('GetSaChGeneral')
request.add_query_param('ServiceCode', 'alinlp')
request.add_query_param('Text', json.dumps(content))
response = client.do_action_with_exception(request)
resp_obj = json.loads(response)
print(resp_obj['Data'])