NaturalLanguageClassifier

public class NaturalLanguageClassifier

On 9 August 2021, IBM announced the deprecation of IBM Watson™ Natural Language Classifier. As of 9 September 2021, you cannot create new instances. However, existing instances are supported until 8 August 2022. The service will no longer be available on 8 August 2022.

As an alternative, consider migrating to IBM Watson Natural Language Understanding. For more information, see Migrating to Natural Language Understanding. {: deprecated} Natural Language Classifier uses machine learning algorithms to return the top matching predefined classes for short text input. You create and train a classifier to connect predefined classes to example texts so that the service can apply those classes to new inputs.

  • The base URL to use when contacting the service.

    Declaration

    Swift

    public var serviceURL: String?
  • Service identifiers

    Declaration

    Swift

    public static let defaultServiceName: String
  • The default HTTP headers for all requests to the service.

    Declaration

    Swift

    public var defaultHeaders: [String : String]
  • Undocumented

    Declaration

    Swift

    public let authenticator: Authenticator
  • Create a NaturalLanguageClassifier object.

    If an authenticator is not supplied, the initializer will retrieve credentials from the environment or a local credentials file and construct an appropriate authenticator using these credentials. The credentials file can be downloaded from your service instance on IBM Cloud as ibm-credentials.env. Make sure to add the credentials file to your project so that it can be loaded at runtime.

    If an authenticator is not supplied and credentials are not available in the environment or a local credentials file, initialization will fail by throwing an exception. In that case, try another initializer that directly passes in the credentials.

    • serviceName: String = defaultServiceName
  • Create a NaturalLanguageClassifier object.

    Declaration

    Swift

    public init(authenticator: Authenticator)

    Parameters

    authenticator

    The Authenticator object used to authenticate requests to the service

  • Allow network requests to a server without verification of the server certificate. IMPORTANT: This should ONLY be used if truly intended, as it is unsafe otherwise.

    Declaration

    Swift

    public func disableSSLVerification()
  • Classify a phrase.

    Returns label information for the input. The status must be Available before you can use the classifier to classify text.

    Declaration

    Swift

    public func classify(
        classifierID: String,
        text: String,
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<Classification>?, WatsonError?) -> Void)

    Parameters

    classifierID

    Classifier ID to use.

    text

    The submitted phrase. The maximum length is 2048 characters.

    headers

    A dictionary of request headers to be sent with this request.

    completionHandler

    A function executed when the request completes with a successful result or error

  • Classify multiple phrases.

    Returns label information for multiple phrases. The status must be Available before you can use the classifier to classify text. Note that classifying Japanese texts is a beta feature.

    Declaration

    Swift

    public func classifyCollection(
        classifierID: String,
        collection: [ClassifyInput],
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<ClassificationCollection>?, WatsonError?) -> Void)

    Parameters

    classifierID

    Classifier ID to use.

    collection

    The submitted phrases.

    headers

    A dictionary of request headers to be sent with this request.

    completionHandler

    A function executed when the request completes with a successful result or error

  • Create classifier.

    Sends data to create and train a classifier and returns information about the new classifier.

    Declaration

    Swift

    public func createClassifier(
        trainingMetadata: Data,
        trainingData: Data,
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<Classifier>?, WatsonError?) -> Void)

    Parameters

    trainingMetadata

    Metadata in JSON format. The metadata identifies the language of the data, and an optional name to identify the classifier. Specify the language with the 2-letter primary language code as assigned in ISO standard 639. Supported languages are English (en), Arabic (ar), French (fr), German, (de), Italian (it), Japanese (ja), Korean (ko), Brazilian Portuguese (pt), and Spanish (es).

    trainingData

    Training data in CSV format. Each text value must have at least one class. The data can include up to 3,000 classes and 20,000 records. For details, see Data preparation.

    headers

    A dictionary of request headers to be sent with this request.

    completionHandler

    A function executed when the request completes with a successful result or error

  • List classifiers.

    Returns an empty array if no classifiers are available.

    Declaration

    Swift

    public func listClassifiers(
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<ClassifierList>?, WatsonError?) -> Void)

    Parameters

    headers

    A dictionary of request headers to be sent with this request.

    completionHandler

    A function executed when the request completes with a successful result or error

  • Get information about a classifier.

    Returns status and other information about a classifier.

    Declaration

    Swift

    public func getClassifier(
        classifierID: String,
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<Classifier>?, WatsonError?) -> Void)

    Parameters

    classifierID

    Classifier ID to query.

    headers

    A dictionary of request headers to be sent with this request.

    completionHandler

    A function executed when the request completes with a successful result or error

  • Delete classifier.

    Declaration

    Swift

    public func deleteClassifier(
        classifierID: String,
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<Void>?, WatsonError?) -> Void)

    Parameters

    classifierID

    Classifier ID to delete.

    headers

    A dictionary of request headers to be sent with this request.

    completionHandler

    A function executed when the request completes with a successful result or error