提交候tgit
This commit is contained in:
parent
2e1dfe5d23
commit
245cc0882a
@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/***
|
||||
*
|
||||
* https://next.api.aliyun.com/api/imageaudit/2019-12-30/ScanImage?RegionId=cn-shanghai
|
||||
@ -31,7 +32,7 @@ import java.util.List;
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/image")
|
||||
@RequestMapping("/scan")
|
||||
@NotIntercept
|
||||
public class ScanImageController extends BaseController {
|
||||
|
||||
@ -39,10 +40,9 @@ public class ScanImageController extends BaseController {
|
||||
@Autowired
|
||||
private AScanImageHandle aScanImageHandle;
|
||||
|
||||
@RequestMapping("/scan")
|
||||
@RequestMapping("/image")
|
||||
@CacheResult
|
||||
public R scan(ScanImageReq req) {
|
||||
|
||||
ScanImageResp resp = new ScanImageResp();
|
||||
AScanImageRequest request = new AScanImageRequest();
|
||||
|
||||
|
||||
@ -0,0 +1,98 @@
|
||||
package com.heyu.api.controller.imageaudit;
|
||||
|
||||
|
||||
import com.aliyun.imageaudit20191230.models.ScanTextResponse;
|
||||
import com.aliyun.imageaudit20191230.models.ScanTextResponseBody;
|
||||
import com.heyu.api.alibaba.handle.imageaudit.AScanTextHandle;
|
||||
import com.heyu.api.alibaba.request.imageaudit.AScanTextRequest;
|
||||
import com.heyu.api.controller.BaseController;
|
||||
import com.heyu.api.data.annotation.CacheResult;
|
||||
import com.heyu.api.data.annotation.NotIntercept;
|
||||
import com.heyu.api.data.utils.ApiR;
|
||||
import com.heyu.api.data.utils.R;
|
||||
import com.heyu.api.request.imageaudit.ScanImageReq;
|
||||
import com.heyu.api.resp.imageaudit.ScanTextResp;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/***
|
||||
*https://next.api.aliyun.com/api/imageaudit/2019-12-30/ScanText
|
||||
*
|
||||
* 文本内容安全
|
||||
*
|
||||
* ScanText
|
||||
*
|
||||
* 功能描述
|
||||
* 文本内容安全结合行为、内容,采用多维度、多模型、多检测手段,识别文本中的敏感信息,规避敏感人物姓名、敏感事件描述、敏感言论等内容风险。
|
||||
* 支持检测的场景包括:文字垃圾内容识别、文字广告内容识别、文字敏感内容识别、文字暴恐内容识别、文字辱骂内容识别、文字鉴黄内容识别、文字灌水内容识别、
|
||||
* 文字违禁内容识别。 在提交检测任务时,您需要指定 Labels 参数,并且支持组合使用,即可对同一段文字进行多种风险检测。如果接口返回结果为空,
|
||||
* 表示未检测到 Labels 中的风险点。
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/scan")
|
||||
@NotIntercept
|
||||
public class ScanTextController extends BaseController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private AScanTextHandle aScanTextHandle;
|
||||
|
||||
@RequestMapping("/text")
|
||||
@CacheResult
|
||||
public R scan(ScanImageReq req) {
|
||||
AScanTextRequest request = new AScanTextRequest();
|
||||
request.setContents(req.getContents());
|
||||
request.setScenes(req.getScenes());
|
||||
List<ScanTextResp> resps = new ArrayList<>();
|
||||
|
||||
ApiR<ScanTextResponse> aR = aScanTextHandle.handle(request);
|
||||
|
||||
if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
|
||||
|
||||
ScanTextResponseBody.ScanTextResponseBodyData responseBodyData = aR.getData().getBody().getData();
|
||||
List<ScanTextResponseBody.ScanTextResponseBodyDataElements> responseBodyDataElements = responseBodyData.getElements();
|
||||
|
||||
if (CollectionUtils.isNotEmpty(responseBodyDataElements)) {
|
||||
for (ScanTextResponseBody.ScanTextResponseBodyDataElements responseBodyDataElement : responseBodyDataElements) {
|
||||
List<ScanTextResponseBody.ScanTextResponseBodyDataElementsResults> results = responseBodyDataElement.getResults();
|
||||
if (CollectionUtils.isNotEmpty(results)) {
|
||||
for (ScanTextResponseBody.ScanTextResponseBodyDataElementsResults result : results) {
|
||||
ScanTextResp scanTextResp = new ScanTextResp();
|
||||
scanTextResp.setRate(result.getRate());
|
||||
scanTextResp.setSuggestion(result.getSuggestion());
|
||||
scanTextResp.setLabel(result.getLabel());
|
||||
List<ScanTextResp.ElementsResultsDetails> elementsResultsDetails = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(result.getDetails())) {
|
||||
for (ScanTextResponseBody.ScanTextResponseBodyDataElementsResultsDetails detail : result.getDetails()) {
|
||||
|
||||
ScanTextResp.ElementsResultsDetails elementsResultsDetail = new ScanTextResp.ElementsResultsDetails();
|
||||
elementsResultsDetail.setLabel(detail.getLabel());
|
||||
List<String> contexts = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(detail.getContexts())) {
|
||||
for (ScanTextResponseBody.ScanTextResponseBodyDataElementsResultsDetailsContexts context : detail.getContexts()) {
|
||||
contexts.add(context.getContext());
|
||||
}
|
||||
}
|
||||
elementsResultsDetail.setContexts(contexts);
|
||||
elementsResultsDetails.add(elementsResultsDetail);
|
||||
}
|
||||
}
|
||||
scanTextResp.setDetails(elementsResultsDetails);
|
||||
resps.add(scanTextResp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return R.ok().setData(resps);
|
||||
}
|
||||
return R.error();
|
||||
}
|
||||
|
||||
}
|
||||
@ -10,24 +10,34 @@ import java.util.List;
|
||||
public class ScanImageReq extends CommonReq {
|
||||
|
||||
/**
|
||||
* 指定图片检测的应用场景,可选值包括:
|
||||
* 场景
|
||||
* 指定文本检测的应用场景,可选值包括:
|
||||
* <p>
|
||||
* porn:图片智能鉴黄
|
||||
* spam:文字垃圾内容识别
|
||||
* <p>
|
||||
* terrorism:图片敏感内容识别、图片风险人物识别
|
||||
* politics:文字敏感内容识别
|
||||
* <p>
|
||||
* ad:图片垃圾广告识别
|
||||
* abuse:文字辱骂内容识别
|
||||
* <p>
|
||||
* live:图片不良场景识别
|
||||
* terrorism:文字暴恐内容识别
|
||||
* <p>
|
||||
* logo:图片 Logo 识别
|
||||
* porn:文字鉴黄内容识别
|
||||
* <p>
|
||||
* flood:文字灌水内容识别
|
||||
* <p>
|
||||
* contraband:文字违禁内容识别
|
||||
* <p>
|
||||
* ad:文字广告内容识别
|
||||
* <p>
|
||||
* 说明 支持多场景(scenes)一起检测。例如scenes=[“porn”, “terrorism”],即对一张图片同时进行鉴黄和涉恐识别,此时也会按照两个场景计费。
|
||||
* 示例值:
|
||||
* porn
|
||||
* ad
|
||||
*/
|
||||
public List<String> scenes;
|
||||
private List<String> scenes;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private List<String> contents;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
package com.heyu.api.request.imageaudit;
|
||||
|
||||
|
||||
import com.heyu.api.data.dto.BaseReq;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
public class ScanTextReq extends BaseReq {
|
||||
|
||||
|
||||
/**
|
||||
* 指定检测的对象,JSON 数组中的每个元素是一个文字检测任务结构体。
|
||||
*
|
||||
* 说明
|
||||
* N 个 Task 会折算为 N 次调用进行计费。
|
||||
* 算法识别效果问题请通过钉钉群(23109592)加入阿里云视觉智能开放平台咨询群联系我们。
|
||||
* 示例值:
|
||||
* 维修管道,联系weixin
|
||||
*/
|
||||
private String content;
|
||||
|
||||
|
||||
/**
|
||||
* 指定文本检测的应用场景,可选值包括:
|
||||
*
|
||||
* spam:文字垃圾内容识别
|
||||
*
|
||||
* politics:文字敏感内容识别
|
||||
*
|
||||
* abuse:文字辱骂内容识别
|
||||
*
|
||||
* terrorism:文字暴恐内容识别
|
||||
*
|
||||
* porn:文字鉴黄内容识别
|
||||
*
|
||||
* flood:文字灌水内容识别
|
||||
*
|
||||
* contraband:文字违禁内容识别
|
||||
*
|
||||
* ad:文字广告内容识别
|
||||
*
|
||||
* 示例值:
|
||||
* ad
|
||||
*/
|
||||
private List<String> labels;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
package com.heyu.api.resp.imageaudit;
|
||||
|
||||
|
||||
import com.heyu.api.data.dto.BaseResp;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/***
|
||||
* https://next.api.aliyun.com/api/imageaudit/2019-12-30/ScanText
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
public class ScanTextResp extends BaseResp {
|
||||
|
||||
|
||||
/**
|
||||
* 文本的检测结果。
|
||||
*/
|
||||
public List<ElementsResultsDetails> details;
|
||||
|
||||
/**
|
||||
* 检测结果的分类。
|
||||
* <p>
|
||||
* 示例值:
|
||||
* ad
|
||||
*/
|
||||
public String label;
|
||||
|
||||
/**
|
||||
* 结果为该分类的概率,取值范围为[0.00-100.00]。值越高,表示越有可能属于该分类。
|
||||
* <p>
|
||||
* 示例值:
|
||||
* 99.91
|
||||
*/
|
||||
public Float rate;
|
||||
|
||||
/***
|
||||
* 建议您执行的操作,取值包括:
|
||||
*
|
||||
* pass:文本正常。
|
||||
*
|
||||
* review:需要人工审核。
|
||||
*
|
||||
* block:文本违规,可以直接删除或者做限制处理。
|
||||
*
|
||||
* 示例值:
|
||||
* block
|
||||
*/
|
||||
public String suggestion;
|
||||
|
||||
@Data
|
||||
public static class ElementsResultsDetails {
|
||||
|
||||
/***
|
||||
* 命中风险文本的分类。
|
||||
*
|
||||
* 示例值:
|
||||
* ad
|
||||
*/
|
||||
public String label;
|
||||
|
||||
/**
|
||||
* 检测文本命中的风险内容。
|
||||
* <p>
|
||||
* 示例值:
|
||||
* 联系weixin
|
||||
*/
|
||||
private List<String> contexts;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user