阿里云自然语言处理--命名实体识别(中文高级版)Quick Start

使用前提与环境准备:服务开通与购买


Step By Step

1.参考API文档与公共参数文档获取相应请求参数

阿里云自然语言处理--命名实体识别(中文高级版)Quick Start

  • 公共参数说明

阿里云自然语言处理--命名实体识别(中文高级版)Quick Start

2.添加pom依赖

        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
            <version>4.5.25</version>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-nlp-automl</artifactId>
            <version>0.0.5</version>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-alinlp</artifactId>
            <version>1.0.16</version>
       </dependency>

2.Code Sample

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;

//命名实体识别(中文高级版)common request 调用示例
public class MingMst {
    public static void main(String[] args) {
        // 创建DefaultAcsClient实例并初始化
        DefaultProfile defaultProfile = DefaultProfile.getProfile(
                "cn-hangzhou",
                "XXXXXXXXXX",
                "XXXXXXXXXX");
        IAcsClient client = new DefaultAcsClient(defaultProfile);
        // 创建API请求并设置参数
        CommonRequest request = new CommonRequest();
        // domain和version是固定值
        request.setDomain("alinlp.cn-hangzhou.aliyuncs.com");
        request.setVersion("2020-06-29");
        //action name可以在API文档里查到
        request.setSysAction("GetNerCustomizedChEcom");//请求的接口名称
        //put的参数可以在API文档查看到
        request.putQueryParameter("ServiceCode", "alinlp");
        request.putQueryParameter("Text", "这是一个小米手机");
        request.putQueryParameter("TokenizerId", "ECOM");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClientException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

3.测试结果

{"RequestId":"19D23654-4058-5A07-962B-213FB34625BA","Data":"{\"result\":[{\"synonym\":\"\",\"weight\":\"0.100000\",\"tag\":\"普通词\",\"word\":\"这\"},{\"synonym\":\"\",\"weight\":\"0.100000\",\"tag\":\"普通词\",\"word\":\"是\"},{\"synonym\":\"\",\"weight\":\"0.100000\",\"tag\":\"普通词\",\"word\":\"一个\"},{\"synonym\":\"\",\"weight\":\"0.800000\",\"tag\":\"品牌\",\"word\":\"小米\"},{\"synonym\":\"\",\"weight\":\"1.000000\",\"tag\":\"品类\",\"word\":\"手机\"}],\"success\":true}"}

更多参考

快速入门
API参考-命名实体识别(中文高级版)
SDK示例
阿里云自然语言处理PHP Core SDK使用Quick Start

上一篇:中国人工智能学会通讯——蚂蚁金服智能金融实践


下一篇:能量收集通信 | 带你读《5G系统关键技术详解》之五