新增直接获取敏感词处理结果方法
This commit is contained in:
parent
14033464cd
commit
2f6387288a
@ -1,17 +1,13 @@
|
|||||||
package com.cm.plugin.manager;
|
package com.cm.plugin.manager;
|
||||||
|
|
||||||
import com.alibaba.druid.sql.visitor.functions.Char;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.omg.CORBA.OBJ_ADAPTER;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When you feel like quitting. Think about why you started
|
* When you feel like quitting. Think about why you started
|
||||||
@ -123,6 +119,33 @@ public class SensitiveWordsManager {
|
|||||||
return sensitiveResult;
|
return sensitiveResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回敏感结果,替换成相应字符
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
* @param replace
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getSensitiveWordsResultWithReplace(String content, char replace) {
|
||||||
|
SensitiveResult sensitiveResult = getSensitiveWordsResult(content);
|
||||||
|
if (sensitiveResult == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<SensitiveWordsResult> sensitiveWordsResults = sensitiveResult.getSensitiveWordsResults();
|
||||||
|
if (sensitiveWordsResults.isEmpty()) {
|
||||||
|
return sensitiveResult.getSensitive();
|
||||||
|
}
|
||||||
|
for (SensitiveWordsResult sensitiveWordsResult : sensitiveWordsResults) {
|
||||||
|
String sensitiveWord = sensitiveWordsResult.getSensitiveWord();
|
||||||
|
StringBuilder replaceSB = new StringBuilder();
|
||||||
|
for (int i = 0; i < sensitiveWord.length(); i++) {
|
||||||
|
replaceSB.append(replace);
|
||||||
|
}
|
||||||
|
sensitiveResult.setSensitive(sensitiveResult.getSensitive().replaceAll(sensitiveWord, replaceSB.toString()));
|
||||||
|
}
|
||||||
|
return sensitiveResult.getSensitive();
|
||||||
|
}
|
||||||
|
|
||||||
private static class SensitiveWordsManagerBuilder {
|
private static class SensitiveWordsManagerBuilder {
|
||||||
public static SensitiveWordsManager sensitiveWordsManager = new SensitiveWordsManager();
|
public static SensitiveWordsManager sensitiveWordsManager = new SensitiveWordsManager();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user