AI实现文本审核

1.首先导入jar包

com.baidu.aip
java-sdk
${version}

2.调取百度API文档实现AI实现文本审核
.package com.zlkj.data.portals.service.AipContentCensor;

import com.baidu.aip.contentcensor.AipContentCensor;
import org.json.JSONObject;

import java.io.*;

public class Sample {

//设置APPID/AK/SK
public static final String APP_ID = "17088823";
public static final String API_KEY = "xiS4XGHkkqbx45D25KkBlKCL";
public static final String SECRET_KEY = "Xbooc9dpHc2PG10NOFa4n0W2WUWmDGRE";

public static void main(String[] args) {
    String file = "C:\\\\Users\\\\35011\\\\Desktop\\\\a.txt";
    String str = a(file);
    JSONObject response = client.textCensorUserDefined(str);
    System.out.println(response.toString());
}

/**
将文件转换为字符串

*/
public static String getString (String FILE_IN){
String str="";
File file=new File(FILE_IN);
try {
FileInputStream in=new FileInputStream(file);
// size 为字串的长度 ,这里一次性读完
int size=in.available();
byte[] buffer=new byte[size];
in.read(buffer);
in.close();
str=new String(buffer,“GB2312”);
} catch (IOException e) {
// TODO Auto-generated catch block
return null;
}
return str;
}
}

你可能感兴趣的:(AI实现文本审核)