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
NaturalLanguageUnderstandingobject.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
NaturalLanguageUnderstandingobject.Declaration
Swift
public init(version: String, authenticator: Authenticator)Parameters
versionRelease date of the API version you want to use. Specify dates in YYYY-MM-DD format. The current version is
2021-08-01.authenticatorThe 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(features:text: html: url: clean: xpath: fallbackToRaw: returnAnalyzedText: language: limitTextCharacters: headers: completionHandler: ) 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
languageparameter, 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
featuresSpecific features to analyze the document for.
textThe plain text to analyze. One of the
text,html, orurlparameters is required.htmlThe HTML file to analyze. One of the
text,html, orurlparameters is required.urlThe webpage to analyze. One of the
text,html, orurlparameters is required.cleanSet this to
falseto disable webpage cleaning. For more information about webpage cleaning, see Analyzing webpages.xpathAn XPath query to perform on
htmlorurlinput. 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 thecleanparameter tofalse.fallbackToRawWhether to use raw HTML content if text cleaning fails.
returnAnalyzedTextWhether or not to return the analyzed text.
languageISO 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.
limitTextCharactersSets the maximum number of characters that are processed by the service.
headersA dictionary of request headers to be sent with this request.
completionHandlerA 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
headersA dictionary of request headers to be sent with this request.
completionHandlerA 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
modelIDModel ID of the model to delete.
headersA dictionary of request headers to be sent with this request.
completionHandlerA function executed when the request completes with a successful result or error
-
createSentimentModel(language:trainingData: name: description: modelVersion: workspaceID: versionDescription: headers: completionHandler: ) 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
statusisavailable.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
languageThe 2-letter language code of this model.
trainingDataTraining data in CSV format. For more information, see Sentiment training data requirements.
nameAn optional name for the model.
descriptionAn optional description of the model.
modelVersionAn optional version string.
workspaceIDID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.
versionDescriptionThe description of the version.
headersA dictionary of request headers to be sent with this request.
completionHandlerA 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
headersA dictionary of request headers to be sent with this request.
completionHandlerA 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
modelIDID of the model.
headersA dictionary of request headers to be sent with this request.
completionHandlerA function executed when the request completes with a successful result or error
-
updateSentimentModel(modelID:language: trainingData: name: description: modelVersion: workspaceID: versionDescription: headers: completionHandler: ) 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
modelIDID of the model.
languageThe 2-letter language code of this model.
trainingDataTraining data in CSV format. For more information, see Sentiment training data requirements.
nameAn optional name for the model.
descriptionAn optional description of the model.
modelVersionAn optional version string.
workspaceIDID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.
versionDescriptionThe description of the version.
headersA dictionary of request headers to be sent with this request.
completionHandlerA 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
modelIDID of the model.
headersA dictionary of request headers to be sent with this request.
completionHandlerA function executed when the request completes with a successful result or error
-
createCategoriesModel(language:trainingData: trainingDataContentType: name: description: modelVersion: workspaceID: versionDescription: headers: completionHandler: ) 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
statusisavailable.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
languageThe 2-letter language code of this model.
trainingDataTraining data in JSON format. For more information, see Categories training data requirements.
trainingDataContentTypeThe content type of trainingData.
nameAn optional name for the model.
descriptionAn optional description of the model.
modelVersionAn optional version string.
workspaceIDID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.
versionDescriptionThe description of the version.
headersA dictionary of request headers to be sent with this request.
completionHandlerA 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
headersA dictionary of request headers to be sent with this request.
completionHandlerA 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
modelIDID of the model.
headersA dictionary of request headers to be sent with this request.
completionHandlerA function executed when the request completes with a successful result or error
-
updateCategoriesModel(modelID:language: trainingData: trainingDataContentType: name: description: modelVersion: workspaceID: versionDescription: headers: completionHandler: ) 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
modelIDID of the model.
languageThe 2-letter language code of this model.
trainingDataTraining data in JSON format. For more information, see Categories training data requirements.
trainingDataContentTypeThe content type of trainingData.
nameAn optional name for the model.
descriptionAn optional description of the model.
modelVersionAn optional version string.
workspaceIDID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.
versionDescriptionThe description of the version.
headersA dictionary of request headers to be sent with this request.
completionHandlerA 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
modelIDID of the model.
headersA dictionary of request headers to be sent with this request.
completionHandlerA function executed when the request completes with a successful result or error
-
createClassificationsModel(language:trainingData: trainingDataContentType: name: description: modelVersion: workspaceID: versionDescription: headers: completionHandler: ) 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
statusisavailable.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
languageThe 2-letter language code of this model.
trainingDataTraining data in JSON format. For more information, see Classifications training data requirements.
trainingDataContentTypeThe content type of trainingData.
nameAn optional name for the model.
descriptionAn optional description of the model.
modelVersionAn optional version string.
workspaceIDID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.
versionDescriptionThe description of the version.
headersA dictionary of request headers to be sent with this request.
completionHandlerA 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
headersA dictionary of request headers to be sent with this request.
completionHandlerA 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
modelIDID of the model.
headersA dictionary of request headers to be sent with this request.
completionHandlerA function executed when the request completes with a successful result or error
-
updateClassificationsModel(modelID:language: trainingData: trainingDataContentType: name: description: modelVersion: workspaceID: versionDescription: headers: completionHandler: ) 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
modelIDID of the model.
languageThe 2-letter language code of this model.
trainingDataTraining data in JSON format. For more information, see Classifications training data requirements.
trainingDataContentTypeThe content type of trainingData.
nameAn optional name for the model.
descriptionAn optional description of the model.
modelVersionAn optional version string.
workspaceIDID of the Watson Knowledge Studio workspace that deployed this model to Natural Language Understanding.
versionDescriptionThe description of the version.
headersA dictionary of request headers to be sent with this request.
completionHandlerA 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
modelIDID of the model.
headersA dictionary of request headers to be sent with this request.
completionHandlerA function executed when the request completes with a successful result or error
View on GitHub
NaturalLanguageUnderstanding Class Reference