获取SDK

在pom.xml文件中引用sdk的maven依赖。

<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>aliyun-java-sdk-nlp-automl</artifactId>
  <version>0.0.2</version>
</dependency>

使用示例

SDK使用方法举例。

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.nlp_automl.model.v20191111.GetPredictResultRequest;
import com.aliyuncs.nlp_automl.model.v20191111.GetPredictResultResponse;
import com.aliyuncs.profile.DefaultProfile;

public class NlpAutomlTestApp {
    public static void main(String[] args) throws ClientException {
        DefaultProfile profile = DefaultProfile.getProfile(
            "cn-hangzhou",
            "<your-access-key-id>",
            "<your-access-key-secret>");
        IAcsClient client = new DefaultAcsClient(profile);

        GetPredictResultRequest request = new GetPredictResultRequest();
        request.setModelId(1818);
        request.setContent("中华人民共和国人民解放军");
        GetPredictResultResponse response = client.getAcsResponse(request);
        System.out.println(response.getContent());
    }
}

执行结果

不同模型类型返回结果会有不同。

{
  "requestId": "85A1B6AC-DB09-4623-B8BC-10A9F24DB9F7",
  "content": "[\"人民解放军\",\"中华人民共和国\"]"
}