源码:
package com.jeson.ceshi; import java.util.HashMap; import org.json.JSONObject; import com.baidu.aip.nlp.AipNlp; public class demo { //设置APPID/AK/SK public static final String APP_ID = "*****"; public static final String API_KEY = "*************"; public static final String SECRET_KEY = "******"; public static void main(String[] args) { // 初始化一个AipNlp AipNlp client = new AipNlp(APP_ID, API_KEY, SECRET_KEY); // 可选:设置网络连接参数 client.setConnectionTimeoutInMillis(2000); client.setSocketTimeoutInMillis(60000); sample(client); } public static void sample(AipNlp client) { String text = "苹果是一家伟大的公司"; // 传入可选参数调用接口 HashMap<String, Object> options = new HashMap<String, Object>(); // 情感倾向分析 JSONObject res = client.sentimentClassify(text, options); System.out.println(res.toString(2)); } }
结果:
参加百度云具体事例。