Commit 1fe20bb451793ea35acd75e21b571dbe12d6898f

Authored by 徐近程
1 parent 3fecec28

易盾文本解析update

src/main/java/com/cnlive/shenhe/enums/TextLabels.java 0 → 100644
  1 +package com.cnlive.shenhe.enums;
  2 +
  3 +/**
  4 + * @Author: xujincheng
  5 + * @Date: 2020/6/22 14:08
  6 + */
  7 +public enum TextLabels {
  8 +
  9 + PORNOGRAPHIC("色情", 100), ADVERTISEMENT("广告", 200), VIOLENTFEAR("暴恐", 300),
  10 + CONTRABAND("违禁", 400), POLITICSINVOLVED("涉政", 500), ABUSE("谩骂", 600),
  11 + IRRIGATION("灌水", 700), OTHER("其他", 900);
  12 +
  13 + private String name;
  14 + private int index;
  15 +
  16 + TextLabels(String name, int index) {
  17 + this.name = name;
  18 + this.index = index;
  19 + }
  20 +
  21 + public static String getName(int index) {
  22 + for (TextLabels c : TextLabels.values()) {
  23 + if (c.getIndex() == index) {
  24 + return c.name;
  25 + }
  26 + }
  27 + return null;
  28 + }
  29 +
  30 + public String getName() {
  31 + return name;
  32 + }
  33 +
  34 + public void setName(String name) {
  35 + this.name = name;
  36 + }
  37 +
  38 + public int getIndex() {
  39 + return index;
  40 + }
  41 +}
... ...
src/main/java/com/cnlive/shenhe/job/YiDunUrlResultJob.java
... ... @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
4 4 import com.alibaba.fastjson.JSONObject;
5 5 import com.cnlive.shenhe.entity.ShyContent;
6 6 import com.cnlive.shenhe.entity.ShyYidun;
  7 +import com.cnlive.shenhe.enums.TextLabels;
7 8 import com.cnlive.shenhe.serviceImpl.ContentServiceImpl;
8 9 import com.cnlive.shenhe.serviceImpl.YiDunServiceImpl;
9 10 import com.cnlive.shenhe.utils.CommonConst;
... ... @@ -106,7 +107,7 @@ public class YiDunUrlResultJob {
106 107 newYiDunMsg.setDesc_msg(desc);
107 108 //修改图文状态
108 109 contentServiceImpl.callback(yiDunMsg.getContent_id(), desc, CommonConst.AUDIT_SUCCESS, "", "机审通过");
109   - desc="";
  110 + desc="易盾网站审核";
110 111 } else {
111 112 JSONObject evidences = jsonObject.getJSONObject("evidences");
112 113 JSONArray texts = evidences.getJSONArray("texts");
... ... @@ -115,12 +116,26 @@ public class YiDunUrlResultJob {
115 116 JSONObject jsonObject1 = texts.getJSONObject(j);
116 117 //检测结果,0:通过,1:嫌疑,2:不通过
117 118 int action = jsonObject1.getIntValue("action");
  119 + String labelMsg="";
  120 + if(action!=0){
  121 + JSONArray labels = jsonObject1.getJSONArray("labels");
  122 + labelMsg="(";
  123 + if(labels!=null&&labels.size()>0){
  124 + for (Object obj : labels) {
  125 + JSONObject jsonObjectone = (JSONObject) obj;
  126 + Integer label = jsonObjectone.getInteger("label");
  127 + String name = TextLabels.getName(label);
  128 + labelMsg=labelMsg+name;
  129 +
  130 + }
  131 + }
  132 + }
118 133 if (action == 1) {
119   - desc = desc + "文字嫌疑";
  134 + desc = desc + "文字嫌疑"+labelMsg+")";
120 135 break;
121 136 }
122 137 if (action == 2) {
123   - desc = desc + "文字违规";
  138 + desc = desc + "文字违规"+labelMsg+")";
124 139 break;
125 140 }
126 141 }
... ...
src/main/java/com/cnlive/shenhe/utils/YiDunAntiFraudUtil.java
... ... @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
4 4 import com.alibaba.fastjson.JSONObject;
5 5 import com.cnlive.shenhe.api.AvsampleCallBackControllerApi;
6 6 import com.cnlive.shenhe.entity.ShyYidun;
  7 +import com.cnlive.shenhe.enums.TextLabels;
7 8 import com.cnlive.shenhe.serviceImpl.YiDunServiceImpl;
8 9 import org.apache.commons.codec.digest.DigestUtils;
9 10 import org.slf4j.Logger;
... ... @@ -76,7 +77,7 @@ public class YiDunAntiFraudUtil {
76 77 public static void main(String[] args) {
77 78  
78 79 //智能文本识别审核测试
79   - //getTextFilter("好人");
  80 + getTextFilter("王八蛋");
80 81  
81 82 //智能图片识别审核测试
82 83 /*JSONArray jsonArray = new JSONArray();
... ... @@ -140,17 +141,32 @@ public class YiDunAntiFraudUtil {
140 141 //检测结果,0:通过,1:嫌疑,2:不通过
141 142 int action = resultJsonObject.getIntValue("action");
142 143 String taskId = resultJsonObject.getString("taskId");
  144 + String labelMsg="";
  145 + if(action!=0){
  146 + JSONArray labels = resultJsonObject.getJSONArray("labels");
  147 + labelMsg="(";
  148 + if(labels!=null&&labels.size()>0){
  149 + for (Object obj : labels) {
  150 + JSONObject jsonObjectone = (JSONObject) obj;
  151 + Integer label = jsonObjectone.getInteger("label");
  152 + String name = TextLabels.getName(label);
  153 + labelMsg=labelMsg+name;
  154 +
  155 + }
  156 + }
  157 + }
  158 +
143 159 if (action == 0) {
144 160 jsonObj.put("type", "PASS");
145   - jsonObj.put("desc", "易盾审核通过");
  161 + jsonObj.put("desc", "易盾文本审核通过");
146 162 }
147 163 if (action == 1) {
148 164 jsonObj.put("type", "REJECT");
149   - jsonObj.put("desc", "文本嫌疑");
  165 + jsonObj.put("desc", "易盾文本审核文本嫌疑"+labelMsg+")");
150 166 }
151 167 if (action == 2) {
152 168 jsonObj.put("type", "REJECT");
153   - jsonObj.put("desc", "文本违规");
  169 + jsonObj.put("desc", "易盾文本审核文本违规"+labelMsg+")");
154 170 }
155 171 jsonObj.put("taskId", taskId);
156 172 logger.info("审核云文本识别处理后结果:{}", jsonObj.toString());
... ...