All Products
Search
Document Center

Intelligent Speech Interaction:Call API operations to manage custom linguistic models

Last Updated:Nov 14, 2022

This topic describes how to call the API operations provided by Intelligent Speech Interaction to manage custom linguistic models. 

Intelligent Speech Interaction provides the following API operations to allow you to manage custom linguistic models:

  • Operations that you can call to manage training datasets:

    • CreateAsrLmData: creates a training dataset.

    • GetAsrLmData: queries a training dataset.

    • DeleteAsrLmData: deletes a training dataset.

    • ListAsrLmData: queries training datasets by page.

  • Operations that you can call to manage custom linguistic models:

    • CreateAsrLmModel: creates a custom linguistic model.

    • GetAsrLmModel: queries a custom linguistic model.

    • DeleteAsrLmModel: deletes a custom linguistic model.

    • ListAsrLmModel: queries custom linguistic models by page.

  • Operations that you can call to train and publish custom linguistic models:

    • AddDataToAsrLmModel: adds a training dataset to a custom linguistic model.

    • RemoveDataFromAsrLmModel: removes a training dataset from a custom linguistic model.

    • TrainAsrLmModel: trains a custom linguistic model.

    • DeployAsrLmModel: publishes a custom linguistic model.

    • UndeployAsrLmModel: unpublishes a custom linguistic model.

Activate Intelligent Speech Interaction

Before you call the Intelligent Speech Interaction API to create and train a custom linguistic model, log on to the Alibaba Cloud Management Console to activate Intelligent Speech Interaction. For more information, see Create a custom linguistic model.

Note

On the Project Settings page of your project in the Intelligent Speech Interaction console, you can specify the Automatic Speech Recognition (ASR) model of the project to the basic model of the custom linguistic model that you want to train. 

The following table describes information about the Intelligent Speech Interaction API. 

Item

Value

Region ID

ap-southeast-1

Domain name

nls-slp.ap-southeast-1.aliyuncs.com

Protocol

HTTPS

API version

2018-11-20

Prepare training corpora

Prepare training corpora based on the limits and optimization suggestions. For more information, see the "Notes on training corpora" section of Overview

Item

Description

Maximum number of custom linguistic models

You can create up to 10 custom linguistic models. Linguistic models are free of charge. 

Maximum number of training datasets

You can create up to 100 training datasets. 

Maximum size of a training dataset

A training dataset can contain up to 10 MB of data. 

Maximum number of training datasets in a custom linguistic model

You can add up to 10 training datasets to a custom linguistic model. 

Effective time

If the total size of the training datasets that you add to a custom linguistic model does not exceed 10 MB, the system requires approximately five minutes to train and publish the model. If the total size of the training datasets exceeds 10 MB, the system requires approximately 30 minutes to train and publish the model. 

Train a custom linguistic model

To train a custom linguistic model, perform the following steps:

  1. Prepare and import training corpus data to the self-learning platform. Then, create training datasets based on the data that you imported. 

    The following table describes the possible status of a training dataset.

    Status

    Description

    Fetching

    The training corpus data is being imported from the specified URL to the self-learning platform. 

    FetchingFailed

    The system failed to import the training corpus data. Check whether the URL that you specified is valid. Only HTTP URLs and HTTPS URLs of files in Alibaba Cloud Object Storage Service (OSS) are supported. 

    Ready

    The training corpus data is imported. 

  2. Create a custom linguistic model and add the training dataset that is created to this model. 

  3. Train the custom linguistic model and wait until the training is completed. 

    The following table describes the possible status of a custom linguistic model.

    Status

    Description

    Empty

    The custom linguistic model is created and is not trained. 

    Training

    The custom linguistic model is being trained. 

    TrainingFailed

    The system failed to train the custom linguistic model. 

    Ready

    The custom linguistic model is unpublished. 

    Deploying

    The custom linguistic model is being published or unpublished. 

    Deployed

    The custom linguistic model is published. 

API operations

Manage training datasets. A training dataset refers to a training corpus that you can upload to the Intelligent Speech Interaction console. 

Create a dataset

API operation: CreateAsrLmData

Request parameters:

When you send a request to create a training dataset, you must include request parameters in the request body. The following table describes the parameters. 

Parameter

Type

Required

Description

Name

String

Yes

The name of the training dataset that you want to create. 

Url

String

Yes

The URL of the training corpus data. The self-learning platform accesses and downloads the training corpus data from the URL. Only HTTP URLs and HTTPS URLs of OSS files are supported. 

Description

String

No

The description of the training dataset. 

Response parameters:

The response body that is returned by the server is in the JSON format. 

{
    "RequestId": "C71B7CAA-18D6-4012-AC3D-425BA1CB****",
    "DataId": "9934e10f19044282825508cbc7c8****"
}

Parameter description:

  • The HTTP status code 200 indicates that the operation is successful. For more information about HTTP status codes, see the "Error codes" section. 

  • The following table describes the response parameters that are returned in the JSON format.

    Parameter

    Type

    Description

    RequestId

    String

    The ID of the request. 

    DataId

    String

    The ID of the training dataset that is created. You can use the ID to specify the training dataset when you call the AddDataToAsrLmModel operation to add the training dataset to a linguistic model. 

Note

The system polls the status of the training dataset until the status of the training dataset changes to Ready. The Ready state indicates that the training dataset is created. 

Query a training dataset

API operation: GetAsrLmData

Request parameters:

When you send a request to query a training dataset, you must include request parameters in the request body. The following table describes the parameters. 

Parameter

Type

Required

Description

DataId

String

Yes

The ID of the training dataset that you want to query. 

Response parameters:

The response body that is returned by the server is in the JSON format. 

{
    "Data": {
        "Name": "TestTrainingDataset",
        "Status": "Ready",
        "Md5": "38fc072ac60796a84ce1a0b13f78****",
        "Description": "The training dataset is created by using the API.",
        "Url": "https://aliyun-nls.oss-ap-southeast-1.aliyuncs.com/asr/fileASR/SLP/SLPTest.txt",
        "CreateTime": "2019-02-11 14:40:35",
        "UpdateTime": "2019-02-11 14:40:35",
        "Id": "9934e10f19044282825508cbc7c8****",
        "Size": 5991
    },
    "RequestId": "C88130E6-F3B5-4F3E-9BF5-9C617DDD****"
}

Parameter description:

  • The HTTP status code 200 indicates that the operation is successful. For more information about HTTP status codes, see the "Error codes" section. 

  • The following table describes the response parameters that are returned in the JSON format.

    Parameter

    Type

    Description

    RequestId

    String

    The ID of the request. 

    Data

    Object

    The information about the training dataset. 

    The following table describes the parameters that are included in Data.

    Parameter

    Type

    Description

    Id

    String

    The ID of the training dataset. The value is the same as the value of the DataId parameter that is returned after the training dataset is created. 

    Name

    String

    The name of the training dataset. 

    Description

    String

    The description of the training dataset. 

    Size

    Integer

    The size of the training dataset (Byte). 

    Md5

    String

    The MD5 hash value of the training dataset. 

    Url

    String

    The URL of the training corpus file that you specified when you created the training dataset. 

    Status

    String

    The status of the training dataset. Valid values: Fetching, FetchingFailed, and Ready. 

    CreateTime

    String

    The point in time when the training dataset was created. 

    UpdateTime

    String

    The most recent point in time when the training dataset was updated. 

    ErrorMessage

    String

    The error message that is returned when the operation fails. 

Delete a training dataset

API operation: DeleteAsrLmData

Request parameters:

When you send a request to delete a training dataset, you must include request parameters in the request body. The following table describes the parameters. 

Parameter

Type

Required

Description

DataId

String

Yes

The ID of the training dataset that you want to delete. 

Response parameters:

The response body that is returned by the server is in the JSON format. 

{
    "RequestId": "7130914d32a3441db06747523675d9ff"
}

Parameter description:

The HTTP status code 200 indicates that the operation is successful. For more information about HTTP status codes, see the "Error codes" section. 

Note

You can delete only training datasets that are in the Ready state. 

Query training datasets by page

API operation: ListAsrLmData

Request parameters:

When you send a request to query training datasets by page, you must include request parameters in the request body. The following table describes the parameters. 

Parameter

Type

Required

Description

PageNumber

Int

No

The number of the page to return. Pages start from page 1. Default value: 1. 

PageSize

Int

No

The number of entries to return on each page. Valid values: 10 to 100. Default value: 10. 

ModelId

String

No

The ID of the custom linguistic model based on which you want to query training datasets. You can specify this parameter to query training datasets that are used by the specified custom linguistic model. If you do not specify this parameter, the system queries all training datasets that you can access. 

Response parameters:

The response body that is returned by the server is in the JSON format. 

{
    "RequestId": "7130914d32a3441db06747523675d9ff",
    "Page": {
        "Content": [{
            "Id": "1b64bee9994749f2a67eadac6379****",
            "Name": "SampleTrainingDataset",
            "Description": "This is a sample training dataset.",
            "Size": 7777404,
            "Md5": "39326cf690e384735355a385ec1e****",
            "Url": "slp/tmp/demo-data-lm.txt",
            "Status": "Ready",
            "CreateTime": "2018-10-31 17:20:39",
            "UpdateTime": "2018-10-31 17:20:39"
        }],
        "TotalPages": 1,
        "TotalItems": 1,
        "PageNumber": 1,
        "PageSize": 10
    }
}

Parameter description:

  • The HTTP status code 200 indicates that the operation is successful. For more information about HTTP status codes, see the "Error codes" section. 

  • The following table describes the response parameters that are returned in the JSON format. 

    Parameter

    Type

    Description

    RequestId

    String

    The ID of the request.

    Page

    Object

    The information about the training datasets that are displayed on the specified page. If you do not specify a page number in the request, information about the training datasets that are displayed on the first page is returned. 

    The following table describes the parameters that are included in Page. 

    Parameter

    Type

    Description

    Content

    List< Data >

    The information about the training dataset. For more information, see the description of the Data response parameter of the GetAsrLmData operation. 

    TotalPages

    Integer

    The total number of pages. 

    TotalItems

    Integer

    The total number of training datasets. 

    PageNumber

    Integer

    The page number of the returned page. The value of this parameter is the same as the value of the PageNumber parameter in the request. 

    PageSize

    Integer

    The number of entries returned per page. The value of this parameter is the same as the value of the PageSize parameter in the request. 

Operations that you can call to manage custom linguistic models:

Create a custom linguistic model

API operation: CreateAsrLmModel

Request parameters:

When you send a request to create a custom linguistic model, you must include request parameters in the request body. The following table describes the parameters. 

Parameter

Type

Required

Description

Name

String

Yes

Model name 

BaseId

String

Yes

The ID of the basic model. You cannot change the basic model after the custom linguistic model is created. In the Intelligent Speech Interaction console, you must set the ASR model of the project to the model that is the same as the model that is specified by this parameter in the project settings. 

Description

String

No

The description of the custom linguistic model. 

The following table describes the IDs of basic models that you can use to train custom linguistic models. For more information about basic models, see the ASR models that are displayed on the Select ASR Model page of your project in the Intelligent Speech Interaction console.

Model name

BaseId

Universal Chinese Language Recognition Model (Mandarin, 16,000 Hz)

universal

Chinese Telephone Customer Service Recognition Model (Mandarin, 8,000 Hz)

customer_service_8k

Cantonese Telephone Customer Service Recognition Model (Cantonese, 8,000 Hz)

cantonese_customer_service_8k

English speech recognition model (English, 16,000 Hz)

english

Response parameters:

The response body that is returned by the server is in the JSON format. 

{
    "ModelId": "dbb6b71ff3e54b45a600ee5157a2****",
    "RequestId": "945C59DF-B3D9-4F22-808E-76752FF3****"
}

Parameter description:

  • The HTTP status code 200 indicates that the operation is successful. For more information about HTTP status codes, see the "Error codes" section. 

  • The following table describes the response parameters that are returned in the JSON format. 

    Parameter

    Type

    Description

    RequestId

    String

    The ID of the request. 

    ModelId

    String

    The ID of the custom linguistic model. You can use the ID to specify the custom linguistic model when you call the TrainAsrLmModel operation to train the linguistic model. 

Note

After the custom linguistic model is created, the custom linguistic model is in the Empty state. 

Query a custom linguistic model

API operation: GetAsrLmModel

Request parameters:

When you send a request to query a custom linguistic model, you can include the request parameters that are described in the following table in the request body. 

Parameter

Type

Required

Description

ModelId

String

Yes

The ID of the custom linguistic model that you want to query. 

Response parameters:

The response body that is returned by the server is in the JSON format. 

{
    "Model": {
        "Name": "TestLinguisticModel",
        "Status": "Empty",
        "Description": "This is a sample description.",
        "CreateTime": "2019-02-12 10:11:57",
        "UpdateTime": "2019-02-12 10:11:57",
        "Id": "dbb6b71ff3e54b45a600ee5157a2****",
        "BaseId": "common",
        "Size": 0
    },
    "RequestId": "6CE24FF7-B7C8-4B9F-B0EB-FE4AF20B****"
}

Parameter description:

  • The HTTP status code 200 indicates that the operation is successful. For more information about HTTP status codes, see the "Error codes" section. 

  • The following table describes the response parameters that are returned in the JSON format. 

    Parameter

    Type

    Description

    RequestId

    String

    The ID of the request. 

    Model

    Object

    The information about the custom linguistic model. 

    The following table describes the parameters that are included in Model. 

    Parameter

    Type

    Description

    Id

    String

    The ID of the custom linguistic model. The value of this parameter is the same as the value of the ModelId parameter that is returned after the custom linguistic model is created. 

    Name

    String

    The name of the custom linguistic model. 

    Description

    String

    The description of the custom linguistic model. 

    BaseId

    String

    The ID of the basic model. 

    Size

    Integer

    The size of the custom linguistic model. 

    Status

    String

    The status of the custom linguistic model. Valid values: Empty, Training, TrainingFailed, Ready, Deploying, and Deployed. 

    CreateTime

    String

    The point in time when the custom linguistic model was created. 

    UpdateTime

    String

    The most recent point in time when the model was updated. 

    ErrorMessage

    String

    The error message that is returned when the operation fails. 

Delete a custom linguistic model

Important

Before you delete a custom linguistic model, make sure that the model is not being used by applications. After you delete the custom linguistic model, the model becomes ineffective. 

API operation: DeleteAsrLmModel

Request parameters:

When you send a request to delete a custom linguistic model, you must include request parameters in the request body. The following table describes the parameters. 

Parameter

Type

Required

Description

ModelId

String

Yes

The ID of the custom linguistic model that you want to delete. 

Response parameters:

The response body that is returned by the server is in the JSON format. 

{
    "RequestId": "7130914d32a3441db06747523675d9ff"
}

Parameter description:

The HTTP status code 200 indicates that the operation is successful. For more information about HTTP status codes, see the "Error codes" section. 

Note

You cannot delete custom linguistic models that are in the Training or Deploying state. 

Query custom linguistic models by page

API operation: ListAsrLmModel

Request parameters:

When you send a request to query custom linguistic models by page, you must include request parameters in the request body. The following table describes the parameters. 

Parameter

Type

Required

Description

PageNumber

Int

No

The number of the page to return. Pages start from page 1. Default value: 1. 

PageSize

Int

No

The number of entries to return on each page. Valid values: 10 to 100. Default value: 10. 

DataId

String

No

The ID of the training dataset based on which you want to query custom linguistic models. You can specify this parameter to query the custom linguistic models that use the specified training dataset. If you do not specify this parameter, the system queries all custom linguistic models that you can access. 

Response parameters:

The response body that is returned by the server is in the JSON format. 

{
    "RequestId": "7130914d32a3441db06747523675****",
    "Page": {
        "Content": [{
            "Id": "demo-model",
            "Name": "SampleLinguisticModel",
            "Description": "This is a test model.",
            "Size": 0,
            "Status": "Empty",
            "CreateTime": "2018-11-01 17:05:21",
            "UpdateTime": "2018-11-01 17:05:21",
            "BaseId": "common"
        }],
        "TotalPages": 1,
        "TotalItems": 1,
        "PageNumber": 1,
        "PageSize": 10
    }
}

Parameter description:

  • The HTTP status code 200 indicates that the operation is successful. For more information about HTTP status codes, see the "Error codes" section. 

  • The following table describes the response parameters that are returned in the JSON format. 

    Parameter

    Type

    Description

    RequestId

    String

    The ID of the request.

    Page

    Object

    The information about the custom linguistic models that are displayed on the specified page. If you do not specify a page number in the request, information about the custom linguistic models that are displayed on the first page is returned. 

    The following table describes the parameters that are included in Page.

    Parameter

    Type

    Description

    Content

    List< Model >

    The information about the custom linguistic model. For more information, see the description of the Model object of the GetAsrLmModel operation. 

    TotalPages

    Integer

    The total number of pages. 

    TotalItems

    Integer

    The total number of custom linguistic models. 

    PageNumber

    Integer

    The page number of the returned page. The value of this parameter is the same as the value of the PageNumber parameter in the request. 

    PageSize

    Integer

    The number of custom linguistic models that are returned per page. The value of this parameter is the same as the value of the PageSize parameter in the request. 

Add a training dataset to a custom linguistic model

Important

You cannot add the same training dataset to the same custom linguistic model again. 

API operation: AddDataToAsrLmModel

Request parameters:

When you send a request to add a training dataset to a custom linguistic model, you must include request parameters in the request body. The following table describes the parameters. 

Parameter

Type

Required

Description

ModelId

String

Yes

The ID of the custom linguistic model. 

DataId

String

Yes

The ID of the training dataset that you want to add to the specified custom linguistic model. 

Response parameters:

The response body that is returned by the server is in the JSON format. 

{
    "RequestId": "9B232563-12C0-4242-AA27-C250E1BB****"
}

Parameter description:

The HTTP status code 200 indicates that the operation is successful. For more information about HTTP status codes, see the "Error codes" section. 

Note

The training dataset that you add to a custom linguistic model must be in the Ready state. You cannot add a training dataset to a custom linguistic model that is in the Training or Deploying state. 

Remove a training dataset from a custom linguistic model

API operation: RemoveDataFromAsrLmModel

Request parameters:

When you send a request to remove a training dataset from a custom linguistic model, you must include request parameters in the request body. The following table describes the parameters. 

Parameter

Type

Required

Description

ModelId

String

Yes

The ID of the custom linguistic model. 

DataId

String

Yes

The ID of the training dataset that you want to remove from the specified custom linguistic model. 

Response parameters:

The response body that is returned by the server is in the JSON format. 

{
    "RequestId": "7130914d32a3441db06747523675****"
}

Parameter description:

The HTTP status code 200 indicates that the operation is successful. For more information about HTTP status codes, see the "Error codes" section. 

Note

You cannot remove a training dataset from a custom linguistic model that is in the Training or Deploying state. 

Train a custom linguistic model

API operation: TrainAsrLmModel

Request parameters:

When you send a request to train a custom linguistic model, you must include request parameters in the request body. The following table describes the parameters. 

Parameter

Type

Required

Description

ModelId

String

Yes

The ID of the custom linguistic model. 

Response parameters:

The response body that is returned by the server is in the JSON format. 

{
    "RequestId": "3D922A91-68AA-4260-AFE4-C429832F****"
}

Parameter description:

The HTTP status code 200 indicates that the operation is successful. For more information about HTTP status codes, see the "Error codes" section. 

Note

  • You cannot train a custom linguistic model that is in the Deploying state. 

  • After a custom linguistic model is trained, the system automatically publishes the model, and changes the status of the model to Deployed

Publish a custom linguistic model

API operation: DeployAsrLmModel

Request parameters:

When you send a request to publish a custom linguistic model, you must include request parameters in the request body. The following table describes the parameters. 

Parameter

Type

Required

Description

ModelId

String

Yes

The ID of the custom linguistic model. 

Response parameters:

The response body that is returned by the server is in the JSON format. 

{
    "RequestId": "D9DDA978-5D68-45A4-B840-E4BC45C7****"
}

Parameter description:

The HTTP status code 200 indicates that the operation is successful. For more information about HTTP status codes, see the "Error codes" section. 

Note

You can publish only custom linguistic models that are in the Ready state. 

Unpublish a custom linguistic model

Important

Before you unpublish a custom linguistic model, make sure that the model is not being used by applications. After you unpublish the custom linguistic model, the model becomes ineffective. 

API operation: UndeployAsrLmModel

Request parameters:

When you send a request to unpublish a custom linguistic model, you must include request parameters in the request body. The following table describes the parameters. 

Parameter

Type

Required

Description

ModelId

String

Yes

The ID of the custom linguistic model. 

Response parameters:

The response body that is returned by the server is in the JSON format. 

{
    "RequestId": "8417BA8E-2428-41D2-A849-396A0897****"
}

Parameter description:

The HTTP status code 200 indicates that the operation is successful. For more information about HTTP status codes, see the "Error codes" section. 

Note

You can unpublish only custom linguistic models that are in the Deployed

Supported operations for training datasets or custom linguistic models in different states

Note

The following table describes the operations that you can perform on training datasets or custom linguistic models in different states. The value No indicates that you cannot call the operation on a training dataset or custom linguistic model in the specific state. The value - indicates that you can perform the operation on a training dataset or custom linguistic model in the specific state. 

Status/Operation

Fetching

FetchingFailed

Ready

Empty

Training

Training Failed

Ready

Deploying

Deployed

CreateAsrLmData

-

-

-

-

-

-

-

-

-

ListAsrLmData

-

-

-

-

-

-

-

-

-

GetAsrLmData

-

-

-

-

-

-

-

-

-

DeleteAsrLmData

NO

NO

-

-

NO

-

-

-

-

CreateAsrLmModel

-

-

-

-

-

-

-

-

-

ListAsrLmModel

-

-

-

-

-

-

-

-

-

GetAsrLmModel

-

-

-

-

-

-

-

-

-

DeleteAsrLmModel

-

-

-

-

NO

-

-

NO

-

AddDataToAsrLmModel

NO

NO

-

-

NO

-

-

NO

-

RemoveDataFromAsrLmModel

-

-

-

-

NO

-

-

-

-

TrainAsrLmModel

-

-

-

-

-

-

-

NO

-

DeployAsrLmModel

-

-

-

NO

NO

NO

-

NO

NO

UndeployAsrLmModel

-

-

-

NO

NO

NO

NO

NO

-

Error codes

If an error occurs after an operation is called, the system returns an error code in the response body. You can troubleshoot errors based on the error codes. The following table describes the error codes. 

Error code

Description

SLP.ASR_MODEL_ERROR

The error code returned because an error related to the custom linguistic model is occurred. 

SLP.NOT_FOUND

The error code returned because the specified resource ID is invalid. The system failed to find the resource based on the ID. 

SLP.PARAMETER_ERROR

The error code returned because you specified invalid parameter values when you created a resource. 

SLP.EXCEED_LIMIT

The error code returned because the number of resources reached the upper limit. You cannot create more resources. 

The following sample response is returned if the resource ID that you specify in the request is invalid:

{
    "RequestId": "E70F51F6-23E3-4681-B954-ABF32B89****",
    "HostId": "nls-slp.ap-southeast-1.aliyuncs.com",
    "Code": "SLP.NOT_FOUND",
    "Message": "Model not found!"
}

Parameter

Type

Description

RequestId

String

The ID of the request. 

HostId

String

The endpoint of the self-learning platform server. 

Code

String

The error code. 

Message

String

The error message. 

Sample code

Note

  • In the following sample code, the CommonRequest method of Alibaba Cloud SDK for Java is used to send remote procedure call (RPC) requests. 

  • When you use the SDK to send API requests, you must use the credentials of your Alibaba Cloud account to authenticate your identity. You must use the AccessKey ID and AccessKey secret of your Alibaba Cloud account to call API operations by using Alibaba Cloud SDK for Java and create a globally unique IAcsClient object. For information about how to obtain the AccessKey pair of your Alibaba Cloud account, see Activate Intelligent Speech Interaction

  • The following classes are included in the sample code:

    • AsrLmModelPopApiDemo: the API test class that contains the main method. You can use this class to test API operations and check the status of custom linguistic models during API calls. 

    • AsrLmData: the training dataset class. This class encapsulates the data objects and API operations that are related to training datasets. 

    • AsrLmModel: the custom linguistic model class. This class encapsulates the data objects and API operations that are related to custom linguistic models. 

Add dependencies. You need to add the core library of Alibaba Cloud SDK for Java and the Alibaba Cloud open source library Fastjson to your project dependencies. The core library of Alibaba Cloud SDK for Java must be a version from V3.5.0 to V3.7.x. 

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-core</artifactId>
    <version>3.7.1</version>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.83</version>
</dependency>
  • AsrLmModelPopApiDemo

    import com.alibaba.fastjson.JSONObject;
    import com.aliyuncs.DefaultAcsClient;
    import com.aliyuncs.IAcsClient;
    import com.aliyuncs.profile.DefaultProfile;
    public class AsrLmModelPopApiDemo {
        private static String REGION = "ap-southeast-1";
        private static final String STATUS_FETCHING = "Fetching";
        private static final String STATUS_FETCHINGFAILED = "FetchingFailed";
        private static final String STATUS_READY = "Ready";
        private static final String STATUS_EMPTY = "Empty";
        private static final String STATUS_TRAINING = "Training";
        private static final String STATUS_TRAININGFAILED = "TrainingFailed";
        private static final String STATUS_DEPLOYING = "Deploying";
        private static final String STATUS_DEPLOYED = "Deployed";
        private static IAcsClient client;
        private AsrLmData asrLmData;
        private AsrLmModel asrLmModel;
        public AsrLmModelPopApiDemo(String akId, String akSecret) {
            DefaultProfile profile = DefaultProfile.getProfile(REGION, akId, akSecret);
            client = new DefaultAcsClient(profile);
            asrLmData = new AsrLmData(client);
            asrLmModel = new AsrLmModel(client);
        }
        /******************************* Manage training datasets *******************************/
        // Create a training dataset.
        public String createAsrLmData(String name, String fileUrl, String description) {
            String dataId = asrLmData.createAsrLmData(name, fileUrl, description);
            if (null == dataId) {
                return dataId;
            }
            // Poll the status of the training dataset until the dataset enters the Ready state. The Ready state indicates that the training dataset is created. 
            while (true) {
                AsrLmData.LmData data = asrLmData.getAsrLmData(dataId);
                if (null == data) {
                    dataId = null;
                    break;
                }
                if (data.Status.equals(STATUS_FETCHING)) {
                    System.out.println("The training corpus data is being imported. Dataset ID: " + dataId);
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                else if (data.Status.equals(STATUS_FETCHINGFAILED)) {
                    System.out.println("An error occurs when the system imports the training corpus data. Dataset ID: " + dataId);
                    asrLmData.deleteAsrLmData(dataId);
                    dataId = null;
                    break;
                }
                else if (data.Status.equals(STATUS_READY)) {
                    System.out.println("The training corpus data is imported. Dataset ID: " + dataId);
                    break;
                }
            }
            return dataId;
        }
        // Query a training dataset.
        public AsrLmData.LmData getAsrLmData(String dataId) {
            return asrLmData.getAsrLmData(dataId);
        }
        // Delete a training dataset.
        public boolean deleteAsrLmData(String dataId) {
            AsrLmData.LmData data = asrLmData.getAsrLmData(dataId);
            if (null == data) {
                return false;
            }
            if (!data.Status.equals(STATUS_READY)) {
                System.out.println("The training dataset in the current state cannot be deleted. Status: " + data.Status);
                return false;
            }
            return asrLmData.deleteAsrLmData(dataId);
        }
        // Query training datasets by page.
        public AsrLmData.LmDataPage listAsrLmData() {
            return asrLmData.listAsrLmData();
        }
        /******************************* Manage custom linguistic models *******************************/
        // Create a custom linguistic model.
        public String createAsrLmModel(String name, String baseId, String description) {
            String modelId = asrLmModel.createAsrLmModel(name, baseId, description);
            if (null == modelId) {
                return modelId;
            }
            // Poll the status of the custom linguistic model until the model enters the Empty state. The Empty state indicates that the custom linguistic model is created. 
            while (true) {
                AsrLmModel.LmModel model = asrLmModel.getAsrLmModel(modelId);
                if (null == model) {
                    modelId = null;
                    break;
                }
                if (model.Status.equals(STATUS_EMPTY)) {
                    break;
                }
                else {
                    System.out.println("Failed to create the custom linguistic model. Model ID: " + modelId);
                    asrLmModel.deleteAsrLmModel(modelId);
                    modelId = null;
                    break;
                }
            }
            return modelId;
        }
        // Query a custom linguistic model.
        public AsrLmModel.LmModel getAsrLmModel(String modelId) {
            return asrLmModel.getAsrLmModel(modelId);
        }
        // Delete a custom linguistic model.
        public boolean deleteAsrLmModel(String modelId) {
            AsrLmModel.LmModel model = asrLmModel.getAsrLmModel(modelId);
            if (null == model) {
                return false;
            }
            if (model.Status.equals(STATUS_TRAINING)  model.Status.equals(STATUS_DEPLOYING)) {
                System.out.println("The custom linguistic model in the current state cannot be deleted. Status: " + model.Status);
                return false;
            }
            return asrLmModel.deleteAsrLmModel(modelId);
        }
        // Query custom linguistic models by page.
        public AsrLmModel.LmModelPage listAsrLmModel() {
            return asrLmModel.listAsrLmModel();
        }
        /**************************** Train a custom linguistic model and publish the custom linguistic model ***************************/
        // Add a training dataset to a custom linguistic model.
        public boolean addDataToAsrLmModel(String dataId, String modelId) {
            AsrLmData.LmData data = asrLmData.getAsrLmData(dataId);
            if (null == data) {
                return false;
            }
            if (!data.Status.equals(STATUS_READY)) {
                System.out.println("The training dataset in the current state cannot be added to the custom linguistic model. Status: " + data.Status);
                return false;
            }
            AsrLmModel.LmModel model = asrLmModel.getAsrLmModel(modelId);
            if (null == model) {
                return false;
            }
            if (model.Status.equals(STATUS_TRAINING)  model.Status.equals(STATUS_DEPLOYING)) {
                System.out.println("The training dataset cannot be added to the custom linguistic model when the model is in the current state. Status: " + model.Status);
                return false;
            }
            return asrLmModel.addDataToAsrLmModel(dataId, modelId);
        }
        // Remove a training dataset from a custom linguistic model.
        public boolean removeDataFromAsrLmModel(String dataId, String modelId) {
            // Query the training datasets that are added to the specified custom linguistic model to check whether the training dataset that you want to delete is added to the custom linguistic model. 
            boolean isAdded = false;
            AsrLmData.LmDataPage page = asrLmData.listAsrLmData(1, 10, modelId);
            if (page != null && page.Content.size() > 0) {
                for (int i = 0; i < page.Content.size(); i++) {
                    if (dataId.equals(page.Content.get(i).Id)) {
                        isAdded = true;
                        break;
                    }
                }
            }
            if (!isAdded) {
                System.out.println("The remove operation failed because the dataset that you specified is not a dataset of the custom linguistic model.")
                return false;
            }
            // Check whether the training dataset can be removed from the custom linguistic model when the model is in the current state.
            AsrLmModel.LmModel model = asrLmModel.getAsrLmModel(modelId);
            if (null == model) {
                return false;
            }
            if (model.Status.equals(STATUS_TRAINING)) {
                System.out.println("The training dataset cannot be removed from the custom linguistic model when the model is in the current state. Status: " + model.Status);
                return false;
            }
            return asrLmModel.removeDataFromAsrLmModel(dataId, modelId);
        }
        // Train a custom linguistic model.
        public boolean trainAsrLmModel(String modelId) {
            AsrLmModel.LmModel model = asrLmModel.getAsrLmModel(modelId);
            if (null == model) {
                return false;
            }
            if (model.Status.equals(STATUS_DEPLOYING)) {
                System.out.println("The custom linguistic model in the current state cannot be trained. Status: " + model.Status);
                return false;
            }
            boolean isTrain = asrLmModel.trainAsrLmModel(modelId);
            if (!isTrain) {
                return isTrain;
            }
            // Poll the status of the custom linguistic model until the model enters the Deployed state. The Deployed state indicates that the custom linguistic model is trained and published. 
            while (true) {
                model = asrLmModel.getAsrLmModel(modelId);
                if (null == model) {
                    isTrain = false;
                    break;
                }
                if (model.Status.equals(STATUS_TRAINING)  model.Status.equals(STATUS_DEPLOYING)) {
                    if (model.Status.equals(STATUS_TRAINING)) {
                        System.out.println("The custom linguistic model is being trained. Model ID: " + modelId);
                    }
                    else {
                        System.out.println("The custom linguistic model is being published. Model ID: " + modelId);
                    }
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                else if (model.Status.equals(STATUS_TRAININGFAILED)) {
                    System.out.println("Failed to train the custom linguistic model. Model ID: " + modelId);
                    isTrain = false;
                    break;
                }
                else if (model.Status.equals(STATUS_DEPLOYED)) {
                    System.out.println("The custom linguistic model is trained and published. Model ID: " + modelId);
                    isTrain = true;
                    break;
                }
                else {
                    System.out.println("The custom linguistic model in the current state cannot be trained. Status: " + model.Status);
                    isTrain = false;
                    break;
                }
            }
            return isTrain;
        }
        // Publish a custom linguistic model.
        public boolean deployAsrLmModel(String modelId) {
            AsrLmModel.LmModel model = asrLmModel.getAsrLmModel(modelId);
            if (null == model) {
                return false;
            }
            if (!model.Status.equals(STATUS_READY)) {
                System.out.println("The custom linguistic model in the current state cannot be published. Status: " + model.Status);
                return false;
            }
            boolean isDeployed = asrLmModel.deployAsrLmModel(modelId);
            if (!isDeployed) {
                return isDeployed;
            }
            // Poll the status of the custom linguistic model until the model enters the Deployed state. The Deployed state indicates that the custom linguistic model is published. 
            while (true) {
                model = asrLmModel.getAsrLmModel(modelId);
                if (null == model) {
                    isDeployed = false;
                    break;
                }
                if (model.Status.equals(STATUS_DEPLOYING)) {
                    System.out.println("The custom linguistic model is being published. Model ID: " + modelId);
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                else if (model.Status.equals(STATUS_DEPLOYED)) {
                    System.out.println("The custom linguistic model is published. Model ID: " + modelId);
                    isDeployed = true;
                    break;
                }
                else {
                    System.out.println("The custom linguistic model in the current state cannot be published. Status: " + model.Status);
                    isDeployed = false;
                    break;
                }
            }
            return isDeployed;
        }
        // Unpublish a custom linguistic model.
        public boolean undeployAsrLmModel(String modelId) {
            AsrLmModel.LmModel model = asrLmModel.getAsrLmModel(modelId);
            if (null == model) {
                return false;
            }
            if (!model.Status.equals(STATUS_DEPLOYED)) {
                System.out.println("The custom linguistic model in the current state cannot be unpublished. Status: " + model.Status);
                return false;
            }
            boolean isUnDeployed = asrLmModel.undeployAsrLmModel(modelId);
            if (!isUnDeployed) {
                return isUnDeployed;
            }
            // Poll the status of the custom linguistic model until the model enters the Ready state. If the model enters the Ready state, the custom linguistic model is unpublished. 
            while (true) {
                model = asrLmModel.getAsrLmModel(modelId);
                if (null == model) {
                    isUnDeployed = false;
                    break;
                }
                if (model.Status.equals(STATUS_DEPLOYING)) {
                    System.out.println("The custom linguistic model is being unpublished. Model ID: " + modelId);
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                else if (model.Status.equals(STATUS_READY)) {
                    System.out.println("The custom linguistic model is unpublished. Model ID: " + modelId);
                    isUnDeployed = true;
                    break;
                }
                else {
                    System.out.println("The custom linguistic model in the current state cannot be unpublished. Status: " + model.Status);
                    isUnDeployed = false;
                    break;
                }
            }
            return isUnDeployed;
        }
        public static void main(String[] args) {
            if (args.length < 2) {
                System.err.println("AsrLmModelPopApiDemo need params: <AccessKey Id> <AccessKey Secret>");
                return;
            }
            String accessKeyId = args[0];
            String accessKeySecret = args[1];
            AsrLmModelPopApiDemo demo = new AsrLmModelPopApiDemo(accessKeyId, accessKeySecret);
            /******************************* Manage training datasets *******************************/
            // The ID of a training dataset.
            String dataId;
            // Create a training dataset.
            String name = "TestTrainingDataset";
            String fileUrl = "https://aliyun-nls.oss-cn-hangzhou.aliyuncs.com/asr/fileASR/SLP/SLPTest.txt";
            String description = "The training dataset is created by using the API.";
            dataId = demo.createAsrLmData(name, fileUrl, description);
            if (dataId != null) {
                System.out.println("The training dataset is created. Dataset ID:" + dataId);
            }
            else {
                System.out.println("Failed to create the training dataset.")
            }
            // Query a training dataset.
            AsrLmData.LmData data = demo.getAsrLmData(dataId);
            if (data != null) {
                System.out.println("The information about the training dataset is returned." + JSONObject.toJSONString(data));
            }
            else {
                System.out.println("Failed to query the training dataset.")
            }
            // Query training datasets by page.
            AsrLmData.LmDataPage page = demo.listAsrLmData();
            if (page != null) {
                System.out.println("The information about the training datasets on the specified page is returned." + JSONObject.toJSONString(page));
            }
            else {
                System.out.println("Failed to query training datasets.")
                return;
            }
            /************************** Manage custom linguistic models *********************************/
            // The ID of a custom linguistic model.
            String modelId;
            // Create a custom linguistic model.
            String modelName = "TestLinguisticModel";
            // In this example, the universal Chinese speech recognition model is used. You must specify a basic model based on your business requirements. 
            String baseId = "universal";
            String modelDescription = "This is a sample description.";
            modelId = demo.createAsrLmModel(modelName, baseId, modelDescription);
            if (modelId != null) {
                System.out.println("The custom linguistic model is created. Model ID:" + modelId);
            }
            else {
                System.out.println("Failed to create the custom linguistic model.")
            }
            // Query a custom linguistic model.
            AsrLmModel.LmModel model = demo.getAsrLmModel(modelId);
            if (model != null) {
                System.out.println("The information about the custom linguistic model is returned." + JSONObject.toJSONString(model));
            }
            else {
                System.out.println("Failed to query the custom linguistic model.")
            }
            // Query custom linguistic models by page.
            AsrLmModel.LmModelPage modelPage = demo.listAsrLmModel();
            if (modelPage != null) {
                System.out.println("The information about the custom linguistic models on the specified page is returned." + JSONObject.toJSONString(modelPage));
            }
            else {
                System.out.println("Failed to query custom linguistic models.")
            }
            /******************************* Train a custom linguistic model and publish the custom linguistic model *******************************/
            // Add a training dataset to a custom linguistic model.
            boolean isAdded = demo.addDataToAsrLmModel(dataId, modelId);
            if (isAdded) {
                System.out.println("The training dataset is added to the custom linguistic model.")
            }
            else {
                System.out.println("Failed to add the training dataset to the custom linguistic model.")
            }
            // Train a custom linguistic model.
            boolean isTrian = demo.trainAsrLmModel(modelId);
            if (isTrian) {
                System.out.println("The custom linguistic model is trained.")
            }
            else {
                System.out.println("Failed to train the custom linguistic model.")
            }
            // Unpublish a custom linguistic model.
            boolean isUnDeployed = demo.undeployAsrLmModel(modelId);
            if (isUnDeployed) {
                System.out.println("The custom linguistic model is unpublished.")
            }
            else {
                System.out.println("Failed to unpublish the custom linguistic model.")
            }
            // Publish a custom linguistic model.
            boolean isDeployed = demo.deployAsrLmModel(modelId);
            if (isDeployed) {
                System.out.println("The custom linguistic model is published.")
            }
            else {
                System.out.println("Failed to publish the custom linguistic model.")
            }
            /***************************** Delete training datasets and custom linguistic models based on your business requirements *****************************/
            // 1. Unpublish a custom linguistic model based on your business requirements. 
            isUnDeployed = demo.undeployAsrLmModel(modelId);
            if (isUnDeployed) {
                System.out.println("The custom linguistic model is unpublished.")
            }
            else {
                System.out.println("Failed to unpublish the custom linguistic model.")
            }
            // 2. Remove a training dataset from a custom linguistic model based on your business requirements. 
            boolean isDeleted = demo.removeDataFromAsrLmModel(dataId, modelId);
            if (isDeleted) {
                System.out.println("The training dataset is removed from the custom linguistic model.")
            }
            else {
                System.out.println("Failed to remove the training dataset from the custom linguistic model.")
            }
            // 3. Delete a dataset based on your business requirements. 
            boolean isDeletedData = demo.deleteAsrLmData(dataId);
            if (isDeletedData) {
                System.out.println("The training dataset is deleted.")
            }
            else {
                System.out.println("Failed to delete the training dataset.")
            }
            // 4. Delete a custom linguistic model based on your business requirements. 
            boolean isDeletedModel = demo.deleteAsrLmModel(modelId);
            if (isDeletedModel) {
                System.out.println("The custom linguistic model is deleted.")
            }
            else {
                System.out.println("Failed to delete the custom linguistic model.")
            }
        }
    }

  • AsrLmData

    import com.alibaba.fastjson.JSONObject;
    import com.aliyuncs.CommonRequest;
    import com.aliyuncs.CommonResponse;
    import com.aliyuncs.IAcsClient;
    import com.aliyuncs.exceptions.ClientException;
    import com.aliyuncs.http.MethodType;
    import com.aliyuncs.http.ProtocolType;
    import java.util.ArrayList;
    import java.util.List;
    public class AsrLmData {
        public static class LmData {
            public String Name;
            public String Status;
            public String Description;
            public String Url;
            public String CreateTime;
            public String UpdateTime;
            public String Id;
            public String ErrorMessage;   // An error message is returned only when an operation fails. 
            public int Size;
        }
        public static class LmDataPage {
            public int PageNumber;
            public int PageSize;
            public int TotalItems;
            public int TotalPages;
            public List<LmData> Content = new ArrayList<LmData>();
        }
        private static final String VERSION = "2018-11-20";
        private static final String DOMAIN = "nls-slp.ap-southeast-1.aliyuncs.com";
        private static ProtocolType PROTOCOL_TYPE = ProtocolType.HTTPS;
        private static final String KEY_NAME = "Name";
        private static final String KEY_URL = "Url";
        private static final String KEY_DESCRIPTION = "Description";
        private static final String KEY_DATA_ID = "DataId";
        private static final String KEY_DATA = "Data";
        private static final String KEY_PAGE = "Page";
        private static final String KEY_PAGE_NUMBER = "PageNumber";
        private static final String KEY_PAGE_SIZE = "PageSize";
        private static final String KEY_MODEL_ID = "ModelId";
        private IAcsClient client;
        private CommonRequest newRequest(String action) {
            CommonRequest request = new CommonRequest();
            request.setDomain(DOMAIN);
            request.setProtocol(PROTOCOL_TYPE);
            request.setVersion(VERSION);
            request.setMethod(MethodType.POST);
            request.setAction(action);
            return request;
        }
        public AsrLmData(IAcsClient client) {
            this.client = client;
        }
        /**
         * Create a training dataset.
         * @param name: Required. The name of the training dataset that you want to create. 
         * @param fileUrl: Required. The URL from which you want Intelligent Speech Interaction to import training corpus data. 
         * @param description: Optional. The description of the training dataset. 
         * @return: Returns the ID of the training dataset. The value is of the STRING data type. 
         */
        public String createAsrLmData(String name, String fileUrl, String description) {
            CommonRequest request = newRequest("CreateAsrLmData");
            request.putBodyParameter(KEY_NAME, name);
            request.putBodyParameter(KEY_URL, fileUrl);
            request.putBodyParameter(KEY_DESCRIPTION, description);
            CommonResponse response = null;
            try {
                response = client.getCommonResponse(request);
            } catch (ClientException e) {
                e.printStackTrace();
            }
            System.out.println("CreateAsrLmData: " + response.getData());
            if (response == null  response.getHttpStatus() != 200) {
                System.out.println(response.getData());
                System.out.println("Failed to create the training dataset. HTTP status code:" + response.getHttpStatus());
                return null;
            }
            JSONObject result = JSONObject.parseObject(response.getData());
            String dataId = result.getString(KEY_DATA_ID);
            return dataId;
        }
        /**
         * Query a training dataset.
         * @param dataId: The ID of the training dataset that you want to query.
         * @return LmData: The information about the training dataset.
         */
        public LmData getAsrLmData(String dataId) {
            CommonRequest request = newRequest("GetAsrLmData");
            request.putBodyParameter(KEY_DATA_ID, dataId);
            CommonResponse response = null;
            try {
                response = client.getCommonResponse(request);
            } catch (ClientException e) {
                e.printStackTrace();
            }
            System.out.println("GetAsrLmData: " + response.getData());
            if (response == null  response.getHttpStatus() != 200) {
                System.out.println(response.getData());
                System.out.println("Failed to query the training dataset. HTTP status code:" + response.getHttpStatus());
                return null;
            }
            JSONObject result = JSONObject.parseObject(response.getData());
            String dataJson = result.getString(KEY_DATA);
            LmData data = JSONObject.parseObject(dataJson, LmData.class);
            return data;
        }
        /**
         * Delete a training dataset.
         * @param dataId: Required. The ID of the training dataset that you want to delete. 
         * @return: Returns a value that indicates whether the training dataset is deleted. 
         */
        public boolean deleteAsrLmData(String dataId) {
            CommonRequest request = newRequest("DeleteAsrLmData");
            request.putBodyParameter(KEY_DATA_ID, dataId);
            CommonResponse response = null;
            try {
                response = client.getCommonResponse(request);
            } catch (ClientException e) {
                e.printStackTrace();
            }
            System.out.println("DeleteAsrLmData: " + response.getData());
            if (response == null  response.getHttpStatus() != 200) {
                System.out.println(response.getData());
                System.out.println("Failed to delete the training dataset. HTTP status code:" + response.getHttpStatus());
                return false;
            }
            return true;
        }
        /**
         * Query training datasets by page.
         * @param pageNumber: Optional. The number of the page to return. Pages start from page 1. Default value: 1. 
         * @param pageSize: Optional. The number of entries to return on each page. Valid values: 10 to 100. Default value: 10. 
         * @param modelId: Optional. The ID of the custom linguistic model based on which you want to query training datasets. You can specify this parameter to query training datasets that are used by the specified custom linguistic model. If you do not specify this parameter, the system queries all training datasets that you can access. 
         * @return: Returns the information about the training datasets on the specified page. 
         */
        public LmDataPage listAsrLmData(int pageNumber, int pageSize, String modelId) {
            CommonRequest request = newRequest("ListAsrLmData");
            request.putBodyParameter(KEY_PAGE_NUMBER, pageNumber);
            request.putBodyParameter(KEY_PAGE_SIZE, pageSize);
            request.putBodyParameter(KEY_MODEL_ID, modelId);
            CommonResponse response = null;
            try {
                response = client.getCommonResponse(request);
            } catch (ClientException e) {
                e.printStackTrace();
            }
            System.out.println("ListAsrLmData: " + response.getData());
            if (response == null  response.getHttpStatus() != 200) {
                System.out.println(response.getData());
                System.out.println("Failed to query training datasets. HTTP status code:" + response.getHttpStatus());
                return null;
            }
            JSONObject result = JSONObject.parseObject(response.getData());
            String pageJson = result.getString(KEY_PAGE);
            LmDataPage page = JSONObject.parseObject(pageJson, LmDataPage.class);
            return page;
        }
        public LmDataPage listAsrLmData() {
            return listAsrLmData(1, 10, null);
        }
    }

  • AsrLmModel

    import com.alibaba.fastjson.JSONObject;
    import com.aliyuncs.CommonRequest;
    import com.aliyuncs.CommonResponse;
    import com.aliyuncs.IAcsClient;
    import com.aliyuncs.exceptions.ClientException;
    import com.aliyuncs.http.MethodType;
    import com.aliyuncs.http.ProtocolType;
    import java.util.ArrayList;
    import java.util.List;
    public class AsrLmModel {
        public static class LmModel {
            public String Name;
            public String Status;
            public String Description;
            public String CreateTime;
            public String UpdateTime;
            public String Id;
            public String BaseId;
            public String ErrorMessage;   // An error message is returned only when an operation fails. 
            public int Size;
        }
        public static class LmModelPage {
            public int PageNumber;
            public int PageSize;
            public int TotalItems;
            public int TotalPages;
            public List<LmModel> Content = new ArrayList<LmModel>();
        }
        private static final String VERSION = "2018-11-20";
        private static final String DOMAIN = "nls-slp.ap-southeast-1.aliyuncs.com";
        private static ProtocolType PROTOCOL_TYPE = ProtocolType.HTTPS;
        private static final String KEY_NAME = "Name";
        private static final String KEY_BASE_ID = "BaseId";
        private static final String KEY_DESCRIPTION = "Description";
        private static final String KEY_MODEL_ID = "ModelId";
        private static final String KEY_MODEL = "Model";
        private static final String KEY_PAGE = "Page";
        private static final String KEY_PAGE_NUMBER = "PageNumber";
        private static final String KEY_PAGE_SIZE = "PageSize";
        private static final String KEY_DATA_ID = "DataId";
        private IAcsClient client;
        private CommonRequest newRequest(String action) {
            CommonRequest request = new CommonRequest();
            request.setDomain(DOMAIN);
            request.setProtocol(PROTOCOL_TYPE);
            request.setVersion(VERSION);
            request.setMethod(MethodType.POST);
            request.setAction(action);
            return request;
        }
        public AsrLmModel(IAcsClient client) {
            this.client = client;
        }
        /**
         * Create a custom linguistic model.
         * @param name: Required. The name of the custom linguistic model that you want to create. 
         * @param baseId: Required. The ID of the basic model that you want to use. You cannot change the basic model after the custom linguistic model is created. 
         * @param description: Optional. The description of the custom linguistic model. 
         * @return: Returns the ID of the custom linguistic model. 
         */
        public String createAsrLmModel(String name, String baseId, String description) {
            CommonRequest request = newRequest("CreateAsrLmModel");
            request.putBodyParameter(KEY_NAME, name);
            request.putBodyParameter(KEY_BASE_ID, baseId);
            request.putBodyParameter(KEY_DESCRIPTION, description);
            CommonResponse response = null;
            try {
                response = client.getCommonResponse(request);
            } catch (ClientException e) {
                e.printStackTrace();
            }
            System.out.println("CreateAsrLmModel: " + response.getData());
            if (response == null  response.getHttpStatus() != 200) {
                System.out.println(response.getData());
                System.out.println("Failed to create the custom linguistic model. HTTP status code:" + response.getHttpStatus());
                return null;
            }
            JSONObject result = JSONObject.parseObject(response.getData());
            String modelId = result.getString(KEY_MODEL_ID);
            return modelId;
        }
        /**
         * Query a custom linguistic model.
         * @param modelId: The ID of the custom linguistic model that you want to query.
         * @return: Returns the information about the custom linguistic model.
         */
        public LmModel getAsrLmModel(String modelId) {
            CommonRequest request = newRequest("GetAsrLmModel");
            request.putBodyParameter(KEY_MODEL_ID, modelId);
            CommonResponse response = null;
            try {
                response = client.getCommonResponse(request);
            } catch (ClientException e) {
                e.printStackTrace();
            }
            System.out.println("GetAsrLmModel: " + response.getData());
            if (response == null  response.getHttpStatus() != 200) {
                System.out.println(response.getData());
                System.out.println("Failed to query the custom linguistic model. HTTP status code:" + response.getHttpStatus());
                return null;
            }
            JSONObject result = JSONObject.parseObject(response.getData());
            String modelJson = result.getString(KEY_MODEL);
            LmModel model = JSONObject.parseObject(modelJson, LmModel.class);
            return model;
        }
        /**
         * Delete a custom linguistic model.
         * @param modelId: The ID of the custom linguistic model that you want to delete.
         * @return: Returns a value that indicates whether the custom linguistic model is deleted.
         */
        public boolean deleteAsrLmModel(String modelId) {
            CommonRequest request = newRequest("DeleteAsrLmModel");
            request.putBodyParameter(KEY_MODEL_ID, modelId);
            CommonResponse response = null;
            try {
                response = client.getCommonResponse(request);
            } catch (ClientException e) {
                e.printStackTrace();
            }
            System.out.println("DeleteAsrLmModel: " + response.getData());
            if (response == null  response.getHttpStatus() != 200) {
                System.out.println(response.getData());
                System.out.println("Failed to delete the custom linguistic model. HTTP status code:" + response.getHttpStatus());
                return false;
            }
            return true;
        }
        /**
         * Query custom linguistic models by page.
         * @param pageNumber: Optional. The number of the page to return. Pages start from page 1. Default value: 1. 
         * @param pageSize: Optional. The number of entries to return on each page. Valid values: 1 to 100. Default value: 10. 
         * @param dataId: Optional. The ID of the training dataset based on which you want to query custom linguistic models. You can specify this parameter to query the custom linguistic models that use the specified training dataset. If you do not specify this parameter, the system queries all custom linguistic models that you can access. 
         * @return: Returns the information about the custom linguistic models on the specified page. 
         */
        public LmModelPage listAsrLmModel(int pageNumber, int pageSize, String dataId) {
            CommonRequest request = newRequest("ListAsrLmModel");
            request.putBodyParameter(KEY_PAGE_NUMBER, pageNumber);
            request.putBodyParameter(KEY_PAGE_SIZE, pageSize);
            request.putBodyParameter(KEY_DATA_ID, dataId);
            CommonResponse response = null;
            try {
                response = client.getCommonResponse(request);
            } catch (ClientException e) {
                e.printStackTrace();
            }
            System.out.println("ListAsrLmModel: " + response.getData());
            if (response == null  response.getHttpStatus() != 200) {
                System.out.println(response.getData());
                System.out.println("Failed to query custom linguistic models. HTTP status code:" + response.getHttpStatus());
                return null;
            }
            JSONObject result = JSONObject.parseObject(response.getData());
            String pageJson = result.getString(KEY_PAGE);
            LmModelPage page = JSONObject.parseObject(pageJson, LmModelPage.class);
            return page;
        }
        public LmModelPage listAsrLmModel() {
            return listAsrLmModel(1, 10, null);
        }
        /**
         * Add a training dataset to a custom linguistic model.
         * @param dataId: The ID of the training dataset that you want to add to a custom linguistic model.
         * @param modelId: The ID of the custom linguistic model to which you want to add the training dataset.
         * @return: Returns a value that indicates whether the training dataset is added to the custom linguistic model.
         */
        public boolean addDataToAsrLmModel(String dataId, String modelId) {
            CommonRequest request = newRequest("AddDataToAsrLmModel");
            request.putBodyParameter(KEY_DATA_ID, dataId);
            request.putBodyParameter(KEY_MODEL_ID, modelId);
            CommonResponse response = null;
            try {
                response = client.getCommonResponse(request);
            } catch (ClientException e) {
                e.printStackTrace();
            }
            System.out.println("AddDataToAsrLmModel: " + response.getData());
            if (response == null  response.getHttpStatus() != 200) {
                System.out.println(response.getData());
                System.out.println("Failed to add the training dataset to the custom linguistic model. HTTP status code:" + response.getHttpStatus());
                return false;
            }
            return true;
        }
        /**
         * Remove a training dataset from a custom linguistic model
         * @param dataId: The ID of the training dataset that you want to remove.
         * @param modelId: The ID of the custom linguistic model from which you want to remove the training dataset.
         * @return: Returns a value that indicates whether the training dataset is removed from the custom linguistic model.
         */
        public boolean removeDataFromAsrLmModel(String dataId, String modelId) {
            CommonRequest request = newRequest("RemoveDataFromAsrLmModel");
            request.putBodyParameter(KEY_DATA_ID, dataId);
            request.putBodyParameter(KEY_MODEL_ID, modelId);
            CommonResponse response = null;
            try {
                response = client.getCommonResponse(request);
            } catch (ClientException e) {
                e.printStackTrace();
            }
            System.out.println("RemoveDataFromAsrLmModel: " + response.getData());
            if (response == null  response.getHttpStatus() != 200) {
                System.out.println(response.getData());
                System.out.println("Failed to remove the training dataset from the custom linguistic model. HTTP status code:" + response.getHttpStatus());
                return false;
            }
            return true;
        }
        /**
         * Train a custom linguistic model.
         * @param modelId: The ID of the custom linguistic model that you want to train.
         * @return: Returns a value that indicates whether the custom linguistic model is trained.
         * */
        public boolean trainAsrLmModel(String modelId) {
            CommonRequest request = newRequest("TrainAsrLmModel");
            request.putBodyParameter(KEY_MODEL_ID, modelId);
            CommonResponse response = null;
            try {
                response = client.getCommonResponse(request);
            } catch (ClientException e) {
                e.printStackTrace();
            }
            System.out.println("TrainAsrLmModel: " + response.getData());
            if (response == null  response.getHttpStatus() != 200) {
                System.out.println(response.getData());
                System.out.println("Failed to train the custom linguistic model. HTTP status code:" + response.getHttpStatus());
                return false;
            }
            return true;
        }
        /**
         * Publish a custom linguistic model.
         * @param modelId: The ID of the custom linguistic model that you want to publish.
         * @return: Returns a value that indicates whether the custom linguistic model is published.
         */
        public boolean deployAsrLmModel(String modelId) {
            CommonRequest request = newRequest("DeployAsrLmModel");
            request.putBodyParameter(KEY_MODEL_ID, modelId);
            CommonResponse response = null;
            try {
                response = client.getCommonResponse(request);
            } catch (ClientException e) {
                e.printStackTrace();
            }
            System.out.println("DeployAsrLmModel: " + response.getData());
            if (response == null  response.getHttpStatus() != 200) {
                System.out.println(response.getData());
                System.out.println("Failed to publish the custom linguistic model. HTTP status code:" + response.getHttpStatus());
                return false;
            }
            return true;
        }
        /**
         * Unpublish a custom linguistic model.
         * @param modelId: The ID of the custom linguistic model that you want to unpublish.
         * @return: Returns a value that indicates whether the custom linguistic model is unpublished.
         */
        public boolean undeployAsrLmModel(String modelId) {
            CommonRequest request = newRequest("UndeployAsrLmModel");
            request.putBodyParameter(KEY_MODEL_ID, modelId);
            CommonResponse response = null;
            try {
                response = client.getCommonResponse(request);
            } catch (ClientException e) {
                e.printStackTrace();
            }
            System.out.println("UndeployAsrLmModel: " + response.getData());
            if (response == null  response.getHttpStatus() != 200) {
                System.out.println(response.getData());
                System.out.println("Failed to unpublish the custom linguistic model. HTTP status code:" + response.getHttpStatus());
                return false;
            }
            return true;
        }
    }