feat: SensitiveWords

main
wangqing 11 months ago
parent ea0f431a0d
commit 980a52a062

@ -1,4 +1,4 @@
package com.luoo.comment.sensitiveword; package com.luoo.comment.sensitiveWord;
import com.github.houbb.sensitive.word.api.IWordAllow; import com.github.houbb.sensitive.word.api.IWordAllow;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -15,8 +15,6 @@ public class MyDdWordAllow implements IWordAllow {
list.add("五星红旗"); list.add("五星红旗");
list.add("天安门"); list.add("天安门");
return list; return list;
} }

@ -1,27 +1,34 @@
package com.luoo.comment.sensitiveword; package com.luoo.comment.sensitiveWord;
import com.github.houbb.sensitive.word.api.IWordDeny; import com.github.houbb.sensitive.word.api.IWordDeny;
import constants.SensitiveWords; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@Component @Component
public class MyDdWordDeny implements IWordDeny { public class MyDdWordDeny implements IWordDeny {
String DENY_WORDS= SensitiveWords.DENY_WORDS;
@Override @Override
public List<String> deny() { public List<String> deny() {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
// list.add("落网"); list.add("落网");
Resource mySensitiveWords = new ClassPathResource("denyWords.txt");
try {
Path mySensitiveWordsPath = Paths.get(mySensitiveWords.getFile().getPath());
list = Files.readAllLines(mySensitiveWordsPath, StandardCharsets.UTF_8);
String[] s = DENY_WORDS.split("\n"); } catch (IOException e) {
for(String denyWord:s) { throw new RuntimeException(e);
list.add(denyWord);
} }
return list; return list;
} }
} }

@ -16,8 +16,6 @@ public class SensitiveWordService {
* <p> * <p>
* 使 * 使
*/ */
public void refresh() { public void refresh() {
// 每次数据库的信息发生变化之后,首先调用更新数据库敏感词库的方法,然后调用这个方法。 // 每次数据库的信息发生变化之后,首先调用更新数据库敏感词库的方法,然后调用这个方法。
sensitiveWordBs.init(); sensitiveWordBs.init();

Loading…
Cancel
Save