使用前提与环境准备:服务开通与购买
Step By Step
1.参考API文档与公共参数文档获取相应请求参数
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.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.alinlp.model.v20200629.GetPosChEcomRequest;
import com.aliyuncs.alinlp.model.v20200629.GetPosChEcomResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
// 这里以词性标注(电商)为例,其它算法的API名称和参数请参考文档
public class TestCloud {
public static void main(String[] args) throws ClientException {
DefaultProfile defaultProfile = DefaultProfile.getProfile(
"cn-hangzhou",
"XXXXXXXXXX",
"XXXXXXXXXX");
IAcsClient client = new DefaultAcsClient(defaultProfile);
GetPosChEcomRequest request = new GetPosChEcomRequest(); //请求的接口名称
request.setSysEndpoint("alinlp.cn-hangzhou.aliyuncs.com");
request.setServiceCode("alinlp");
request.setText("这是一条文本");
request.setTokenizerId("MAINSE");
long start = System.currentTimeMillis();
GetPosChEcomResponse response = client.getAcsResponse(request);
System.out.println(response.hashCode());
System.out.println(response.getRequestId() + "\n" + response.getData() + "\n" + "cost:" + (System.currentTimeMillis()- start));
}
}
3.测试结果
RequestId:BE871C7D-AAC5-5EBF-9941-23766FF2F8BC
{"result":[{"pos":"PN","word":"这"},{"pos":"VC","word":"是"},{"pos":"JJ","word":"一条"},{"pos":"NN","word":"文本"}],"success":true}
更多参考
快速入门
API参考-词性标注(电商)
SDK示例
阿里云自然语言处理PHP Core SDK使用Quick Start