天天看點

基于阿裡雲自然語言處理基礎版實作中文分詞Step By Step參考文檔

Step By Step

step1:開通服務

參考位址

目前NLP提供了三個版本,可根據需要選擇合适的,本次調用選用基礎版本

基于阿裡雲自然語言處理基礎版實作中文分詞Step By Step參考文檔

step2:擷取賬号的AccessKey

參考文檔:

擷取AccessKey
基于阿裡雲自然語言處理基礎版實作中文分詞Step By Step參考文檔

step3:Java SDK Code

package org.nlp;
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;
public class GetEcChGeneral {
    public static void main(String[] args) throws ClientException {
        DefaultProfile defaultProfile = DefaultProfile.getProfile(
                "cn-hangzhou",
                "ak",
                "sk");
        IAcsClient client = new DefaultAcsClient(defaultProfile);
        GetPosChEcomRequest request = new GetPosChEcomRequest();
        request.setSysEndpoint("alinlp.cn-hangzhou.aliyuncs.com");
        request.setActionName("GetWsChGeneral");
        request.setServiceCode("alinlp");
        request.setText("1997年我學會了開汽車");
        request.setTokenizerId("GENERAL_CHN");
        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));
    }
}           

運作結果:

基于阿裡雲自然語言處理基礎版實作中文分詞Step By Step參考文檔

參考文檔

自然語言處理