Help Center > > API Reference> APIs> Moderation (Text)> Text Moderation

Text Moderation

Updated at: Aug 09, 2021 GMT+08:00

Function

This API analyzes and identifies whether the uploaded text contains pornographic elements, and returns the result to you.

URI

POST /v2/{project_id}/moderation/text

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Indicates the project ID.

Log in to the HUAWEI CLOUD management console, click the username in the upper right corner, and select My Credentials from the drop-down list. On the displayed page, choose API Credentials in the left navigation pane and obtain the project ID in a specific region from the right pane.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Indicates the user token.

The token can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

categories

No

Array of strings

Indicates the detection scenario.

Currently, the following scenarios are supported:

  • Default scenarios:
    • porn: indicates pornographic information detection.
    • ad: indicates advertisement detection.
    • abuse: indicates offensive content detection.
    • contraband: indicates contraband information detection.
    • flood: indicates spamming detection.
  • User-defined scenario: custom blocklist dictionary
    NOTE:
    • For details about how to create and use a custom dictionary, see Configuring a Custom Dictionary.
    • The custom allowlist dictionary cannot be used in the flood scenario.

items

Yes

Array of TextDetectionItemsReq objects

Indicates the items to be checked. Currently, only one item can be checked each time.

Table 4 TextDetectionItemsReq parameters

Parameter

Mandatory

Type

Description

text

Yes

String

Indicates the text to be detected. The text is encoded using UTF-8 and contains a maximum of 5000 characters. If the text contains more than 5000 characters, only the first 5000 characters are detected.

Minimum length: 1

Maximum length: 5000

type

No

String

Indicates the text type. The default value is content. Currently, only the content type is supported.

Response Parameters

Status code: 200

Table 5 Response body parameters

Parameter

Type

Description

result

result object

Indicates the calling result of a successful API call.

This parameter is not included when the API fails to be called.

Table 6 result parameters

Parameter

Type

Description

suggestion

String

Indicates whether the check is passed.

block: indicates that sensitive information is detected and the information fails to pass the check.

pass: indicates that no sensitive information is detected and the information passes the check.

review: indicates that the manual review is required.

detail

Object

Indicates details about the returned check result. Possible values are as follows:

  • porn: indicates a list of pornographic words.
  • ad: indicates a list of sensitive advertisement words.
  • abuse: indicates a list of offensive words.
  • contraband: indicates a list of words related to contraband.
  • flood: indicates spam, or unwanted content particularly in forums that provide little value to readers.
    NOTE:
    • The spam content contains a maximum of 200 characters.
    • The details about the returned check result of each scenario refer to only the detected words instead of the whole content.

Status code: 400

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Indicates the error code of a failed API call. For details, see Error Codes.

This parameter is not included when the API is successfully called.

error_msg

String

Indicates the error message of a failed API call.

This parameter is not included when the API is successfully called.

fail_category

String

Indicates the failure scenario when there are multiple scenarios.

Example Requests

POST https://{endpoint}/v2/{project_id}/moderation/text

{
  "categories" : [ "ad", "politics", "abuse", "porn", "contraband", "flood" ],
  "items" : [ {
    "text" :  "asdfasdfasdf",
    "type" : "content"
  }
 ]
}

Example Responses

Status code: 200

Example of a successful response

{
  "result" : {
    "detail" : {
      "abuse" : [ "fuck" ]
    },
    "suggestion" : "block"
  }
}

Status code: 400

Example of a failed response

{
  "error_code" : "AIS.0005",
  "error_msg" : "The service does not exist."
}

Status Codes

Status Code

Description

200

Example of a successful response

400

Example of a failed response

Error Codes

For details, see Error Codes.

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel