栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

阿里云第三方文章垃圾内容审核

阿里云第三方文章垃圾内容审核

一、导入maven依赖
      
            com.aliyun
            aliyun-java-sdk-core
            4.5.29
        
        
            com.aliyun
            aliyun-java-sdk-ocr
            1.0.11
        

        
            com.aliyun
            aliyun-java-sdk-imageaudit
            1.0.8
        

        
            com.aliyun
            aliyun-java-sdk-imagerecog
            1.0.12
        
二、根据官方文档案例测试代码:可根据自己的需求自行添加

链接

package com.xiaoxu.admin.kafka.aliyun;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.AcsResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.RpcAcsRequest;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.imageaudit.model.v20191230.ScanImageRequest;
import com.aliyuncs.imageaudit.model.v20191230.ScanImageRequest.Task;
import com.aliyuncs.imageaudit.model.v20191230.ScanImageResponse;
import com.aliyuncs.imageaudit.model.v20191230.ScanTextRequest;
import com.aliyuncs.imageaudit.model.v20191230.ScanTextResponse;
import com.aliyuncs.imagerecog.model.v20190930.RecognizeSceneRequest;
import com.aliyuncs.imagerecog.model.v20190930.RecognizeSceneResponse;
import com.aliyuncs.imagerecog.model.v20190930.TaggingImageRequest;
import com.aliyuncs.imagerecog.model.v20190930.TaggingImageResponse;
import com.aliyuncs.ocr.model.v20191230.*;
import com.aliyuncs.profile.DefaultProfile;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;


public class ImageTest {

    static IAcsClient client = null;

    public static void main(String[] args) throws Exception {

        DefaultProfile profile = DefaultProfile.getProfile(
                "cn-shanghai",             //默认
                "",         //您的AccessKeyID
                "");    //您的AccessKeySecret

        client = new DefaultAcsClient(profile);

        // 内容审核
       // testScanImage(); // 内容审核
        testScanText();

        System.out.println("--------------------------------------------------------------");

    }

    private static , T extends AcsResponse> T getAcsResponse(R req) throws Exception {
        try {
            return client.getAcsResponse(req);
        } catch (ServerException e) {
            // 服务端异常
            System.out.println(String.format("ServerException: errCode=%s, errMsg=%s", e.getErrCode(), e.getErrMsg()));
            throw e;
        } catch (ClientException e) {
            // 客户端错误
            System.out.println(String.format("ClientException: errCode=%s, errMsg=%s", e.getErrCode(), e.getErrMsg()));
            throw e;
        } catch (Exception e) {
            System.out.println("Exception:" + e.getMessage());
            throw e;
        }
    }






    public static void testScanImage() throws Exception {
        System.out.println("--------  内容审核 --------------");
        ScanImageRequest req = new ScanImageRequest();
        List scenes = new ArrayList();
        scenes.add("porn");
        req.setScenes(scenes);
        List tasks = new ArrayList();
        com.aliyuncs.imageaudit.model.v20191230.ScanImageRequest.Task task = new Task();
        task.setDataId(UUID.randomUUID().toString());
        task.setImageURL("https://viapi-demo.oss-cn-shanghai.aliyuncs.com/viapi-demo/images/ChangeImageSize/change-image-size-src.png");
        tasks.add(task);
        req.setTasks(tasks);


        ScanImageResponse resp = getAcsResponse(req);
        printResponse(req.getSysActionName(), resp.getRequestId(), resp);
    }

    public static void testScanText() throws Exception {
        System.out.println("--------  文章内容审核 --------------");
        ScanTextRequest req = new ScanTextRequest();
        List labelss = new ArrayList<>();
        ScanTextRequest.Labels label1 = new ScanTextRequest.Labels();
        label1.setLabel("politics");
        labelss.add(label1);
        ScanTextRequest.Labels label2 = new ScanTextRequest.Labels();
        label2.setLabel("abuse");
        labelss.add(label2);
        ScanTextRequest.Labels label3 = new ScanTextRequest.Labels();
        label3.setLabel("terrorism");
        labelss.add(label3);
        ScanTextRequest.Labels label4 = new ScanTextRequest.Labels();
        label4.setLabel("porn");
        labelss.add(label4);
        ScanTextRequest.Labels label5 = new ScanTextRequest.Labels();
        label5.setLabel("ad");
        labelss.add(label5);

        req.setLabelss(labelss);

        List tasks = new ArrayList<>();
        ScanTextRequest.Tasks task1 = new ScanTextRequest.Tasks();
        task1.setContent("本校小额贷款,安全、快捷、方便、无抵押,随机随贷,当天放款,上门服务。联系weixin 123456");
        tasks.add(task1);
        req.setTaskss(tasks);


        ScanTextResponse response = getAcsResponse(req);

        System.out.println(JSON.toJSONString(response));
    }





    //通用图像打标
    public static void testTaggingImage() throws Exception {
        System.out.println("--------  通用图像打标 --------------");
        TaggingImageRequest req = new TaggingImageRequest();
        // 注意:下面的链接换成自有的oss链接
        req.setImageURL("https://viapi-demo.oss-cn-shanghai.aliyuncs.com/viapi-demo/xxx.png");
        TaggingImageResponse resp = getAcsResponse(req);
        printResponse(req.getSysActionName(), resp.getRequestId(), resp);
    }

    

    public static void printResponse(String actionName, String requestId, AcsResponse  data) {
       // System.out.println(String.format("actionName=%s, requestId=%s", actionName, requestId));

        System.out.println( String.format("data=%s",JSON.toJSONString(data)) );

    }
}


三、测试结果


审核结果:
链接

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/775811.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号