Keyword Extraction

Introduction

This API is used to extract the keywords that best express the topic or meaning of the specified text.

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}/nlp-fundamental/keyword-extraction
  • 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

text

String

Yes

Text to be analyzed. The text is encoded using UTF-8 and contains 1 to 512 characters.

limit

int

No

Maximum number of returned keywords. The default value is 5.

If the number of words in the request text is less than the value of this parameter, the actual number of words is returned.

If the number of words is a floating point number, this parameter is set to the integer rounded down the floating point number.

lang

String

No

Supported language type. Currently, only Chinese is supported. The default value is zh.

Response

Table 3 describes the response parameters.

Table 3 Response parameters

Parameter

Type

Description

words

Array of String

Keyword list

error_code

String

Error code when the API fails to be called. For details, see Error Code.

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

error_msg

String

Error message returned when the API fails to be called.

The parameter is not included when the API call succeeds.

Example

  • Example request
    POST https://{endpoint}/v1/{project_id}/nlp-fundamental/keyword-extraction
    
    Request Header:
        Content-Type: application/json
        X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
    
    Request Body:
    	{
      "text": "Huawei is a leading global information and communications technology (ICT) solution provider. It focuses on the ICT field, adheres to robust operation, continuous innovation, and open cooperation, builds end-to-end solution advantages in telecom carriers, enterprises, devices, and cloud computing, provides competitive ICT solutions, products, and services for carriers, enterprises, and consumers, and is dedicated to enabling the future information society and building a better connected world.", 
    	  "limit": 8,
    	  "lang": "zh"
    	}
    
  • Example response
    • Successful example response
      {
          "words": [
              "Word 1",
              "ICT",
              "Word 2",
              "Word 3",
              "Word 4",
              "Word 5",
              "Word 6",
              "Word 7",
          ]
      }
    • Failed example response
      {
          "error_code": "NLP.0301",
          "error_msg": "argument valid error:lang.only support language:zh;"
      }

Status Code

For details about status codes, see Status Code.

Error Code

For details about error codes, see Error Code.