使用前提:服务开通与资源包购买
- 自然语言处理:开通地址
- NLP自学习平台:开通地址
- 自学习平台资源包:购买地址
- 获取阿里云账号的AccessKey ID 和AccessKey Secret
- 授权子账号(无需子账号,可以忽略此步骤):RAM鉴权
操作步骤:
1.添加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.exceptions.ClientException;
import com.aliyuncs.nlp_automl.model.v20191111.RunPreTrainServiceRequest;
import com.aliyuncs.nlp_automl.model.v20191111.RunPreTrainServiceResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.HashMap;
import java.util.Map;
//预训练模型-商品评价解析服务(汽车领域) 调用示例
public class Demo10 {
public static void main(String[] args) throws ClientException{
DefaultProfile defaultProfile = DefaultProfile.getProfile("cn-hangzhou","XXXXXXXXXX","XXXXXXXXXX");
IAcsClient client = new DefaultAcsClient(defaultProfile);
Map<String, Object> input = new HashMap();
input.put("content","频繁上坡起步有含糊味,不知力活片是不是质量有问题。倒档要停稳才能挂。");
input.put("domain","car");
input.put("entity",true);
Map<String, Object> map = new HashMap<>();
map.put("input", input);
RunPreTrainServiceRequest request = new RunPreTrainServiceRequest();
request.setServiceName("aoe-automl-app-car");
//request.setPredictContent(JSON.toJSONString(map));
request.setPredictContent(new Gson().toJson(map));
RunPreTrainServiceResponse response = client.getAcsResponse(request);
System.out.println(response.getPredictResult());
}
}
3.测试结果
{"code":1000,"data":{"cost":"51.409ms","textProb":0.9975,"aspectItem":[{"clause":"频繁上坡起步有含糊味","clauseIndex":"0,10","aspectPolarity":"负","terms":[{"aspectTerm":"频繁上坡起步","opinionTerm":"有含糊味","normedAspectTerm":"频繁上坡起步","normedOpinionTerm":"有含糊味"}],"positiveProb":0.003,"aspectCategory":"异味/气味","negativeProb":0.996},{"clause":"倒档要停稳才能挂","clauseIndex":"25,33","aspectPolarity":"负","terms":[{"aspectTerm":"倒档","opinionTerm":"要停稳才能挂","normedAspectTerm":"倒档","normedOpinionTerm":"要停稳才能挂"}],"positiveProb":0.001,"aspectCategory":"挂挡/换挡","negativeProb":0.999}],"textPolarity":"负"},"message":"SUCCESS","tracerId":"1652318632.896708"}
更多参考
快速入门-模型服务调用流程
预训练模型使用教程
商品评价解析服务-汽车领域
阿里云自然语言处理PHP Core SDK使用Quick Start