Step By Step
step1:开通服务
参考地址
目前NLP提供了三个版本,可根据需要选择合适的,本次调用选用基础版本
step2:获取账号的AccessKey
参考文档:获取AccessKey
step3:添加依赖
pip install aliyun-python-sdk-core # 安装阿里云SDK核心库
step4:Common code
import json
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
# 创建AcsClient实例
client = AcsClient(
"<your-access-id-key>",
"<your-access-id-secret>",
"cn-hangzhou"
)
request = CommonRequest()
# domain和version是固定值
request.set_domain('alinlp.cn-hangzhou.aliyuncs.com')
request.set_version('2020-06-29')
# action name可以在API文档里查到
request.set_action_name('GetWsCustomizedChGeneral')
# 需要add哪些param可以在API文档里查到
request.add_query_param('ServiceCode', 'alinlp')
request.add_query_param('Text', '云麦好轻智能体脂秤精准蓝牙秤体重测人体脂肪秤家用称健康电子秤')
request.add_query_param('TokenizerId', 'GENERAL_CHN')
response = client.do_action_with_exception(request)
resp_obj = json.loads(response)
print(resp_obj)
step5:运行结果
{'RequestId': '19FD650C-CD78-5705-851A-B2C9DFA4215A', 'Data': '{"result":[{"id":"0","word":"云麦","tags":["其他专名"]},{"id":"1","word":"好","tags":["基本词-中文","文体娱乐类-flash作品"]},{"id":"2","word":"轻","tags":["基本词-中文"]},{"id":"3","word":"智能","tags":["产品类型修饰词","基本词-中文","软件-纯软件名"]},{"id":"4","word":"体","tags":["基本词-中文"]},{"id":"5","word":"脂","tags":["基本词-中文"]},{"id":"6","word":"秤","tags":["产品类型-简单","基本词-中文"]},{"id":"7","word":"精准","tags":["基本词-中文","产品-品牌"]},{"id":"8","word":"蓝牙","tags":["产品类型-简单","基本词-中文","产品类型修饰词","软件-纯软件名"]},{"id":"9","word":"秤","tags":["产品类型-简单","基本词-中文"]},{"id":"10","word":"体重","tags":["基本词-中文","产品类型属性词","产品类型修饰词"]},{"id":"11","word":"测","tags":["基本词-中文"]},{"id":"12","word":"人体","tags":["产品类型修饰词","基本词-中文","色情词汇-中文"]},{"id":"13","word":"脂肪秤","tags":["产品类型-简单","基本词-中文","产品类型修饰词"]},{"id":"14","word":"家用称","tags":["产品类型-简单"]},{"id":"15","word":"健康","tags":["基本词-中文","产品类型修饰词","文体娱乐类-书文课程类"]},{"id":"16","word":"电子秤","tags":["产品类型-简单","基本词-中文","产品类型修饰词"]}],"success":true}'}