tencent cloud

Feedback

Text Moderation

Last updated: 2024-02-29 16:06:23

    Overview

    This document describes how to use the content moderation feature provided by Cloud Infinite (CI). CI fully integrates the processing capabilities with the COS SDK.
    Note:
    To use the content moderation service, you need to have the permission to use CI:
    For root accounts, click here for role authorization.
    This document provides an overview of APIs and SDK code samples for text moderation.
    API
    Description
    Submits a text moderation job.
    Queries the result of the specified text moderation job.

    SDK API References

    For parameters and method description of all APIs in the SDK, see SDK API Reference.

    Creating a Task

    Feature description

    This API (QCloudPostTextRecognitionRequest) is used to submit a text moderation job. You can receive the moderation result by setting the callback address or querying by JobId.
    Note:
    The COS iOS SDK version must be at least v6.0.9.

    Sample request

    Objective-C
    QCloudPostTextRecognitionRequest * request = [[QCloudPostTextRecognitionRequest alloc]init];
    
    // Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "dir1/object1".
    request.object = @"exampleobject";
    
    // Bucket name in the format of BucketName-APPID
    request.bucket = @"examplebucket-1250000000";
    
    // File region
    request.regionName = @"regionName";
    
    // Moderation type, such as `porn` (pornography), `terrorist` (terrorism), `politics` (politically sensitive), and `ads` (advertising).
    // You can select multiple types; for example, `detect-type=porn,ads` indicates to moderate the image for pornographic and advertising information.
    // You can use multiple parameters together, such as `QCloudRecognitionPorn | QCloudRecognitionTerrorist`.
    request.detectType = QCloudRecognitionPorn | QCloudRecognitionAds | QCloudRecognitionPolitics | QCloudRecognitionTerrorist;
    
    // Moderation policy. If this parameter is not specified, the default policy will be used. For more information, visit https://www.tencentcloud.com/document/product/460/56345?from_cn_redirect=1.
    request.bizType = BizType;
    
    request.finishBlock = ^(QCloudPostTextRecognitionResult * outputObject, NSError *error) {
    // The moderation result `outputObject` contains the job ID used for query. For detailed fields, see the API documentation or SDK source code.
    // `QCloudPostTextRecognitionResult` class
    };
    [[QCloudCOSXMLService defaultCOSXML] PostTextRecognition:request];
    Note:
    For more complete samples, visit GitHub.
    Swift
    let request = QCloudPostTextRecognitionRequest();
    
    // Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "dir1/object1".
    request.object = "exampleobject";
    
    // Bucket name in the format of BucketName-APPID
    request.bucket = "examplebucket-1250000000";
    
    // File region
    request.regionName = "regionName";
    
    // Moderation type, such as `porn` (pornography), `terrorist` (terrorism), `politics` (politically sensitive), and `ads` (advertising).
    // You can select multiple types; for example, `detect-type=porn,ads` indicates to moderate the image for pornographic and advertising information.
    // You can use multiple parameters together, such as `QCloudRecognitionPorn | QCloudRecognitionTerrorist`.
    request.detectType = QCloudRecognitionEnum(rawValue: QCloudRecognitionEnum.porn.rawValue | QCloudRecognitionEnum.ads.rawValue)!
    
    // Moderation policy. If this parameter is not specified, the default policy will be used. For more information, visit https://www.tencentcloud.com/document/product/460/56345?from_cn_redirect=1.
    request.setFinish { outputObject, error in
    // The moderation result `outputObject` contains the job ID used for query. For detailed fields, see the API documentation or SDK source code.
    // `QCloudPostTextRecognitionResult` class
    }
    QCloudCOSXMLService.defaultCOSXML().postTextRecognition(request);
    Note:
    For more complete samples, visit GitHub.

    Querying Job

    Feature description

    This API (QCloudGetTextRecognitionRequest) is used to query the result of the specified text moderation job by JobId.
    Note:
    The COS iOS SDK version must be at least v6.0.9.

    Sample request

    Objective-C
    QCloudGetTextRecognitionRequest * request = [[QCloudGetTextRecognitionRequest alloc]init];
    
    // Bucket name in the format of BucketName-APPID
    request.bucket = @"examplebucket-1250000000";
    
    // File region
    request.regionName = @"regionName";
    
    // The `jobid` returned by the `QCloudPostTextRecognitionRequest` API
    request.jobId = @"jobid";
    
    request.finishBlock = ^(QCloudTextRecognitionResult * outputObject, NSError *error) {
    // The moderation result `outputObject` contains the job ID used for query. For detailed fields, see the API documentation or SDK source code.
    // `QCloudTextRecognitionResult` class
    };
    [[QCloudCOSXMLService defaultCOSXML] GetTextRecognition:request];
    Note:
    For more complete samples, visit GitHub.
    Swift
    let request = QCloudGetTextRecognitionRequest();
    
    // Bucket name in the format of BucketName-APPID
    request.bucket = "examplebucket-1250000000";
    
    // File region
    request.regionName = "regionName";
    
    // The `jobid` returned by the `QCloudPostTextRecognitionRequest` API
    request.jobId = "jobid";
    
    request.setFinish { outputObject, error in
    // The moderation result `outputObject` contains the job ID used for query. For detailed fields, see the API documentation or SDK source code.
    // `QCloudTextRecognitionResult` class
    };
    QCloudCOSXMLService.defaultCOSXML().getTextRecognition(request);
    Note:
    For more complete samples, visit GitHub.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support