Natural Language Classifier

The IBM Watson Natural Language Classifier service enables developers without a background in machine learning or statistical algorithms to create natural language interfaces for their applications. The service interprets the intent behind text and returns a corresponding classification with associated confidence levels. The return value can then be used to trigger a corresponding action, such as redirecting the request or answering a question.

The following example demonstrates how to use the Natural Language Classifier service:

import NaturalLanguageClassifierV1

let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}")
let naturalLanguageClassifier = NaturalLanguageClassifier(authenticator: authenticator)
naturalLanguageClassifier.serviceURL = "{url}"

naturalLanguageClassifier.classify(classifierID: "{classifier_id}", text: "How hot will it be today?") {
  response, error in

  guard let classification = response?.result else {
    print(error?.localizedDescription ?? "unknown error")
    return
  }

  print(classification)
}

For details on all API operations, including Swift examples, see the API reference.