NaturalLanguageUnderstanding

public class NaturalLanguageUnderstanding

Analyze various features of text content at scale. Provide text, raw HTML, or a public URL and IBM Watson Natural Language Understanding will give you results for the features you request. The service cleans HTML content before analysis by default, so the results can ignore most advertisements and other unwanted content. You can create custom models with Watson Knowledge Studio to detect custom entities and relations in Natural Language Understanding.

  • The base URL to use when contacting the service.

    Declaration

    Swift

    public var serviceURL: String?
  • Release date of the API version you want to use. Specify dates in YYYY-MM-DD format. The current version is 2021-08-01.

    Declaration

    Swift

    public var version: 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 NaturalLanguageUnderstanding 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 NaturalLanguageUnderstanding object.

    Declaration

    Swift

    public init(version: String, authenticator: Authenticator)

    Parameters

    version

    Release date of the API version you want to use. Specify dates in YYYY-MM-DD format. The current version is 2021-08-01.

    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()
  • Analyze text.

    Analyzes text, HTML, or a public webpage for the following features:

    • Categories
    • Classifications
    • Concepts
    • Emotion
    • Entities
    • Keywords
    • Metadata
    • Relations
    • Semantic roles
    • Sentiment
    • Syntax
    • Summarization (Experimental) If a language for the input text is not specified with the language parameter, the service automatically detects the language.

    Declaration

    Swift

    public func analyze(
        features: Features,
        text: String? = nil,
        html: String? = nil,
        url: String? = nil,
        clean: Bool? = nil,
        xpath: String? = nil,
        fallbackToRaw: Bool? = nil,
        returnAnalyzedText: Bool? = nil,
        language: String? = nil,
        limitTextCharacters: Int? = nil,
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<AnalysisResults>?, WatsonError?) -> Void)

    Parameters

    features

    Specific features to analyze the document for.

    text

    The plain text to analyze. One of the text, html, or url parameters is required.

    html

    The HTML file to analyze. One of the text, html, or url parameters is required.

    url

    The webpage to analyze. One of the text, html, or url parameters is required.

    clean

    Set this to false to disable webpage cleaning. For more information about webpage cleaning, see Analyzing webpages.

    xpath

    An XPath query to perform on html or url input. Results of the query will be appended to the cleaned webpage text before it is analyzed. To analyze only the results of the XPath query, set the clean parameter to false.

    fallbackToRaw

    Whether to use raw HTML content if text cleaning fails.

    returnAnalyzedText

    Whether or not to return the analyzed text.

    language

    ISO 639-1 code that specifies the language of your text. This overrides automatic language detection. Language support differs depending on the features you include in your analysis. For more information, see Language support.

    limitTextCharacters

    Sets the maximum number of characters that are processed by the service.

    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 models.

    Lists Watson Knowledge Studio custom entities and relations models that are deployed to your Natural Language Understanding service.

    Declaration

    Swift

    public func listModels(
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<ListModelsResults>?, 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

  • Delete model.

    Deletes a custom model.

    Declaration

    Swift

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

    Parameters

    modelID

    Model ID of the model 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

  • Create sentiment model.

    (Beta) Creates a custom sentiment model by uploading training data and associated metadata. The model begins the training and deploying process and is ready to use when the status is available.

    Declaration

    Swift

    public func createSentimentModel(
        language: String,
        trainingData: Data,
        name: String? = nil,
        description: String? = nil,
        modelVersion: String? = nil,
        workspaceID: String? = nil,
        versionDescription: String? = nil,
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<SentimentModel>?, WatsonError?) -> Void)

    Parameters

    language

    The 2-letter language code of this model.

    trainingData

    Training data in CSV format. For more information, see Sentiment training data requirements.

    name

    An optional name for the model.

    description

    An optional description of the model.

    modelVersion

    An optional version string.

    workspaceID

    ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.

    versionDescription

    The description of the version.

    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 sentiment models.

    (Beta) Returns all custom sentiment models associated with this service instance.

    Declaration

    Swift

    public func listSentimentModels(
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<ListSentimentModelsResponse>?, 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 sentiment model details.

    (Beta) Returns the status of the sentiment model with the given model ID.

    Declaration

    Swift

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

    Parameters

    modelID

    ID of the model.

    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

  • Update sentiment model.

    (Beta) Overwrites the training data associated with this custom sentiment model and retrains the model. The new model replaces the current deployment.

    Declaration

    Swift

    public func updateSentimentModel(
        modelID: String,
        language: String,
        trainingData: Data,
        name: String? = nil,
        description: String? = nil,
        modelVersion: String? = nil,
        workspaceID: String? = nil,
        versionDescription: String? = nil,
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<SentimentModel>?, WatsonError?) -> Void)

    Parameters

    modelID

    ID of the model.

    language

    The 2-letter language code of this model.

    trainingData

    Training data in CSV format. For more information, see Sentiment training data requirements.

    name

    An optional name for the model.

    description

    An optional description of the model.

    modelVersion

    An optional version string.

    workspaceID

    ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.

    versionDescription

    The description of the version.

    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 sentiment model.

    (Beta) Un-deploys the custom sentiment model with the given model ID and deletes all associated customer data, including any training data or binary artifacts.

    Declaration

    Swift

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

    Parameters

    modelID

    ID of the model.

    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 categories model.

    (Beta) Creates a custom categories model by uploading training data and associated metadata. The model begins the training and deploying process and is ready to use when the status is available.

    Declaration

    Swift

    public func createCategoriesModel(
        language: String,
        trainingData: Data,
        trainingDataContentType: String? = nil,
        name: String? = nil,
        description: String? = nil,
        modelVersion: String? = nil,
        workspaceID: String? = nil,
        versionDescription: String? = nil,
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<CategoriesModel>?, WatsonError?) -> Void)

    Parameters

    language

    The 2-letter language code of this model.

    trainingData

    Training data in JSON format. For more information, see Categories training data requirements.

    trainingDataContentType

    The content type of trainingData.

    name

    An optional name for the model.

    description

    An optional description of the model.

    modelVersion

    An optional version string.

    workspaceID

    ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.

    versionDescription

    The description of the version.

    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 categories models.

    (Beta) Returns all custom categories models associated with this service instance.

    Declaration

    Swift

    public func listCategoriesModels(
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<CategoriesModelList>?, 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 categories model details.

    (Beta) Returns the status of the categories model with the given model ID.

    Declaration

    Swift

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

    Parameters

    modelID

    ID of the model.

    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

  • Update categories model.

    (Beta) Overwrites the training data associated with this custom categories model and retrains the model. The new model replaces the current deployment.

    Declaration

    Swift

    public func updateCategoriesModel(
        modelID: String,
        language: String,
        trainingData: Data,
        trainingDataContentType: String? = nil,
        name: String? = nil,
        description: String? = nil,
        modelVersion: String? = nil,
        workspaceID: String? = nil,
        versionDescription: String? = nil,
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<CategoriesModel>?, WatsonError?) -> Void)

    Parameters

    modelID

    ID of the model.

    language

    The 2-letter language code of this model.

    trainingData

    Training data in JSON format. For more information, see Categories training data requirements.

    trainingDataContentType

    The content type of trainingData.

    name

    An optional name for the model.

    description

    An optional description of the model.

    modelVersion

    An optional version string.

    workspaceID

    ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.

    versionDescription

    The description of the version.

    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 categories model.

    (Beta) Un-deploys the custom categories model with the given model ID and deletes all associated customer data, including any training data or binary artifacts.

    Declaration

    Swift

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

    Parameters

    modelID

    ID of the model.

    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 classifications model.

    Creates a custom classifications model by uploading training data and associated metadata. The model begins the training and deploying process and is ready to use when the status is available.

    Declaration

    Swift

    public func createClassificationsModel(
        language: String,
        trainingData: Data,
        trainingDataContentType: String? = nil,
        name: String? = nil,
        description: String? = nil,
        modelVersion: String? = nil,
        workspaceID: String? = nil,
        versionDescription: String? = nil,
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<ClassificationsModel>?, WatsonError?) -> Void)

    Parameters

    language

    The 2-letter language code of this model.

    trainingData

    Training data in JSON format. For more information, see Classifications training data requirements.

    trainingDataContentType

    The content type of trainingData.

    name

    An optional name for the model.

    description

    An optional description of the model.

    modelVersion

    An optional version string.

    workspaceID

    ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.

    versionDescription

    The description of the version.

    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 classifications models.

    Returns all custom classifications models associated with this service instance.

    Declaration

    Swift

    public func listClassificationsModels(
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<ClassificationsModelList>?, 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 classifications model details.

    Returns the status of the classifications model with the given model ID.

    Declaration

    Swift

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

    Parameters

    modelID

    ID of the model.

    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

  • Update classifications model.

    Overwrites the training data associated with this custom classifications model and retrains the model. The new model replaces the current deployment.

    Declaration

    Swift

    public func updateClassificationsModel(
        modelID: String,
        language: String,
        trainingData: Data,
        trainingDataContentType: String? = nil,
        name: String? = nil,
        description: String? = nil,
        modelVersion: String? = nil,
        workspaceID: String? = nil,
        versionDescription: String? = nil,
        headers: [String: String]? = nil,
        completionHandler: @escaping (WatsonResponse<ClassificationsModel>?, WatsonError?) -> Void)

    Parameters

    modelID

    ID of the model.

    language

    The 2-letter language code of this model.

    trainingData

    Training data in JSON format. For more information, see Classifications training data requirements.

    trainingDataContentType

    The content type of trainingData.

    name

    An optional name for the model.

    description

    An optional description of the model.

    modelVersion

    An optional version string.

    workspaceID

    ID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.

    versionDescription

    The description of the version.

    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 classifications model.

    Un-deploys the custom classifications model with the given model ID and deletes all associated customer data, including any training data or binary artifacts.

    Declaration

    Swift

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

    Parameters

    modelID

    ID of the model.

    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