Text Classification

  • Example request
    //You are advised to construct and use the client in a singleton pattern to avoid frequent object creation.
    NluClient client = new NluClient (AuthMode.AKSK,authInfo);
    
    ClassifyReq req = new ClassifyReq();
    req.setContent("Text for classification");
    
    //Classified domain type. ClassifyDomainConstant.DOMAIN_TYPE_AD indicates advertisement and its value is 1. Currently, only the advertisement type is supported.
    req.setDomain(ClassifyDomainConstant.DOMAIN_TYPE_AD);
    
    try {
        ClassifyResp resp = client.classifyText(req);
    } catch (NlpException e) {
        //A failure is thrown as an exception. For details about exceptions, see section "Exceptions". The client automatically processes exceptions.
    }
  • Table 1 describes ClassifyReq parameters.
    Table 1 ClassifyReq parameters

    Parameter

    Mandatory

    Type

    Description

    content

    Yes

    String

    Text to be analyzed. The text is encoded using UTF-8 and the value contains a maximum of 400 characters. If the value exceeds 400 characters, only the first 400 characters are detected.

    domain

    No

    Integer

    The default value is 1. Currently, only advertisement detection is supported.

    1: Advertisement detection

  • Table 2 describes ClassifyResp parameters.
    Table 2 ClassifyResp parameters

    Parameter

    Type

    Description

    result

    Result

    Encapsulated object of the returned result

  • Table 3 describes the data structure description of the Result field.
    Table 3 Data structure description of the Result field

    Parameter

    Type

    Description

    content

    String

    Text to be analyzed.

    label

    Integer

    Positive and negative labels are included.

    • 1: advertisement
    • 0: non-advertisement

    confidence

    Float

    Confidence level of a label