Help Center> Natural Language Processing> API Reference> NLP APIs> LU APIs> Sentiment Analysis (Domain-specific Edition)

Sentiment Analysis (Domain-specific Edition)

Introduction

This API is used to analyze user comments in e-commerce, automotive industries, and other unknown domains.

For details about endpoints, see Endpoints.

Calling NLP APIs will incur fees. NLP packages are classified into the basic and domain-specific editions. When purchasing a package, view the APIs supported by the basic package and domain-specific packages in the Natural Language Processing Price Calculator.

URI

  • URI format
    POST /v1/{project_id}/nlu/sentiment/domain
  • Parameter description
    Table 1 URI parameters

    Parameter

    Mandatory

    Description

    project_id

    Yes

    Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

Request

Table 2 describes the request parameters.

Table 2 Request parameters

Parameter

Type

Mandatory

Description

content

String

Yes

Text to be analyzed. The text must be encoded using UTF-8. Chinese is supported currently.

  • If type is set to 0 (domain adaptation), or 1 (e-commerce), the value contains a maximum of 200 characters. If the value exceeds 200 characters, only the first 200 characters are detected.
  • If type is set to 2 (automotive), the value contains a maximum of 400 characters. If the value exceeds 400 characters, only the first 400 characters are detected.

type

Integer

No

The default value is 0. The options are as follows:

0: domain adaptation. The system automatically identifies the domain based on the input content.

1: e-commerce, which can be applied as comments in the e-commerce industry.

2: automotive, which can be applied as comments in the automotive industry.

Response

Table 3 describes the response parameters.

Table 3 Response parameters

Parameter

Type

Description

result

Result object

Sentiment information returned when the API is successfully called.

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

For details, see Table 4.

error_code

String

Error code returned when the API fails to be called.

The parameter is not included when the API call succeeds.

error_msg

String

Error message returned when the API fails to be called.

The parameter is not included when the API call succeeds.

Table 4 Data structure description of the result field

Parameter

Type

Description

content

String

Text to be analyzed

label

Integer

Positive and negative labels

  • 1: positive
  • 0: negative

confidence

Float

Confidence level of the labels

Examples

  • Example request
    POST https://{endpoint}/v1/{project_id}/nlu/sentiment/domain
    
    Request Header: 
        Content-Type: application/json 
        X-Auth-Token:MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG... 
    
    Request Body: 
        {          
               "content":"Text for analysis",         
            "type": 2 
        }
  • Example response
    • Successful example response
      {       
          "result": {                             
                  "content":"Response",              
              "label": 1,                
              "confidence": 0.96399385          
          }   
      }
    • Failed example response
      {
          "error_code": "NLP.0101",
          "error_msg": "Authentication failed. Please verify the token"
      }

Status Code

For details about status codes, see Status Code.

Error Code

For details about error codes, see Error Code.