java过滤敏感词代码

问题

  • java过滤敏感词代码怎么写?
  • java实现敏感词判断怎么写?
  • java怎么实现敏感词过滤代码?

过滤敏感词简介

  • 提供智能鉴黄、涉政检测、暴恐违禁等 在线敏感词检测、在线敏感词过滤服务,
  • 可部署至「本地服务器」或「云服务器」,保障数据私密性,提供一键启动私有化部署包。
  • 『开箱即用的检测服务』

先下载本地部署包

选择其一下载即可

  • www.wordscheck.com
  • github.com/bosnzt/word…
  • gitee.com/bosnzt/word…

私有化部署优势

  • 不限调用次数;
  • 支持自定义词条;
  • 直接服务器本地检测,低网络延迟、内容隐私。

部署硬件配置要求

普通云机器即可:CPU=1核/2核,内存200M

部署(Linux环境示例)

下载svc文件夹到服务器,运行

[root@localhost svc]# ls
blacklist.txt  config.ini  whitelist.txt  wordscheck
[root@localhost svc]# ./wordscheck

完整部署文档

部署文档地址

java过滤敏感词代码

import java.net.HttpURLConnection;
import java.net.URL;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.json.JSONObject;

public class JavaCase {
    public static void main(String[] args) throws Exception {
        //检测服务的地址
        String url = "http://localhost:8080/wordscheck";
        JSONObject jsonObject = new JSONObject();
        //检测内容
        jsonObject.put("content", "他在传播艳情内容");
        String jsonOutput = jsonObject.toString();

        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        con.setRequestMethod("POST");
        con.setRequestProperty("Content-Type", "application/json");

        con.setDoOutput(true);
        OutputStream os = con.getOutputStream();
        os.write(jsonOutput.getBytes());
        os.flush();
        os.close();

        int responseCode = con.getResponseCode();
        System.out.println("Response Code : " + responseCode);

        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();

        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();

        System.out.println(response.toString());
    }
}

pom.xml配置

    

            org.json
            json
            20230227

过滤结果示例

{
    "code": "0",
    "msg": "检测成功",
    "return_str": "他在传播**内容",
    "word_list": [{
        "keyword": "艳情",
        "category": "色情",
        "position": "4-5",
        "level": "高"
    }]
}