"; //text="天涯无处可寻,我的迷失天堂!"; text=strResulta; try { text=text.replaceAll(" ", ""); //创建一个接口 //HttpUtils.HttpResponse//得到对象 //text 需要分词的内容 cut_threshold:如果设置了此参数,会返回所有概率不低于cut_threshold的词语,如果没设则默认是0.5 HttpUtils.HttpResponse response = HttpUtils.sendGet("http://www.datatang.com/webapi/cloud/sensitive/words", "text=" text "&apikey=" apiKey );// System.out.println(response);//结果在控制台输出 //创建一个如下的对象 // {"errno": 0, "data": [{"word": "迷失天堂", "score": 0.999279, "tag": "不良事件名称", "sentiment": "negative"}, {"word": "天堂", "score": 0.985262, "tag": "词语", "sentiment": "neutral"}, {"word": "我的", "score": 0.999288, "tag": "我称", "sentiment": "neutral"}, {"word": "天涯", "score": 0.982305, "tag": "词语", "sentiment": "neutral"}, {"word": "迷失", "score": 0.975591, "tag": "不良事件名称", "sentiment": "negative"}]} JSONObject json = JSONObject.fromObject(response.getResponseBody()); //得到一个对象 System.out.println("response data:" response.getResponseBody());//结果在控制台获取 String dataArray = json.getString("data"); JSONArray jsonarray = JSONArray.fromObject(dataArray); //获取第一个对象 JSONObject JsonObject = (JSONObject)jsonarray.get(0); System.out.println("JsonObject:" JsonObject.toString()); System.out.println("errno:" json.getString("errno")); //词语 String word = JsonObject.getString("word"); System.out.println("word:" word); //概率 String score = JsonObject.getString("score"); System.out.println("score:" score); //情感极性,每一个词语都有结果 String sentiment = JsonObject.getString("sentiment"); System.out.println("sentiment:" sentiment); //词性 String tag = JsonObject.getString("tag"); System.out.println("tag:" tag); } catch (Exception e) { e.printStackTrace(); } }}
免責聲明:若本站收錄的資源侵犯了您的權益,我們會及時刪除侵權內容,謝謝合作!