运用前提与环境预备:服务注册与购买
Step By Step
1.参阅API文档与公共参数文档获取相应恳求参数
2.添加pom依靠
<groupId>com.aliyungroupId> <artifactId>aliyun-java-sdk-coreartifactId> <version>4.5.25version> </dependency>com.aliyunroupId> <artifactId>aliyun-java-sdk-nlp-automlartifactId> <version>0.0.5version> </dependency>com.aliyunroupId> <artifactId>aliyun-java-sdk-alinlpartifactId> <version>1.0.16version> </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; public class ZinWenbf {
public static void main(String[] args) { DefaultProfile defaultProfile = DefaultProfile.getProfile( "cn-hangzhou", "XXXXXXXXXX", "XXXXXXXXXX");
IAcsClient client = new DefaultAcsClient(defaultProfile); CommonRequest request = new CommonRequest(); request.setDomain("alinlp.cn-hangzhou.aliyuncs.com");
request.setVersion("2020-06-29"); request.setSysAction("GetTcChGeneral"); request.putQueryParameter("ServiceCode", "alinlp"); request.putQueryParameter("Text", "这是一段新闻内容"); try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
} catch (ServerException e) { e.printStackTrace();
} catch (ClientException e) { e.printStackTrace();
}
}
}
3.测试成果
{"RequestId":"0F195033-3AA1-5847-9567-5095801570D8","Data":"{\"result\":{\"labelName\":\"文娱\"},\"success\":true,\"tracerId\":\"56e8f03395827b8c65135806d0afb1b7\"}"}
更多参阅
快速入门
API参阅-智能文本分类(新闻)
SDK示例
阿里云自然语言处理PHP Core SDK运用Quick Start
我有话说: