Introduction
IBM Watson™ 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.
This documentation describes Java SDK major version 9. For more information about how to update your code from the previous version, see the migration guide.
This documentation describes Node SDK major version 6. For more information about how to update your code from the previous version, see the migration guide.
This documentation describes Python SDK major version 5. For more information about how to update your code from the previous version, see the migration guide.
This documentation describes Ruby SDK major version 2. For more information about how to update your code from the previous version, see the migration guide.
This documentation describes .NET Standard SDK major version 5. For more information about how to update your code from the previous version, see the migration guide.
This documentation describes Go SDK major version 2. For more information about how to update your code from the previous version, see the migration guide.
This documentation describes Swift SDK major version 4. For more information about how to update your code from the previous version, see the migration guide.
This documentation describes Unity SDK major version 5. For more information about how to update your code from the previous version, see the migration guide.
The IBM Watson Unity SDK has the following requirements.
- The SDK requires Unity version 2018.2 or later to support Transport Layer Security (TLS) 1.2.
- Set the project settings for both the Scripting Runtime Version and the Api Compatibility Level to
.NET 4.x Equivalent
. - For more information, see TLS 1.0 support.
- Set the project settings for both the Scripting Runtime Version and the Api Compatibility Level to
- The SDK doesn't support the WebGL projects. Change your build settings to any platform except
WebGL
.
For more information about how to install and configure the SDK and SDK Core, see https://github.com/watson-developer-cloud/unity-sdk.
The code examples on this tab use the client library that is provided for Java.
Maven
<dependency>
<groupId>com.ibm.watson</groupId>
<artifactId>ibm-watson</artifactId>
<version>9.0.2</version>
</dependency>
Gradle
compile 'com.ibm.watson:ibm-watson:9.0.2'
GitHub
The code examples on this tab use the client library that is provided for Node.js.
Installation
npm install ibm-watson@^6.0.4
GitHub
The code examples on this tab use the client library that is provided for Python.
Installation
pip install --upgrade "ibm-watson>=5.1.0"
GitHub
The code examples on this tab use the client library that is provided for Ruby.
Installation
gem install ibm_watson
GitHub
The code examples on this tab use the client library that is provided for Go.
go get -u github.com/watson-developer-cloud/go-sdk@v2.0.3
GitHub
The code examples on this tab use the client library that is provided for Swift.
Cocoapods
pod 'IBMWatsonNaturalLanguageClassifierV1', '~> 4.1.0'
Carthage
github "watson-developer-cloud/swift-sdk" ~> 4.1.0
Swift Package Manager
.package(url: "https://github.com/watson-developer-cloud/swift-sdk", from: "4.1.0")
GitHub
The code examples on this tab use the client library that is provided for .NET Standard.
Package Manager
Install-Package IBM.Watson.NaturalLanguageClassifier.v1 -Version 5.1.0
.NET CLI
dotnet add package IBM.Watson.NaturalLanguageClassifier.v1 --version 5.1.0
PackageReference
<PackageReference Include="IBM.Watson.NaturalLanguageClassifier.v1" Version="5.1.0" />
GitHub
The code examples on this tab use the client library that is provided for Unity.
GitHub
Authentication
You authenticate to the API by using IBM Cloud Identity and Access Management (IAM).
You can pass either a bearer token in an authorization header or an API key. Tokens support authenticated requests without embedding service credentials in every call. API keys use basic authentication. For more information, see Authenticating to Watson services.
- For testing and development, you can pass an API key directly.
- For production use, unless you use the Watson SDKs, use an IAM token.
If you pass in an API key, use apikey
for the username and the value of the API key as the password. For example, if the API key is f5sAznhrKQyvBFFaZbtF60m5tzLbqWhyALQawBg5TjRI
in the service credentials, include the credentials in your call like this:
curl -u "apikey:f5sAznhrKQyvBFFaZbtF60m5tzLbqWhyALQawBg5TjRI"
For IBM Cloud instances, the SDK provides initialization methods for each form of authentication.
- Use the API key to have the SDK manage the lifecycle of the access token. The SDK requests an access token, ensures that the access token is valid, and refreshes it if necessary.
- Use the access token to manage the lifecycle yourself. You must periodically refresh the token.
For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.For more information, see IAM authentication with the SDK.
Replace {apikey}
and {url}
with your service credentials.
curl -X {request_method} -u "apikey:{apikey}" "{url}/v1/{method}"
SDK managing the IAM token. Replace {apikey}
and {url}
.
IamAuthenticator authenticator = new IamAuthenticator("{apikey}");
NaturalLanguageClassifier naturalLanguageClassifier = new NaturalLanguageClassifier(authenticator);
naturalLanguageClassifier.setServiceUrl("{url}");
SDK managing the IAM token. Replace {apikey}
and {url}
.
const NaturalLanguageClassifierV1 = require('ibm-watson/natural-language-classifier/v1');
const { IamAuthenticator } = require('ibm-watson/auth');
const naturalLanguageClassifier = new NaturalLanguageClassifierV1({
authenticator: new IamAuthenticator({
apikey: '{apikey}',
}),
serviceUrl: '{url}',
});
SDK managing the IAM token. Replace {apikey}
and {url}
.
from ibm_watson import NaturalLanguageClassifierV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('{apikey}')
natural_language_classifier = NaturalLanguageClassifierV1(
authenticator=authenticator
)
natural_language_classifier.set_service_url('{url}')
SDK managing the IAM token. Replace {apikey}
and {url}
.
require "ibm_watson/authenticators"
require "ibm_watson/natural_language_classifier_v1"
include IBMWatson
authenticator = Authenticators::IamAuthenticator.new(
apikey: "{apikey}"
)
natural_language_classifier = NaturalLanguageClassifierV1.new(
authenticator: authenticator
)
natural_language_classifier.service_url = "{url}"
SDK managing the IAM token. Replace {apikey}
and {url}
.
import (
"github.com/IBM/go-sdk-core/core"
"github.com/watson-developer-cloud/go-sdk/naturallanguageclassifierv1"
)
func main() {
authenticator := &core.IamAuthenticator{
ApiKey: "{apikey}",
}
options := &naturallanguageclassifierv1.NaturalLanguageClassifierV1Options{
Authenticator: authenticator,
}
naturalLanguageClassifier, naturalLanguageClassifierErr := naturallanguageclassifierv1.NewNaturalLanguageClassifierV1(options)
if naturalLanguageClassifierErr != nil {
panic(naturalLanguageClassifierErr)
}
naturalLanguageClassifier.SetServiceURL("{url}")
}
SDK managing the IAM token. Replace {apikey}
and {url}
.
let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}")
let naturalLanguageClassifier = NaturalLanguageClassifier(authenticator: authenticator)
naturalLanguageClassifier.serviceURL = "{url}"
SDK managing the IAM token. Replace {apikey}
and {url}
.
IamAuthenticator authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
NaturalLanguageClassifierService naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator);
naturalLanguageClassifier.SetServiceUrl("{url}");
SDK managing the IAM token. Replace {apikey}
and {url}
.
var authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
while (!authenticator.CanAuthenticate())
yield return null;
var naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator);
naturalLanguageClassifier.SetServiceUrl("{url}");
Access between services
Your application might use more than one Watson service. You can grant access between services and you can grant access to more than one service for your applications.
For IBM Cloud services, the method to grant access between Watson services varies depending on the type of API key. For more information, see IAM access.
- To grant access between IBM Cloud services, create an authorization between the services. For more information, see Granting access between services.
- To grant access to your services by applications without using user credentials, create a service ID, add an API key, and assign access policies. For more information, see Creating and working with service IDs.
When you give a user ID access to multiple services, use an endpoint URL that includes the service instance ID (for example, https://api.us-south.natural-language-classifier.watson.cloud.ibm.com/instances/6bbda3b3-d572-45e1-8c54-22d6ed9e52c2
). You can find the instance ID in two places:
- By clicking the service instance row in the Resource list. The instance ID is the GUID in the details pane.
By clicking the name of the service instance in the list and looking at the credentials URL.
If you don't see the instance ID in the URL, the credentials predate service IDs. Add new credentials from the Service credentials page and use those credentials.
IBM Cloud URLs
The base URLs come from the service instance. To find the URL, view the service credentials by clicking the name of the service in the Resource list. Use the value of the URL. Add the method to form the complete API endpoint for your request.
The following example URL represents a Natural Language Classifier instance that is hosted in Washington DC:
https://api.us-east.natural-language-classifier.watson.cloud.ibm.com/instances/6bbda3b3-d572-45e1-8c54-22d6ed9e52c2
The following URLs represent the base URLs for Natural Language Classifier. When you call the API, use the URL that corresponds to the location of your service instance.
- Dallas:
https://api.us-south.natural-language-classifier.watson.cloud.ibm.com
- Washington DC:
https://api.us-east.natural-language-classifier.watson.cloud.ibm.com
- Frankfurt:
https://api.eu-de.natural-language-classifier.watson.cloud.ibm.com
- Tokyo:
https://api.jp-tok.natural-language-classifier.watson.cloud.ibm.com
- Seoul:
https://api.kr-seo.natural-language-classifier.watson.cloud.ibm.com
Set the correct service URL by calling the setServiceUrl()
method of the service instance.
Set the correct service URL by specifying the serviceUrl
parameter when you create the service instance.
Set the correct service URL by calling the set_service_url()
method of the service instance.
Set the correct service URL by specifying the service_url
property of the service instance.
Set the correct service URL by calling the SetServiceURL()
method of the service instance.
Set the correct service URL by setting the serviceURL
property of the service instance.
Set the correct service URL by calling the SetServiceUrl()
method of the service instance.
Set the correct service URL by calling the SetServiceUrl()
method of the service instance.
Dallas API endpoint example for services managed on IBM Cloud
curl -X {request_method} -u "apikey:{apikey}" "https://api.us-south.natural-language-classifier.watson.cloud.ibm.com/instances/{instance_id}"
Your service instance might not use this URL
Default URL
https://api.us-south.natural-language-classifier.watson.cloud.ibm.com
Example for the Washington DC location
IamAuthenticator authenticator = new IamAuthenticator("{apikey}");
NaturalLanguageClassifier naturalLanguageClassifier = new NaturalLanguageClassifier(authenticator);
naturalLanguageClassifier.setServiceUrl("https://api.us-east.natural-language-classifier.watson.cloud.ibm.com");
Default URL
https://api.us-south.natural-language-classifier.watson.cloud.ibm.com
Example for the Washington DC location
const NaturalLanguageClassifierV1 = require('ibm-watson/natural-language-classifier/v1');
const { IamAuthenticator } = require('ibm-watson/auth');
const naturalLanguageClassifier = new NaturalLanguageClassifierV1({
authenticator: new IamAuthenticator({
apikey: '{apikey}',
}),
serviceUrl: 'https://api.us-east.natural-language-classifier.watson.cloud.ibm.com',
});
Default URL
https://api.us-south.natural-language-classifier.watson.cloud.ibm.com
Example for the Washington DC location
from ibm_watson import NaturalLanguageClassifierV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('{apikey}')
natural_language_classifier = NaturalLanguageClassifierV1(
authenticator=authenticator
)
natural_language_classifier.set_service_url('https://api.us-east.natural-language-classifier.watson.cloud.ibm.com')
Default URL
https://api.us-south.natural-language-classifier.watson.cloud.ibm.com
Example for the Washington DC location
require "ibm_watson/authenticators"
require "ibm_watson/natural_language_classifier_v1"
include IBMWatson
authenticator = Authenticators::IamAuthenticator.new(
apikey: "{apikey}"
)
natural_language_classifier = NaturalLanguageClassifierV1.new(
authenticator: authenticator
)
natural_language_classifier.service_url = "https://api.us-east.natural-language-classifier.watson.cloud.ibm.com"
Default URL
https://api.us-south.natural-language-classifier.watson.cloud.ibm.com
Example for the Washington DC location
naturalLanguageClassifier, naturalLanguageClassifierErr := naturallanguageclassifierv1.NewNaturalLanguageClassifierV1(options)
if naturalLanguageClassifierErr != nil {
panic(naturalLanguageClassifierErr)
}
naturalLanguageClassifier.SetServiceURL("https://api.us-east.natural-language-classifier.watson.cloud.ibm.com")
Default URL
https://api.us-south.natural-language-classifier.watson.cloud.ibm.com
Example for the Washington DC location
let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}")
let naturalLanguageClassifier = NaturalLanguageClassifier(authenticator: authenticator)
naturalLanguageClassifier.serviceURL = "https://api.us-east.natural-language-classifier.watson.cloud.ibm.com"
Default URL
https://api.us-south.natural-language-classifier.watson.cloud.ibm.com
Example for the Washington DC location
IamAuthenticator authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
NaturalLanguageClassifierService naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator);
naturalLanguageClassifier.SetServiceUrl("https://api.us-east.natural-language-classifier.watson.cloud.ibm.com");
Default URL
https://api.us-south.natural-language-classifier.watson.cloud.ibm.com
Example for the Washington DC location
var authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
while (!authenticator.CanAuthenticate())
yield return null;
var naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator);
naturalLanguageClassifier.SetServiceUrl("https://api.us-east.natural-language-classifier.watson.cloud.ibm.com");
Disabling SSL verification
All Watson services use Secure Sockets Layer (SSL) (or Transport Layer Security (TLS)) for secure connections between the client and server. The connection is verified against the local certificate store to ensure authentication, integrity, and confidentiality.
If you use a self-signed certificate, you need to disable SSL verification to make a successful connection.
Enabling SSL verification is highly recommended. Disabling SSL jeopardizes the security of the connection and data. Disable SSL only if necessary, and take steps to enable SSL as soon as possible.
To disable SSL verification for a curl request, use the --insecure
(-k
) option with the request.
To disable SSL verification, create an HttpConfigOptions
object and set the disableSslVerification
property to true
. Then, pass the object to the service instance by using the configureClient
method.
To disable SSL verification, set the disableSslVerification
parameter to true
when you create the service instance.
To disable SSL verification, specify True
on the set_disable_ssl_verification
method for the service instance.
To disable SSL verification, set the disable_ssl_verification
parameter to true
in the configure_http_client()
method for the service instance.
To disable SSL verification, call the DisableSSLVerification
method on the service instance.
To disable SSL verification, call the disableSSLVerification()
method on the service instance. You cannot disable SSL verification on Linux.
To disable SSL verification, set the DisableSslVerification
method to true
on the service instance.
To disable SSL verification, set the DisableSslVerification
method to true
on the service instance.
Example to disable SSL verification. Replace {apikey}
and {url}
with your service credentials.
curl -k -X {request_method} -u "apikey:{apikey}" "{url}/{method}"
Example to disable SSL verification
IamAuthenticator authenticator = new IamAuthenticator("{apikey}");
NaturalLanguageClassifier naturalLanguageClassifier = new NaturalLanguageClassifier(authenticator);
naturalLanguageClassifier.setServiceUrl("{url}");
HttpConfigOptions configOptions = new HttpConfigOptions.Builder()
.disableSslVerification(true)
.build();
naturalLanguageClassifier.configureClient(configOptions);
Example to disable SSL verification
const NaturalLanguageClassifierV1 = require('ibm-watson/natural-language-classifier/v1');
const { IamAuthenticator } = require('ibm-watson/auth');
const naturalLanguageClassifier = new NaturalLanguageClassifierV1({
authenticator: new IamAuthenticator({
apikey: '{apikey}',
}),
serviceUrl: '{url}',
disableSslVerification: true,
});
Example to disable SSL verification
from ibm_watson import NaturalLanguageClassifierV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('{apikey}')
natural_language_classifier = NaturalLanguageClassifierV1(
authenticator=authenticator
)
natural_language_classifier.set_service_url('{url}')
natural_language_classifier.set_disable_ssl_verification(True)
Example to disable SSL verification
require "ibm_watson/authenticators"
require "ibm_watson/natural_language_classifier_v1"
include IBMWatson
authenticator = Authenticators::IamAuthenticator.new(
apikey: "{apikey}"
)
natural_language_classifier = NaturalLanguageClassifierV1.new(
authenticator: authenticator
)
natural_language_classifier.service_url = "{url}"
natural_language_classifier.configure_http_client(disable_ssl_verification: true)
Example to disable SSL verification
naturalLanguageClassifier, naturalLanguageClassifierErr := naturallanguageclassifierv1.NewNaturalLanguageClassifierV1(options)
if naturalLanguageClassifierErr != nil {
panic(naturalLanguageClassifierErr)
}
naturalLanguageClassifier.SetServiceURL("{url}")
naturalLanguageClassifier.DisableSSLVerification()
Example to disable SSL verification
let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}")
let naturalLanguageClassifier = NaturalLanguageClassifier(authenticator: authenticator)
naturalLanguageClassifier.serviceURL = "{url}"
naturalLanguageClassifier.disableSSLVerification()
Example to disable SSL verification
IamAuthenticator authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
NaturalLanguageClassifierService naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator);
naturalLanguageClassifier.SetServiceUrl("{url}");
naturalLanguageClassifier.DisableSslVerification(true);
Example to disable SSL verification
var authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
while (!authenticator.CanAuthenticate())
yield return null;
var naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator);
naturalLanguageClassifier.SetServiceUrl("{url}");
naturalLanguageClassifier.DisableSslVerification = true;
Error handling
Natural Language Classifier uses standard HTTP response codes to indicate whether a method completed successfully. HTTP response codes in the 2xx range indicate success. A response in the 4xx range is some sort of failure, and a response in the 5xx range usually indicates an internal system error that cannot be resolved by the user. Response codes are listed with the method.
ErrorResponse
Name | Description |
---|---|
code integer |
The HTTP response code. |
error string |
General description of an error. |
The Java SDK generates an exception for any unsuccessful method invocation. All methods that accept an argument can also throw an IllegalArgumentException
.
Exception | Description |
---|---|
IllegalArgumentException | An invalid argument was passed to the method. |
When the Java SDK receives an error response from the Natural Language Classifier service, it generates an exception from the com.ibm.watson.developer_cloud.service.exception
package. All service exceptions contain the following fields.
Field | Description |
---|---|
statusCode | The HTTP response code that is returned. |
message | A message that describes the error. |
When the Node SDK receives an error response from the Natural Language Classifier service, it creates an Error
object with information that describes the error that occurred. This error object is passed as the first parameter to the callback function for the method. The contents of the error object are as shown in the following table.
Error
Field | Description |
---|---|
code | The HTTP response code that is returned. |
message | A message that describes the error. |
The Python SDK generates an exception for any unsuccessful method invocation. When the Python SDK receives an error response from the Natural Language Classifier service, it generates an ApiException
with the following fields.
Field | Description |
---|---|
code | The HTTP response code that is returned. |
message | A message that describes the error. |
info | A dictionary of additional information about the error. |
When the Ruby SDK receives an error response from the Natural Language Classifier service, it generates an ApiException
with the following fields.
Field | Description |
---|---|
code | The HTTP response code that is returned. |
message | A message that describes the error. |
info | A dictionary of additional information about the error. |
The Go SDK generates an error for any unsuccessful service instantiation and method invocation. You can check for the error immediately. The contents of the error object are as shown in the following table.
Error
Field | Description |
---|---|
code | The HTTP response code that is returned. |
message | A message that describes the error. |
The Swift SDK returns a WatsonError
in the completionHandler
any unsuccessful method invocation. This error type is an enum that conforms to LocalizedError
and contains an errorDescription
property that returns an error message. Some of the WatsonError
cases contain associated values that reveal more information about the error.
Field | Description |
---|---|
errorDescription | A message that describes the error. |
When the .NET Standard SDK receives an error response from the Natural Language Classifier service, it generates a ServiceResponseException
with the following fields.
Field | Description |
---|---|
Message | A message that describes the error. |
CodeDescription | The HTTP response code that is returned. |
When the Unity SDK receives an error response from the Natural Language Classifier service, it generates an IBMError
with the following fields.
Field | Description |
---|---|
Url | The URL that generated the error. |
StatusCode | The HTTP response code returned. |
ErrorMessage | A message that describes the error. |
Response | The contents of the response from the server. |
ResponseHeaders | A dictionary of headers returned by the request. |
Example error handling
try {
// Invoke a method
} catch (NotFoundException e) {
// Handle Not Found (404) exception
} catch (RequestTooLargeException e) {
// Handle Request Too Large (413) exception
} catch (ServiceResponseException e) {
// Base class for all exceptions caused by error responses from the service
System.out.println("Service returned status code "
+ e.getStatusCode() + ": " + e.getMessage());
}
Example error handling
naturalLanguageClassifier.method(params)
.catch(err => {
console.log('error:', err);
});
Example error handling
from ibm_watson import ApiException
try:
# Invoke a method
except ApiException as ex:
print "Method failed with status code " + str(ex.code) + ": " + ex.message
Example error handling
require "ibm_watson"
begin
# Invoke a method
rescue IBMWatson::ApiException => ex
print "Method failed with status code #{ex.code}: #{ex.error}"
end
Example error handling
import "github.com/watson-developer-cloud/go-sdk/naturallanguageclassifierv1"
// Instantiate a service
naturalLanguageClassifier, naturalLanguageClassifierErr := naturallanguageclassifierv1.NewNaturalLanguageClassifierV1(options)
// Check for errors
if naturalLanguageClassifierErr != nil {
panic(naturalLanguageClassifierErr)
}
// Call a method
result, response, responseErr := naturalLanguageClassifier.MethodName(&methodOptions)
// Check for errors
if responseErr != nil {
panic(responseErr)
}
Example error handling
naturalLanguageClassifier.method() {
response, error in
if let error = error {
switch error {
case let .http(statusCode, message, metadata):
switch statusCode {
case .some(404):
// Handle Not Found (404) exception
print("Not found")
case .some(413):
// Handle Request Too Large (413) exception
print("Payload too large")
default:
if let statusCode = statusCode {
print("Error - code: \(statusCode), \(message ?? "")")
}
}
default:
print(error.localizedDescription)
}
return
}
guard let result = response?.result else {
print(error?.localizedDescription ?? "unknown error")
return
}
print(result)
}
Example error handling
try
{
// Invoke a method
}
catch(ServiceResponseException e)
{
Console.WriteLine("Error: " + e.Message);
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
}
Example error handling
// Invoke a method
naturalLanguageClassifier.MethodName(Callback, Parameters);
// Check for errors
private void Callback(DetailedResponse<ExampleResponse> response, IBMError error)
{
if (error == null)
{
Log.Debug("ExampleCallback", "Response received: {0}", response.Response);
}
else
{
Log.Debug("ExampleCallback", "Error received: {0}, {1}, {3}", error.StatusCode, error.ErrorMessage, error.Response);
}
}
Additional headers
Some Watson services accept special parameters in headers that are passed with the request.
You can pass request header parameters in all requests or in a single request to the service.
To pass a request header, use the --header
(-H
) option with a curl request.
To pass header parameters with every request, use the setDefaultHeaders
method of the service object. See Data collection for an example use of this method.
To pass header parameters in a single request, use the addHeader
method as a modifier on the request before you execute it.
To pass header parameters with every request, specify the headers
parameter when you create the service object. See Data collection for an example use of this method.
To pass header parameters in a single request, use the headers
method as a modifier on the request before you execute it.
To pass header parameters with every request, specify the set_default_headers
method of the service object. See Data collection for an example use of this method.
To pass header parameters in a single request, include headers
as a dict
in the request.
To pass header parameters with every request, specify the add_default_headers
method of the service object. See Data collection for an example use of this method.
To pass header parameters in a single request, specify the headers
method as a chainable method in the request.
To pass header parameters with every request, specify the SetDefaultHeaders
method of the service object. See Data collection for an example use of this method.
To pass header parameters in a single request, specify the Headers
as a map
in the request.
To pass header parameters with every request, add them to the defaultHeaders
property of the service object. See Data collection for an example use of this method.
To pass header parameters in a single request, pass the headers
parameter to the request method.
To pass header parameters in a single request, use the WithHeader()
method as a modifier on the request before you execute it. See Data collection for an example use of this method.
To pass header parameters in a single request, use the WithHeader()
method as a modifier on the request before you execute it.
Example header parameter in a request
curl -X {request_method} -H "Request-Header: {header_value}" "{url}/v1/{method}"
Example header parameter in a request
ReturnType returnValue = naturalLanguageClassifier.methodName(parameters)
.addHeader("Custom-Header", "{header_value}")
.execute();
Example header parameter in a request
const parameters = {
{parameters}
};
naturalLanguageClassifier.methodName(
parameters,
headers: {
'Custom-Header': '{header_value}'
})
.then(result => {
console.log(response);
})
.catch(err => {
console.log('error:', err);
});
Example header parameter in a request
response = natural_language_classifier.methodName(
parameters,
headers = {
'Custom-Header': '{header_value}'
})
Example header parameter in a request
response = natural_language_classifier.headers(
"Custom-Header" => "{header_value}"
).methodName(parameters)
Example header parameter in a request
result, response, responseErr := naturalLanguageClassifier.MethodName(
&methodOptions{
Headers: map[string]string{
"Accept": "application/json",
},
},
)
Example header parameter in a request
let customHeader: [String: String] = ["Custom-Header": "{header_value}"]
naturalLanguageClassifier.methodName(parameters, headers: customHeader) {
response, error in
}
Example header parameter in a request
IamAuthenticator authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
NaturalLanguageClassifierService naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator);
naturalLanguageClassifier.SetServiceUrl("{url}");
naturalLanguageClassifier.WithHeader("Custom-Header", "header_value");
Example header parameter in a request
var authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
while (!authenticator.CanAuthenticate())
yield return null;
var naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator);
naturalLanguageClassifier.SetServiceUrl("{url}");
naturalLanguageClassifier.WithHeader("Custom-Header", "header_value");
Response details
The Natural Language Classifier service might return information to the application in response headers.
To access all response headers that the service returns, include the --include
(-i
) option with a curl request. To see detailed response data for the request, including request headers, response headers, and extra debugging information, include the --verbose
(-v
) option with the request.
Example request to access response headers
curl -X {request_method} {authentication_method} --include "{url}/v1/{method}"
To access information in the response headers, use one of the request methods that returns details with the response: executeWithDetails()
, enqueueWithDetails()
, or rxWithDetails()
. These methods return a Response<T>
object, where T
is the expected response model. Use the getResult()
method to access the response object for the method, and use the getHeaders()
method to access information in response headers.
Example request to access response headers
Response<ReturnType> response = naturalLanguageClassifier.methodName(parameters)
.executeWithDetails();
// Access response from methodName
ReturnType returnValue = response.getResult();
// Access information in response headers
Headers responseHeaders = response.getHeaders();
All response data is available in the Response<T>
object that is returned by each method. To access information in the response
object, use the following properties.
Property | Description |
---|---|
result |
Returns the response for the service-specific method. |
headers |
Returns the response header information. |
status |
Returns the HTTP status code. |
Example request to access response headers
naturalLanguageClassifier.methodName(parameters)
.then(response => {
console.log(response.headers);
})
.catch(err => {
console.log('error:', err);
});
The return value from all service methods is a DetailedResponse
object. To access information in the result object or response headers, use the following methods.
DetailedResponse
Method | Description |
---|---|
get_result() |
Returns the response for the service-specific method. |
get_headers() |
Returns the response header information. |
get_status_code() |
Returns the HTTP status code. |
Example request to access response headers
natural_language_classifier.set_detailed_response(True)
response = natural_language_classifier.methodName(parameters)
# Access response from methodName
print(json.dumps(response.get_result(), indent=2))
# Access information in response headers
print(response.get_headers())
# Access HTTP response status
print(response.get_status_code())
The return value from all service methods is a DetailedResponse
object. To access information in the response
object, use the following properties.
DetailedResponse
Property | Description |
---|---|
result |
Returns the response for the service-specific method. |
headers |
Returns the response header information. |
status |
Returns the HTTP status code. |
Example request to access response headers
response = natural_language_classifier.methodName(parameters)
# Access response from methodName
print response.result
# Access information in response headers
print response.headers
# Access HTTP response status
print response.status
The return value from all service methods is a DetailedResponse
object. To access information in the response
object or response headers, use the following methods.
DetailedResponse
Method | Description |
---|---|
GetResult() |
Returns the response for the service-specific method. |
GetHeaders() |
Returns the response header information. |
GetStatusCode() |
Returns the HTTP status code. |
Example request to access response headers
import (
"github.com/IBM/go-sdk-core/core"
"github.com/watson-developer-cloud/go-sdk/naturallanguageclassifierv1"
)
result, response, responseErr := naturalLanguageClassifier.MethodName(
&methodOptions{})
// Access result
core.PrettyPrint(response.GetResult(), "Result ")
// Access response headers
core.PrettyPrint(response.GetHeaders(), "Headers ")
// Access status code
core.PrettyPrint(response.GetStatusCode(), "Status Code ")
All response data is available in the WatsonResponse<T>
object that is returned in each method's completionHandler
.
Example request to access response headers
naturalLanguageClassifier.methodName(parameters) {
response, error in
guard let result = response?.result else {
print(error?.localizedDescription ?? "unknown error")
return
}
print(result) // The data returned by the service
print(response?.statusCode)
print(response?.headers)
}
The response contains fields for response headers, response JSON, and the status code.
DetailedResponse
Property | Description |
---|---|
Result |
Returns the result for the service-specific method. |
Response |
Returns the raw JSON response for the service-specific method. |
Headers |
Returns the response header information. |
StatusCode |
Returns the HTTP status code. |
Example request to access response headers
var results = naturalLanguageClassifier.MethodName(parameters);
var result = results.Result; // The result object
var responseHeaders = results.Headers; // The response headers
var responseJson = results.Response; // The raw response JSON
var statusCode = results.StatusCode; // The response status code
The response contains fields for response headers, response JSON, and the status code.
DetailedResponse
Property | Description |
---|---|
Result |
Returns the result for the service-specific method. |
Response |
Returns the raw JSON response for the service-specific method. |
Headers |
Returns the response header information. |
StatusCode |
Returns the HTTP status code. |
Example request to access response headers
private void Example()
{
naturalLanguageClassifier.MethodName(Callback, Parameters);
}
private void Callback(DetailedResponse<ResponseType> response, IBMError error)
{
var result = response.Result; // The result object
var responseHeaders = response.Headers; // The response headers
var responseJson = reresponsesults.Response; // The raw response JSON
var statusCode = response.StatusCode; // The response status code
}
Data collection
By default, Natural Language Classifier service instances that are not part of Premium plans log requests and their results. Logging is done only to improve the services for future users. The logged data is not shared or made public. Logging is disabled for services that are part of Premium plans.
To prevent IBM usage of your data for an API request, set the X-Watson-Learning-Opt-Out header parameter to true
.
You must set the header on each request that you do not want IBM to access for general service improvements.
You can set the header by using the setDefaultHeaders
method of the service object.
You can set the header by using the headers
parameter when you create the service object.
You can set the header by using the set_default_headers
method of the service object.
You can set the header by using the add_default_headers
method of the service object.
You can set the header by using the SetDefaultHeaders
method of the service object.
You can set the header by adding it to the defaultHeaders
property of the service object.
You can set the header by using the WithHeader()
method of the service object.
Example request
curl -u "apikey:{apikey}" -H "X-Watson-Learning-Opt-Out: true" "{url}/{method}"
Example request
Map<String, String> headers = new HashMap<String, String>();
headers.put("X-Watson-Learning-Opt-Out", "true");
naturalLanguageClassifier.setDefaultHeaders(headers);
Example request
const NaturalLanguageClassifierV1 = require('ibm-watson/natural-language-classifier/v1');
const { IamAuthenticator } = require('ibm-watson/auth');
const naturalLanguageClassifier = new NaturalLanguageClassifierV1({
authenticator: new IamAuthenticator({
apikey: '{apikey}',
}),
serviceUrl: '{url}',
headers: {
'X-Watson-Learning-Opt-Out': 'true'
}
});
Example request
natural_language_classifier.set_default_headers({'x-watson-learning-opt-out': "true"})
Example request
natural_language_classifier.add_default_headers(headers: {"x-watson-learning-opt-out" => "true"})
Example request
import "net/http"
headers := http.Header{}
headers.Add("x-watson-learning-opt-out", "true")
naturalLanguageClassifier.SetDefaultHeaders(headers)
Example request
naturalLanguageClassifier.defaultHeaders["X-Watson-Learning-Opt-Out"] = "true"
Example request
IamAuthenticator authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
NaturalLanguageClassifierService naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator);
naturalLanguageClassifier.SetServiceUrl("{url}");
naturalLanguageClassifier.WithHeader("X-Watson-Learning-Opt-Out", "true");
Example request
var authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
while (!authenticator.CanAuthenticate())
yield return null;
var naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator);
naturalLanguageClassifier.SetServiceUrl("{url}");
naturalLanguageClassifier.WithHeader("X-Watson-Learning-Opt-Out", "true");
Synchronous and asynchronous requests
The Java SDK supports both synchronous (blocking) and asynchronous (non-blocking) execution of service methods. All service methods implement the ServiceCall interface.
- To call a method synchronously, use the
execute
method of theServiceCall
interface. You can call theexecute
method directly from an instance of the service. - To call a method asynchronously, use the
enqueue
method of theServiceCall
interface to receive a callback when the response arrives. The ServiceCallback interface of the method's argument providesonResponse
andonFailure
methods that you override to handle the callback.
The Ruby SDK supports both synchronous (blocking) and asynchronous (non-blocking) execution of service methods. All service methods implement the Concurrent::Async module. When you use the synchronous or asynchronous methods, an IVar object is returned. You access the DetailedResponse
object by calling ivar_object.value
.
For more information about the Ivar object, see the IVar class docs.
To call a method synchronously, either call the method directly or use the
.await
chainable method of theConcurrent::Async
module.Calling a method directly (without
.await
) returns aDetailedResponse
object.- To call a method asynchronously, use the
.async
chainable method of theConcurrent::Async
module.
You can call the .await
and .async
methods directly from an instance of the service.
Example synchronous request
ReturnType returnValue = naturalLanguageClassifier.method(parameters).execute();
Example asynchronous request
naturalLanguageClassifier.method(parameters).enqueue(new ServiceCallback<ReturnType>() {
@Override public void onResponse(ReturnType response) {
. . .
}
@Override public void onFailure(Exception e) {
. . .
}
});
Example synchronous request
response = natural_language_classifier.method_name(parameters)
or
response = natural_language_classifier.await.method_name(parameters)
Example asynchronous request
response = natural_language_classifier.async.method_name(parameters)
Related information
- Natural Language Classifier docs
- Release notes
- Javadoc for NaturalLanguageClassifier
- Javadoc for sdk-core
Methods
Classify a phrase (GET)
The status must be Available
before you can use the classifier to classify calls.
GET /v1/classifiers/{classifier_id}/classify
Rate limit
This operation is limited to 80 requests per second.
Request
Path Parameters
Classifier ID to use.
Query Parameters
Phrase to classify. The maximum length is 2048 characters.
Constraints: length ≤ 2048
curl -G -u "apikey:{apikey}" "{url}/v1/classifiers/10D41B-nlc-1/classify?text=How%20hot%20will%20it%20be%20today%3F"
var authenticator = new IamAuthenticator( apikey: "{apikey}" ); while (!authenticator.CanAuthenticate()) yield return null; var naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator); naturalLanguageClassifier.SetServiceUrl("{url}"); Classifier getClassifierResponse = null; service.GetClassifier( callback: (DetailedResponse<Classifier> response, IBMError error) => { Log.Debug("NaturalLanguageClassifierServiceV1", "GetClassifier result: {0}", response.Response); getClassifierResponse = response.Result; }, classifierId: "10D41B-nlc-1" ); while (getClassifierResponse == null) yield return null;
Response
Response from the classifier for a phrase.
Unique identifier for this classifier.
Link to the classifier.
The submitted phrase.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
Status Code
OK
Bad request. Likely caused by a classifier status other than
Available
or by a missingtext
parameter.The classifier does not exist or is not available to the user.
Too Many Requests. The rate limit is exceeded for this service instance.
{ "classifier_id": "10D41B-nlc-1", "url": "{url}/v1/classifiers/10D41B-nlc-1/classify?text=How%20hot%20wil/10D41B-nlc-1", "text": "How hot will it be today?", "top_class": "temperature", "classes": [ { "class_name": "temperature", "confidence": 0.9998201258549781 }, { "class_name": "conditions", "confidence": 0.00017987414502176904 } ] }
{ "code": "429", "error": "Error: Too Many Requests" }
Classify a phrase
Returns label information for the input. The status must be Available
before you can use the classifier to classify text.
Returns label information for the input. The status must be Available
before you can use the classifier to classify text.
Returns label information for the input. The status must be Available
before you can use the classifier to classify text.
Returns label information for the input. The status must be Available
before you can use the classifier to classify text.
Returns label information for the input. The status must be Available
before you can use the classifier to classify text.
Returns label information for the input. The status must be Available
before you can use the classifier to classify text.
Returns label information for the input. The status must be Available
before you can use the classifier to classify text.
Returns label information for the input. The status must be Available
before you can use the classifier to classify text.
Returns label information for the input. The status must be Available
before you can use the classifier to classify text.
POST /v1/classifiers/{classifier_id}/classify
(naturalLanguageClassifier *NaturalLanguageClassifierV1) Classify(classifyOptions *ClassifyOptions) (result *Classification, response *core.DetailedResponse, err error)
(naturalLanguageClassifier *NaturalLanguageClassifierV1) ClassifyWithContext(ctx context.Context, classifyOptions *ClassifyOptions) (result *Classification, response *core.DetailedResponse, err error)
ServiceCall<Classification> classify(ClassifyOptions classifyOptions)
classify(params)
classify(self,
classifier_id: str,
text: str,
**kwargs
) -> DetailedResponse
classify(classifier_id:, text:)
func classify(
classifierID: String,
text: String,
headers: [String: String]? = nil,
completionHandler: @escaping (WatsonResponse<Classification>?, WatsonError?) -> Void)
Classify(string classifierId, string text)
Classify(Callback<Classification> callback, string classifierId, string text)
Rate limit
This operation is limited to 80 requests per second.
Request
Instantiate the ClassifyOptions
struct and set the fields to provide parameter values for the Classify
method.
Use the ClassifyOptions.Builder
to create a ClassifyOptions
object that contains the parameter values for the classify
method.
Path Parameters
Classifier ID to use.
Phrase to classify.
The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
WithContext method only
A context.Context instance that you can use to specify a timeout for the operation or to cancel an in-flight request.
The Classify options.
Classifier ID to use.
The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
The classify options.
Classifier ID to use.
The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
parameters
Classifier ID to use.
The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
parameters
Classifier ID to use.
The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
parameters
Classifier ID to use.
The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
parameters
Classifier ID to use.
The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
parameters
Classifier ID to use.
The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
parameters
Classifier ID to use.
The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
curl -X POST -u "apikey:{apikey}" -H "Content-Type:application/json" -d "{\"text\":\"How hot will it be today?\"}" "{url}/v1/classifiers/10D41B-nlc-1/classify"
IamAuthenticator authenticator = new IamAuthenticator( apikey: "{apikey}" ); NaturalLanguageClassifierService naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator); naturalLanguageClassifier.SetServiceUrl("{url}"); var result = service.Classify( classifierId: "10D41B-nlc-1", text: "How hot will it be today?" ); Console.WriteLine(result.Response);
package main import ( "encoding/json" "fmt" "github.com/IBM/go-sdk-core/core" "github.com/watson-developer-cloud/go-sdk/naturallanguageclassifierv1" ) func main() { authenticator := &core.IamAuthenticator{ ApiKey: "{apikey}", } options := &naturallanguageclassifierv1.NaturalLanguageClassifierV1Options{ Authenticator: authenticator, } naturalLanguageClassifier, naturalLanguageClassifierErr := naturallanguageclassifierv1.NewNaturalLanguageClassifierV1(options) if naturalLanguageClassifierErr != nil { panic(naturalLanguageClassifierErr) } naturalLanguageClassifier.SetServiceURL("{url}") result, response, responseErr := naturalLanguageClassifier.Classify( &naturallanguageclassifierv1.ClassifyOptions{ ClassifierID: core.StringPtr("10D41B-nlc-1"), Text: core.StringPtr("How hot will it be today?"), }, ) if responseErr != nil { panic(responseErr) } b, _ := json.MarshalIndent(result, "", " ") fmt.Println(string(b)) }
IamAuthenticator authenticator = new IamAuthenticator("{apikey}"); NaturalLanguageClassifier naturalLanguageClassifier = new NaturalLanguageClassifier(authenticator); naturalLanguageClassifier.setServiceUrl("{url}"); ClassifyOptions classifyOptions = new ClassifyOptions.Builder() .classifierId("10D41B-nlc-1") .text("How hot will it be today?") .build(); Classification classification = naturalLanguageClassifier.classify(classifyOptions) .execute().getResult(); System.out.println(classification);
const NaturalLanguageClassifierV1 = require('ibm-watson/natural-language-classifier/v1'); const { IamAuthenticator } = require('ibm-watson/auth'); const naturalLanguageClassifier = new NaturalLanguageClassifierV1({ authenticator: new IamAuthenticator({ apikey: '{apikey}', }), serviceUrl: '{url}', }); const classifyParams = { text: 'How hot will it be today?', classifierId: '{classifier_id}', }; naturalLanguageClassifier.classify(classifyParams) .then(response => { const classification = response.result; console.log(JSON.stringify(classification, null, 2)); }) .catch(err => { console.log('error:', err); });
import json from ibm_watson import NaturalLanguageClassifierV1 from ibm_cloud_sdk_core.authenticators import IAMAuthenticator authenticator = IAMAuthenticator('{apikey}') natural_language_classifier = NaturalLanguageClassifierV1( authenticator=authenticator ) natural_language_classifier.set_service_url('{url}') classes = natural_language_classifier.classify( '10D41B-nlc-1', 'How hot will it be today?').get_result() print(json.dumps(classes, indent=2))
require "json" require "ibm_watson/authenticators" require "ibm_watson/natural_language_classifier_v1" include IBMWatson authenticator = Authenticators::IamAuthenticator.new( apikey: "{apikey}" ) natural_language_classifier = NaturalLanguageClassifierV1.new( authenticator: authenticator ) natural_language_classifier.service_url = "{url}" classes = natural_language_classifier.classify( classifier_id: "10D41B-nlc-1", text: "How hot will it be today?" ) puts JSON.pretty_generate(classes.result)
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) }
var authenticator = new IamAuthenticator( apikey: "{apikey}" ); while (!authenticator.CanAuthenticate()) yield return null; var naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator); naturalLanguageClassifier.SetServiceUrl("{url}"); Classification classifyResponse = null; service.Classify( callback: (DetailedResponse<Classification> response, IBMError error) => { Log.Debug("NaturalLanguageClassifierServiceV1", "Classify result: {0}", response.Response); classifyResponse = response.Result; }, classifierId: "10D41B-nlc-1", text: "How hot will it be today?" ); while (classifyResponse == null) yield return null;
Response
Response from the classifier for a phrase.
Unique identifier for this classifier.
Link to the classifier.
The submitted phrase.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
Response from the classifier for a phrase.
Unique identifier for this classifier.
Link to the classifier.
The submitted phrase.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.
Class label.
Classes
Response from the classifier for a phrase.
Unique identifier for this classifier.
Link to the classifier.
The submitted phrase.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.
Class label.
classes
Response from the classifier for a phrase.
Unique identifier for this classifier.
Link to the classifier.
The submitted phrase.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.
Class label.
classes
Response from the classifier for a phrase.
Unique identifier for this classifier.
Link to the classifier.
The submitted phrase.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.
Class label.
classes
Response from the classifier for a phrase.
Unique identifier for this classifier.
Link to the classifier.
The submitted phrase.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.
Class label.
classes
Response from the classifier for a phrase.
Unique identifier for this classifier.
Link to the classifier.
The submitted phrase.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.
Class label.
classes
Response from the classifier for a phrase.
Unique identifier for this classifier.
Link to the classifier.
The submitted phrase.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.
Class label.
Classes
Response from the classifier for a phrase.
Unique identifier for this classifier.
Link to the classifier.
The submitted phrase.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.
Class label.
Classes
Status Code
OK.
Bad request. Likely caused by a classifier status other than
Available
or by malformed JSON.The classifier does not exist or is not available to the user.
Too Many Requests. The rate limit is exceeded for this service instance.
{ "classifier_id": "10D41B-nlc-1", "url": "{url}/v1/classifiers/10D41B-nlc-1/classify?text=How%20hot%20wil/10D41B-nlc-1", "text": "How hot will it be today?", "top_class": "temperature", "classes": [ { "class_name": "temperature", "confidence": 0.9998201258549781 }, { "class_name": "conditions", "confidence": 0.00017987414502176904 } ] }
{ "classifier_id": "10D41B-nlc-1", "url": "{url}/v1/classifiers/10D41B-nlc-1/classify?text=How%20hot%20wil/10D41B-nlc-1", "text": "How hot will it be today?", "top_class": "temperature", "classes": [ { "class_name": "temperature", "confidence": 0.9998201258549781 }, { "class_name": "conditions", "confidence": 0.00017987414502176904 } ] }
{ "code": "429", "error": "Error: Too Many Requests" }
{ "code": "429", "error": "Error: Too Many Requests" }
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.
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.
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.
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.
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.
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.
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.
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.
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.
POST /v1/classifiers/{classifier_id}/classify_collection
(naturalLanguageClassifier *NaturalLanguageClassifierV1) ClassifyCollection(classifyCollectionOptions *ClassifyCollectionOptions) (result *ClassificationCollection, response *core.DetailedResponse, err error)
(naturalLanguageClassifier *NaturalLanguageClassifierV1) ClassifyCollectionWithContext(ctx context.Context, classifyCollectionOptions *ClassifyCollectionOptions) (result *ClassificationCollection, response *core.DetailedResponse, err error)
ServiceCall<ClassificationCollection> classifyCollection(ClassifyCollectionOptions classifyCollectionOptions)
classifyCollection(params)
classify_collection(self,
classifier_id: str,
collection: List['ClassifyInput'],
**kwargs
) -> DetailedResponse
classify_collection(classifier_id:, collection:)
func classifyCollection(
classifierID: String,
collection: [ClassifyInput],
headers: [String: String]? = nil,
completionHandler: @escaping (WatsonResponse<ClassificationCollection>?, WatsonError?) -> Void)
ClassifyCollection(string classifierId, List<ClassifyInput> collection)
ClassifyCollection(Callback<ClassificationCollection> callback, string classifierId, List<ClassifyInput> collection)
Rate limit
This operation is limited to 80 requests per second.
Request
Instantiate the ClassifyCollectionOptions
struct and set the fields to provide parameter values for the ClassifyCollection
method.
Use the ClassifyCollectionOptions.Builder
to create a ClassifyCollectionOptions
object that contains the parameter values for the classifyCollection
method.
Path Parameters
Classifier ID to use.
Phrase to classify. You can submit up to 30 text phrases in a request.
The submitted phrases.
Example:
WithContext method only
A context.Context instance that you can use to specify a timeout for the operation or to cancel an in-flight request.
The ClassifyCollection options.
Classifier ID to use.
The submitted phrases.
Example:The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
Collection
The classifyCollection options.
Classifier ID to use.
The submitted phrases.
Example:The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
collection
parameters
Classifier ID to use.
The submitted phrases.
Example:
[{"text":"How hot will it be today?"},{"text":"Is it hot outside?"}]
The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
collection
parameters
Classifier ID to use.
The submitted phrases.
Example:
[{"text":"How hot will it be today?"},{"text":"Is it hot outside?"}]
The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
collection
parameters
Classifier ID to use.
The submitted phrases.
Example:
[{"text":"How hot will it be today?"},{"text":"Is it hot outside?"}]
The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
collection
parameters
Classifier ID to use.
The submitted phrases.
Example:
[{"text":"How hot will it be today?"},{"text":"Is it hot outside?"}]
The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
collection
parameters
Classifier ID to use.
The submitted phrases.
Example:
[{"text":"How hot will it be today?"},{"text":"Is it hot outside?"}]
The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
collection
parameters
Classifier ID to use.
The submitted phrases.
Example:
[{"text":"How hot will it be today?"},{"text":"Is it hot outside?"}]
The submitted phrase. The maximum length is 2048 characters.
Constraints: length ≤ 2048
collection
curl -X POST -u "apikey:{apikey}" -H "Content-Type:application/json" -d "{\"collection\":[{\"text\":\"How hot will it be today?\"},{\"text\":\"Is it hot outside?\"}]}" "{url}/v1/classifiers/10D41B-nlc-1/classify_collection"
IamAuthenticator authenticator = new IamAuthenticator( apikey: "{apikey}" ); NaturalLanguageClassifierService naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator); naturalLanguageClassifier.SetServiceUrl("{url}"); var collection = new List<ClassifyInput>() { new ClassifyInput() { Text = "How hot will it be today?" }, new ClassifyInput() { Text = "Is it hot outside?" } }; var result = service.ClassifyCollection( classifierId: "10D41B-nlc-1", collection: collection ); Console.WriteLine(result.Response);
package main import ( "encoding/json" "fmt" "github.com/IBM/go-sdk-core/core" "github.com/watson-developer-cloud/go-sdk/naturallanguageclassifierv1" ) func main() { authenticator := &core.IamAuthenticator{ ApiKey: "{apikey}", } options := &naturallanguageclassifierv1.NaturalLanguageClassifierV1Options{ Authenticator: authenticator, } naturalLanguageClassifier, naturalLanguageClassifierErr := naturallanguageclassifierv1.NewNaturalLanguageClassifierV1(options) if naturalLanguageClassifierErr != nil { panic(naturalLanguageClassifierErr) } naturalLanguageClassifier.SetServiceURL("{url}") result, response, responseErr := naturalLanguageClassifier.ClassifyCollection( &naturallanguageclassifierv1.ClassifyCollectionOptions{ ClassifierID: core.StringPtr("10D41B-nlc-1"), Collection: []naturallanguageclassifierv1.ClassifyInput{ naturallanguageclassifierv1.ClassifyInput{ Text: core.StringPtr("How hot will it be today?"), }, naturallanguageclassifierv1.ClassifyInput{ Text: core.StringPtr("Is it hot outside?"), }, }, }, ) if responseErr != nil { panic(responseErr) } b, _ := json.MarshalIndent(result, "", " ") fmt.Println(string(b)) }
IamAuthenticator authenticator = new IamAuthenticator("{apikey}"); NaturalLanguageClassifier naturalLanguageClassifier = new NaturalLanguageClassifier(authenticator); naturalLanguageClassifier.setServiceUrl("{url}"); ClassifyInput input1 = new ClassifyInput(); input1.setText("How hot will it be today?"); ClassifyInput input2 = new ClassifyInput(); input2.setText("Is it hot outside?"); List<ClassifyInput> inputCollection = Arrays.asList(input1, input2); ClassifyCollectionOptions classifyOptions = new ClassifyCollectionOptions.Builder() .classifierId(classifierId) .collection(inputCollection) .build(); ClassificationCollection result = naturalLanguageClassifier .classifyCollection(classifyOptions).execute().getResult(); System.out.println(result);
const NaturalLanguageClassifierV1 = require('ibm-watson/natural-language-classifier/v1'); const { IamAuthenticator } = require('ibm-watson/auth'); const naturalLanguageClassifier = new NaturalLanguageClassifierV1({ authenticator: new IamAuthenticator({ apikey: '{apikey}', }), serviceUrl: '{url}', }); const classifyCollectionParams = { collection: [{ text: 'sometext' }], classifierId: '{classifier_id}', }; naturalLanguageClassifier.classifyCollection(classifyCollectionParams) .then(response => { const classificationCollection = response.result; console.log(JSON.stringify(classificationCollection, null, 2)); }) .catch(err => { console.log('error:', err); });
import json from ibm_watson import NaturalLanguageClassifierV1 from ibm_cloud_sdk_core.authenticators import IAMAuthenticator authenticator = IAMAuthenticator('{apikey}') natural_language_classifier = NaturalLanguageClassifierV1( authenticator=authenticator ) natural_language_classifier.set_service_url('{url}') classes = natural_language_classifier.classify_collection( '10D41B-nlc-1', [{'text':'How hot will it be today?'}, {'text':'Is it hot outside?'}]).get_result() print(json.dumps(classes, indent=2))
require "json" require "ibm_watson/authenticators" require "ibm_watson/natural_language_classifier_v1" include IBMWatson authenticator = Authenticators::IamAuthenticator.new( apikey: "{apikey}" ) natural_language_classifier = NaturalLanguageClassifierV1.new( authenticator: authenticator ) natural_language_classifier.service_url = "{url}" classes = natural_language_classifier.classify_collection( classifier_id: "10D41B-nlc-1", collection: [ {text: "How hot will it be today?"}, {text: "Is it hot outside?"} ] ) puts JSON.pretty_generate(classes.result)
let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}") let naturalLanguageClassifier = NaturalLanguageClassifier(authenticator: authenticator) naturalLanguageClassifier.serviceURL = "{url}" naturalLanguageClassifier.classifyCollection( classifierID: "{classifier_id}", collection: [ ClassifyInput(text: "How hot will it be today?"), ClassifyInput(text: "Is it hot outside?") ]) { response, error in guard let classifications = response?.result else { print(error?.localizedDescription ?? "unknown error") return } print(classifications) }
var authenticator = new IamAuthenticator( apikey: "{apikey}" ); while (!authenticator.CanAuthenticate()) yield return null; var naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator); naturalLanguageClassifier.SetServiceUrl("{url}"); ClassificationCollection classifyCollectionResponse = null; List<ClassifyInput> collection = new List<ClassifyInput>() { new ClassifyInput() { Text = "How hot will it be today?" }, new ClassifyInput() { Text = "Is it hot outside?" } }; service.ClassifyCollection( callback: (DetailedResponse<ClassificationCollection> response, IBMError error) => { Log.Debug("NaturalLanguageClassifierServiceV1", "ClassifyCollection result: {0}", response.Response); classifyCollectionResponse = response.Result; }, classifierId: "10D41B-nlc-1", collection: collection ); while (classifyCollectionResponse == null) yield return null;
Response
Response from the classifier for multiple phrases.
Unique identifier for this classifier.
Link to the classifier.
An array of classifier responses for each submitted phrase.
Response from the classifier for multiple phrases.
Unique identifier for this classifier.
Link to the classifier.
An array of classifier responses for each submitted phrase.
The submitted phrase. The maximum length is 2048 characters.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.
Class label.
Classes
Collection
Response from the classifier for multiple phrases.
Unique identifier for this classifier.
Link to the classifier.
An array of classifier responses for each submitted phrase.
The submitted phrase. The maximum length is 2048 characters.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.
Class label.
classes
collection
Response from the classifier for multiple phrases.
Unique identifier for this classifier.
Link to the classifier.
An array of classifier responses for each submitted phrase.
The submitted phrase. The maximum length is 2048 characters.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.
Class label.
classes
collection
Response from the classifier for multiple phrases.
Unique identifier for this classifier.
Link to the classifier.
An array of classifier responses for each submitted phrase.
The submitted phrase. The maximum length is 2048 characters.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.
Class label.
classes
collection
Response from the classifier for multiple phrases.
Unique identifier for this classifier.
Link to the classifier.
An array of classifier responses for each submitted phrase.
The submitted phrase. The maximum length is 2048 characters.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.
Class label.
classes
collection
Response from the classifier for multiple phrases.
Unique identifier for this classifier.
Link to the classifier.
An array of classifier responses for each submitted phrase.
The submitted phrase. The maximum length is 2048 characters.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.
Class label.
classes
collection
Response from the classifier for multiple phrases.
Unique identifier for this classifier.
Link to the classifier.
An array of classifier responses for each submitted phrase.
The submitted phrase. The maximum length is 2048 characters.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.
Class label.
Classes
Collection
Response from the classifier for multiple phrases.
Unique identifier for this classifier.
Link to the classifier.
An array of classifier responses for each submitted phrase.
The submitted phrase. The maximum length is 2048 characters.
The class with the highest confidence.
An array of up to ten class-confidence pairs sorted in descending order of confidence.
A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.
Class label.
Classes
Collection
Status Code
OK.
Bad request. Likely caused by a classifier status other than
Available
or by malformed JSON.The classifier does not exist or is not available to the user.
Too Many Requests. The rate limit is exceeded for this service instance.
{ "classifier_id": "10D41B-nlc-1", "url": "{url}/v1/classifiers/10D41B-nlc-1", "collection": [ { "text": "How hot will it be today?", "top_class": "temperature", "classes": [ { "class_name": "temperature", "confidence": 0.9930558798985937 }, { "class_name": "conditions", "confidence": 0.006944120101406304 } ] }, { "text": "Is it hot outside?", "top_class": "temperature", "classes": [ { "class_name": "temperature", "confidence": 1 }, { "class_name": "conditions", "confidence": 0 } ] } ] }
{ "classifier_id": "10D41B-nlc-1", "url": "{url}/v1/classifiers/10D41B-nlc-1", "collection": [ { "text": "How hot will it be today?", "top_class": "temperature", "classes": [ { "class_name": "temperature", "confidence": 0.9930558798985937 }, { "class_name": "conditions", "confidence": 0.006944120101406304 } ] }, { "text": "Is it hot outside?", "top_class": "temperature", "classes": [ { "class_name": "temperature", "confidence": 1 }, { "class_name": "conditions", "confidence": 0 } ] } ] }
{ "code": "429", "error": "Error: Too Many Requests" }
{ "code": "429", "error": "Error: Too Many Requests" }
Create classifier
Sends data to create and train a classifier and returns information about the new classifier.
Sends data to create and train a classifier and returns information about the new classifier.
Sends data to create and train a classifier and returns information about the new classifier.
Sends data to create and train a classifier and returns information about the new classifier.
Sends data to create and train a classifier and returns information about the new classifier.
Sends data to create and train a classifier and returns information about the new classifier.
Sends data to create and train a classifier and returns information about the new classifier.
Sends data to create and train a classifier and returns information about the new classifier.
Sends data to create and train a classifier and returns information about the new classifier.
POST /v1/classifiers
(naturalLanguageClassifier *NaturalLanguageClassifierV1) CreateClassifier(createClassifierOptions *CreateClassifierOptions) (result *Classifier, response *core.DetailedResponse, err error)
(naturalLanguageClassifier *NaturalLanguageClassifierV1) CreateClassifierWithContext(ctx context.Context, createClassifierOptions *CreateClassifierOptions) (result *Classifier, response *core.DetailedResponse, err error)
ServiceCall<Classifier> createClassifier(CreateClassifierOptions createClassifierOptions)
createClassifier(params)
create_classifier(self,
training_metadata: BinaryIO,
training_data: BinaryIO,
**kwargs
) -> DetailedResponse
create_classifier(training_metadata:, training_data:)
func createClassifier(
trainingMetadata: Data,
trainingData: Data,
headers: [String: String]? = nil,
completionHandler: @escaping (WatsonResponse<Classifier>?, WatsonError?) -> Void)
CreateClassifier(System.IO.MemoryStream trainingMetadata, System.IO.MemoryStream trainingData)
CreateClassifier(Callback<Classifier> callback, System.IO.MemoryStream trainingMetadata, System.IO.MemoryStream trainingData)
Rate limit
This operation is limited to 80 requests per second.
Request
Instantiate the CreateClassifierOptions
struct and set the fields to provide parameter values for the CreateClassifier
method.
Use the CreateClassifierOptions.Builder
to create a CreateClassifierOptions
object that contains the parameter values for the createClassifier
method.
Form Parameters
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
).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.
WithContext method only
A context.Context instance that you can use to specify a timeout for the operation or to cancel an in-flight request.
The CreateClassifier options.
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
).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.
The createClassifier options.
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
).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.
parameters
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
).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.
parameters
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
).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.
parameters
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
).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.
parameters
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
).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.
parameters
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
).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.
parameters
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
).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.
curl -u "apikey:{apikey}" -F training_data=@train.csv -F training_metadata="{\"language\":\"en\",\"name\":\"My Classifier\"}" "{url}/v1/classifiers"
IamAuthenticator authenticator = new IamAuthenticator( apikey: "{apikey}" ); NaturalLanguageClassifierService naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator); naturalLanguageClassifier.SetServiceUrl("{url}"); DetailedResponse<Classifier> result = null; using (FileStream trainingDataFile = File.OpenRead("./train.csv"), metadataFile = File.OpenRead("./metadata.json")) { using (MemoryStream trainingData = new MemoryStream(), metadata = new MemoryStream()) { trainingDataFile.CopyTo(trainingData); metadataFile.CopyTo(metadata); result = service.CreateClassifier( trainingMetadata: metadata, trainingData: trainingData ); } } Console.WriteLine(result.Response);
package main import ( "encoding/json" "fmt" "os" "github.com/IBM/go-sdk-core/core" "github.com/watson-developer-cloud/go-sdk/naturallanguageclassifierv1" ) func main() { authenticator := &core.IamAuthenticator{ ApiKey: "{apikey}", } options := &naturallanguageclassifierv1.NaturalLanguageClassifierV1Options{ Authenticator: authenticator, } naturalLanguageClassifier, naturalLanguageClassifierErr := naturallanguageclassifierv1.NewNaturalLanguageClassifierV1(options) if naturalLanguageClassifierErr != nil { panic(naturalLanguageClassifierErr) } naturalLanguageClassifier.SetServiceURL("{url}") metadata, metadataErr := os.Open("./metadata.json") if metadataErr != nil { panic(metadataErr) } defer metadata.Close() trainingData, trainingDataErr := os.Open("./train.csv") if trainingDataErr != nil { panic(trainingDataErr) } defer trainingData.Close() result, response, responseErr := naturalLanguageClassifier.CreateClassifier( &naturallanguageclassifierv1.CreateClassifierOptions{ TrainingData: trainingData, TrainingMetadata: metadata, }, ) if responseErr != nil { panic(responseErr) } b, _ := json.MarshalIndent(result, "", " ") fmt.Println(string(b)) }
IamAuthenticator authenticator = new IamAuthenticator("{apikey}"); NaturalLanguageClassifier naturalLanguageClassifier = new NaturalLanguageClassifier(authenticator); naturalLanguageClassifier.setServiceUrl("{url}"); CreateClassifierOptions createOptions = new CreateClassifierOptions.Builder() .trainingMetadata("./metadata.json") .trainingData(new File("./train.csv")) .build(); Classifier classifier = naturalLanguageClassifier.createClassifier(createOptions) .execute().getResult(); System.out.println(classifier);
const NaturalLanguageClassifierV1 = require('ibm-watson/natural-language-classifier/v1'); const { IamAuthenticator } = require('ibm-watson/auth'); const naturalLanguageClassifier = new NaturalLanguageClassifierV1({ authenticator: new IamAuthenticator({ apikey: '{apikey}', }), serviceUrl: '{url}', }); const createClassifierParams = { trainingMetadata: fs.createReadStream('./metadata.json'), trainingData: fs.createReadStream('./data.csv'), }; naturalLanguageClassifier.createClassifier(createClassifierParams) .then(response => { const classifier = response.result; console.log(JSON.stringify(classifier, null, 2)); }) .catch(err => { console.log('error:', err); });
import json from ibm_watson import NaturalLanguageClassifierV1 from ibm_cloud_sdk_core.authenticators import IAMAuthenticator authenticator = IAMAuthenticator('{apikey}') natural_language_classifier = NaturalLanguageClassifierV1( authenticator=authenticator ) natural_language_classifier.set_service_url('{url}') with open('./train.csv', 'rb') as training_data: classifier = natural_language_classifier.create_classifier( training_data=training_data, # before Python SDK v1.0.0, name and language were top-level parameters training_metadata='{"name": "My Classifier","language": "en"}' ).get_result() print(json.dumps(classifier, indent=2))
require "json" require "ibm_watson/authenticators" require "ibm_watson/natural_language_classifier_v1" include IBMWatson authenticator = Authenticators::IamAuthenticator.new( apikey: "{apikey}" ) natural_language_classifier = NaturalLanguageClassifierV1.new( authenticator: authenticator ) natural_language_classifier.service_url = "{url}" File.open("./train.csv") do |training_data| classifier = natural_language_classifier.create_classifier( training_data: training_data, training_metadata: {name: "My Classifier",language: "en"} ) puts JSON.pretty_generate(classifier.result) end
let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}") let naturalLanguageClassifier = NaturalLanguageClassifier(authenticator: authenticator) naturalLanguageClassifier.serviceURL = "{url}" let trainingMetadataURL = Bundle.main.url(forResource: "metadata", withExtension: "json") let trainingMetadata = try! Data(contentsOf: trainingMetadataURL!) let trainingDataURL = Bundle.main.url(forResource: "weather_data_train", withExtension: "csv") let trainingData = try! Data(contentsOf: trainingDataURL!) naturalLanguageClassifier.createClassifier(trainingMetadata: trainingMetadata, trainingData: trainingData) { response, error in guard let classifier = response?.result else { print(error?.localizedDescription ?? "unknown error") return } print(classifier) }
var authenticator = new IamAuthenticator( apikey: "{apikey}" ); while (!authenticator.CanAuthenticate()) yield return null; var naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator); naturalLanguageClassifier.SetServiceUrl("{url}"); Classifier createClassifierResponse = null; using (FileStream trainingDataFile = File.OpenRead("./train.csv")) { using (FileStream metadataFile = File.OpenRead("./metadata.json")) { using (MemoryStream trainingData = new MemoryStream()) { using (MemoryStream metadata = new MemoryStream()) { trainingDataFile.CopyTo(trainingData); metadataFile.CopyTo(metadata); service.CreateClassifier( callback: (DetailedResponse<Classifier> response, IBMError error) => { Log.Debug("NaturalLanguageClassifierServiceV1", "CreateClassifier result: {0}", response.Response); createClassifierResponse = response.Result; createdClassifierId = createClassifierResponse.ClassifierId; }, trainingMetadata: metadata, trainingData: trainingData ); while (createClassifierResponse == null) yield return null; } } } }
Response
A classifier for natural language phrases.
Link to the classifier.
Unique identifier for this classifier.
User-supplied name for the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
A classifier for natural language phrases.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
A classifier for natural language phrases.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
A classifier for natural language phrases.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
A classifier for natural language phrases.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
A classifier for natural language phrases.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
A classifier for natural language phrases.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
A classifier for natural language phrases.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
A classifier for natural language phrases.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
Status Code
OK.
Bad request. Might be caused by the size of the training data (too many classes or records or not enough records). Also returned when the training data or metadata is missing or malformed.
Conflict with this classifier. Likely caused by a temporary server issue or invalid training data. Make sure that your training data adheres to the format and data requirements and resubmit the request to try again.
Too Many Requests. The rate limit is exceeded for this service instance.
{ "classifier_id": "10D41B-nlc-1", "name": "My Classifier", "language": "en", "created": "2015-05-28T18:01:57.393Z", "url": "{url}/v1/classifiers/10D41B-nlc-1", "status": "Training", "status_description": "The classifier instance is in its training phase, not yet ready to accept classify requests" }
{ "classifier_id": "10D41B-nlc-1", "name": "My Classifier", "language": "en", "created": "2015-05-28T18:01:57.393Z", "url": "{url}/v1/classifiers/10D41B-nlc-1", "status": "Training", "status_description": "The classifier instance is in its training phase, not yet ready to accept classify requests" }
{ "code": 400, "error": "Too many classes", "description": "The training data has 3,001 classes, which is larger than the maximum of 3,000 classes." }
{ "code": 400, "error": "Too many classes", "description": "The training data has 3,001 classes, which is larger than the maximum of 3,000 classes." }
{ "code": "429", "error": "Error: Too Many Requests" }
{ "code": "429", "error": "Error: Too Many Requests" }
List classifiers
Returns an empty array if no classifiers are available.
Returns an empty array if no classifiers are available.
Returns an empty array if no classifiers are available.
Returns an empty array if no classifiers are available.
Returns an empty array if no classifiers are available.
Returns an empty array if no classifiers are available.
Returns an empty array if no classifiers are available.
Returns an empty array if no classifiers are available.
Returns an empty array if no classifiers are available.
GET /v1/classifiers
(naturalLanguageClassifier *NaturalLanguageClassifierV1) ListClassifiers(listClassifiersOptions *ListClassifiersOptions) (result *ClassifierList, response *core.DetailedResponse, err error)
(naturalLanguageClassifier *NaturalLanguageClassifierV1) ListClassifiersWithContext(ctx context.Context, listClassifiersOptions *ListClassifiersOptions) (result *ClassifierList, response *core.DetailedResponse, err error)
ServiceCall<ClassifierList> listClassifiers()
listClassifiers(params)
list_classifiers(self,
**kwargs
) -> DetailedResponse
list_classifiers
func listClassifiers(
headers: [String: String]? = nil,
completionHandler: @escaping (WatsonResponse<ClassifierList>?, WatsonError?) -> Void)
ListClassifiers()
ListClassifiers(Callback<ClassifierList> callback)
Rate limit
This operation is limited to 80 requests per second.
Request
No Request Parameters
WithContext method only
A context.Context instance that you can use to specify a timeout for the operation or to cancel an in-flight request.
No Request Parameters
No Request Parameters
No Request Parameters
No Request Parameters
No Request Parameters
No Request Parameters
No Request Parameters
No Request Parameters
curl -u "apikey:{apikey}" "{url}/v1/classifiers"
IamAuthenticator authenticator = new IamAuthenticator( apikey: "{apikey}" ); NaturalLanguageClassifierService naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator); naturalLanguageClassifier.SetServiceUrl("{url}"); var result = service.ListClassifiers(); Console.WriteLine(result.Response);
package main import ( "encoding/json" "fmt" "github.com/IBM/go-sdk-core/core" "github.com/watson-developer-cloud/go-sdk/naturallanguageclassifierv1" ) func main() { authenticator := &core.IamAuthenticator{ ApiKey: "{apikey}", } options := &naturallanguageclassifierv1.NaturalLanguageClassifierV1Options{ Authenticator: authenticator, } naturalLanguageClassifier, naturalLanguageClassifierErr := naturallanguageclassifierv1.NewNaturalLanguageClassifierV1(options) if naturalLanguageClassifierErr != nil { panic(naturalLanguageClassifierErr) } naturalLanguageClassifier.SetServiceURL("{url}") result, response, responseErr := naturalLanguageClassifier.ListClassifiers( &naturallanguageclassifierv1.ListClassifiersOptions{}, ) if responseErr != nil { panic(responseErr) } b, _ := json.MarshalIndent(result, "", " ") fmt.Println(string(b)) }
IamAuthenticator authenticator = new IamAuthenticator("{apikey}"); NaturalLanguageClassifier naturalLanguageClassifier = new NaturalLanguageClassifier(authenticator); naturalLanguageClassifier.setServiceUrl("{url}"); ListClassifiersOptions listOptions = new ListClassifiersOptions.Builder() .build(); ClassifierList classifiers = naturalLanguageClassifier.listClassifiers(listOptions) .execute().getResult(); System.out.println(classifiers);
const NaturalLanguageClassifierV1 = require('ibm-watson/natural-language-classifier/v1'); const { IamAuthenticator } = require('ibm-watson/auth'); const naturalLanguageClassifier = new NaturalLanguageClassifierV1({ authenticator: new IamAuthenticator({ apikey: '{apikey}', }), serviceUrl: '{url}', }); naturalLanguageClassifier.listClassifiers() .then(response => { const classifierList = response.result; console.log(JSON.stringify(classifierList, null, 2)); }) .catch(err => { console.log('error:', err); });
import json from ibm_watson import NaturalLanguageClassifierV1 from ibm_cloud_sdk_core.authenticators import IAMAuthenticator authenticator = IAMAuthenticator('{apikey}') natural_language_classifier = NaturalLanguageClassifierV1( authenticator=authenticator ) natural_language_classifier.set_service_url('{url}') classifiers = natural_language_classifier.list_classifiers().get_result() print(json.dumps(classifiers, indent=2))
require "json" require "ibm_watson/authenticators" require "ibm_watson/natural_language_classifier_v1" include IBMWatson authenticator = Authenticators::IamAuthenticator.new( apikey: "{apikey}" ) natural_language_classifier = NaturalLanguageClassifierV1.new( authenticator: authenticator ) natural_language_classifier.service_url = "{url}" classifiers = natural_language_classifier.list_classifiers puts JSON.pretty_generate(classifiers.result)
let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}") let naturalLanguageClassifier = NaturalLanguageClassifier(authenticator: authenticator) naturalLanguageClassifier.serviceURL = "{url}" naturalLanguageClassifier.listClassifiers() { response, error in guard let classifiers = response?.result else { print(error?.localizedDescription ?? "unknown error") return } print(classifiers) }
var authenticator = new IamAuthenticator( apikey: "{apikey}" ); while (!authenticator.CanAuthenticate()) yield return null; var naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator); naturalLanguageClassifier.SetServiceUrl("{url}"); ClassifierList listClassifiersResponse = null; service.ListClassifiers( callback: (DetailedResponse<ClassifierList> response, IBMError error) => { Log.Debug("NaturalLanguageClassifierServiceV1", "ListClassifiers result: {0}", response.Response); listClassifiersResponse = response.Result; classifierId = listClassifiersResponse.Classifiers[0].ClassifierId; } ); while (listClassifiersResponse == null) yield return null;
Response
List of available classifiers.
The classifiers available to the user. Returns an empty array if no classifiers are available.
List of available classifiers.
The classifiers available to the user. Returns an empty array if no classifiers are available.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
Classifiers
List of available classifiers.
The classifiers available to the user. Returns an empty array if no classifiers are available.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
classifiers
List of available classifiers.
The classifiers available to the user. Returns an empty array if no classifiers are available.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
classifiers
List of available classifiers.
The classifiers available to the user. Returns an empty array if no classifiers are available.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
classifiers
List of available classifiers.
The classifiers available to the user. Returns an empty array if no classifiers are available.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
classifiers
List of available classifiers.
The classifiers available to the user. Returns an empty array if no classifiers are available.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
classifiers
List of available classifiers.
The classifiers available to the user. Returns an empty array if no classifiers are available.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
Classifiers
List of available classifiers.
The classifiers available to the user. Returns an empty array if no classifiers are available.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
Classifiers
Status Code
OK
Too Many Requests. The rate limit is exceeded for this service instance.
{ "classifiers": [ { "classifier_id": "10D41B-nlc-1", "url": "{url}/v1/classifiers/10D41B-nlc-1", "name": "My Classifier", "language": "en", "created": "2015-05-28T18:01:57.393Z" } ] }
{ "classifiers": [ { "classifier_id": "10D41B-nlc-1", "url": "{url}/v1/classifiers/10D41B-nlc-1", "name": "My Classifier", "language": "en", "created": "2015-05-28T18:01:57.393Z" } ] }
{ "code": "429", "error": "Error: Too Many Requests" }
{ "code": "429", "error": "Error: Too Many Requests" }
Get information about a classifier
Returns status and other information about a classifier.
Returns status and other information about a classifier.
Returns status and other information about a classifier.
Returns status and other information about a classifier.
Returns status and other information about a classifier.
Returns status and other information about a classifier.
Returns status and other information about a classifier.
Returns status and other information about a classifier.
Returns status and other information about a classifier.
GET /v1/classifiers/{classifier_id}
(naturalLanguageClassifier *NaturalLanguageClassifierV1) GetClassifier(getClassifierOptions *GetClassifierOptions) (result *Classifier, response *core.DetailedResponse, err error)
(naturalLanguageClassifier *NaturalLanguageClassifierV1) GetClassifierWithContext(ctx context.Context, getClassifierOptions *GetClassifierOptions) (result *Classifier, response *core.DetailedResponse, err error)
ServiceCall<Classifier> getClassifier(GetClassifierOptions getClassifierOptions)
getClassifier(params)
get_classifier(self,
classifier_id: str,
**kwargs
) -> DetailedResponse
get_classifier(classifier_id:)
func getClassifier(
classifierID: String,
headers: [String: String]? = nil,
completionHandler: @escaping (WatsonResponse<Classifier>?, WatsonError?) -> Void)
GetClassifier(string classifierId)
GetClassifier(Callback<Classifier> callback, string classifierId)
Rate limit
This operation is limited to 80 requests per second.
Request
Instantiate the GetClassifierOptions
struct and set the fields to provide parameter values for the GetClassifier
method.
Use the GetClassifierOptions.Builder
to create a GetClassifierOptions
object that contains the parameter values for the getClassifier
method.
Path Parameters
Classifier ID to query.
WithContext method only
A context.Context instance that you can use to specify a timeout for the operation or to cancel an in-flight request.
The GetClassifier options.
Classifier ID to query.
The getClassifier options.
Classifier ID to query.
parameters
Classifier ID to query.
parameters
Classifier ID to query.
parameters
Classifier ID to query.
parameters
Classifier ID to query.
parameters
Classifier ID to query.
parameters
Classifier ID to query.
curl -u "apikey:{apikey}" "{url}/v1/classifiers/10D41B-nlc-1"
IamAuthenticator authenticator = new IamAuthenticator( apikey: "{apikey}" ); NaturalLanguageClassifierService naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator); naturalLanguageClassifier.SetServiceUrl("{url}"); var result = service.GetClassifier( classifierId: "10D41B-nlc-1" ); Console.WriteLine(result.Response);
package main import ( "encoding/json" "fmt" "github.com/IBM/go-sdk-core/core" "github.com/watson-developer-cloud/go-sdk/naturallanguageclassifierv1" ) func main() { authenticator := &core.IamAuthenticator{ ApiKey: "{apikey}", } options := &naturallanguageclassifierv1.NaturalLanguageClassifierV1Options{ Authenticator: authenticator, } naturalLanguageClassifier, naturalLanguageClassifierErr := naturallanguageclassifierv1.NewNaturalLanguageClassifierV1(options) if naturalLanguageClassifierErr != nil { panic(naturalLanguageClassifierErr) } naturalLanguageClassifier.SetServiceURL("{url}") result, response, responseErr := naturalLanguageClassifier.GetClassifier( &naturallanguageclassifierv1.GetClassifierOptions{ ClassifierID: core.StringPtr("10D41B-nlc-1"), }, ) if responseErr != nil { panic(responseErr) } b, _ := json.MarshalIndent(result, "", " ") fmt.Println(string(b)) }
IamAuthenticator authenticator = new IamAuthenticator("{apikey}"); NaturalLanguageClassifier naturalLanguageClassifier = new NaturalLanguageClassifier(authenticator); naturalLanguageClassifier.setServiceUrl("{url}"); GetClassifierOptions getOptions = new GetClassifierOptions.Builder() .classifierId("10D41B-nlc-1") .build(); Classifier classifier = naturalLanguageClassifier.getClassifier(getOptions); .execute().getResult(); System.out.println(classifier);
const NaturalLanguageClassifierV1 = require('ibm-watson/natural-language-classifier/v1'); const { IamAuthenticator } = require('ibm-watson/auth'); const naturalLanguageClassifier = new NaturalLanguageClassifierV1({ authenticator: new IamAuthenticator({ apikey: '{apikey}', }), serviceUrl: '{url}', }); const getClassifierParams = { classifierId: '{classifier_id}', }; naturalLanguageClassifier.getClassifier(getClassifierParams) .then(response => { const classifier = response.result; console.log(JSON.stringify(classifier, null, 2)); }) .catch(err => { console.log('error:', err); });
import json from ibm_watson import NaturalLanguageClassifierV1 from ibm_cloud_sdk_core.authenticators import IAMAuthenticator authenticator = IAMAuthenticator('{apikey}') natural_language_classifier = NaturalLanguageClassifierV1( authenticator=authenticator ) natural_language_classifier.set_service_url('{url}') status = natural_language_classifier.get_classifier('10D41B-nlc-1').get_result() print (json.dumps(status, indent=2))
require "json" require "ibm_watson/authenticators" require "ibm_watson/natural_language_classifier_v1" include IBMWatson authenticator = Authenticators::IamAuthenticator.new( apikey: "{apikey}" ) natural_language_classifier = NaturalLanguageClassifierV1.new( authenticator: authenticator ) natural_language_classifier.service_url = "{url}" status = natural_language_classifier.get_classifier( classifier_id: "10D41B-nlc-1" ) puts JSON.pretty_generate(status.result)
let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}") let naturalLanguageClassifier = NaturalLanguageClassifier(authenticator: authenticator) naturalLanguageClassifier.serviceURL = "{url}" naturalLanguageClassifier.getClassifier(classifierID: "{classifier_id}") { response, error in guard let classifier = response?.result else { print(error?.localizedDescription ?? "unknown error") return } print(classifier) }
var authenticator = new IamAuthenticator( apikey: "{apikey}" ); while (!authenticator.CanAuthenticate()) yield return null; var naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator); naturalLanguageClassifier.SetServiceUrl("{url}"); Classifier getClassifierResponse = null; service.GetClassifier( callback: (DetailedResponse<Classifier> response, IBMError error) => { Log.Debug("NaturalLanguageClassifierServiceV1", "GetClassifier result: {0}", response.Response); getClassifierResponse = response.Result; }, classifierId: "10D41B-nlc-1" ); while (getClassifierResponse == null) yield return null;
Response
A classifier for natural language phrases.
Link to the classifier.
Unique identifier for this classifier.
User-supplied name for the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
A classifier for natural language phrases.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
A classifier for natural language phrases.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
A classifier for natural language phrases.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
A classifier for natural language phrases.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
A classifier for natural language phrases.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
A classifier for natural language phrases.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
A classifier for natural language phrases.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
A classifier for natural language phrases.
User-supplied name for the classifier.
Link to the classifier.
The state of the classifier.
Possible values: [
Non Existent
,Training
,Failed
,Available
,Unavailable
]Unique identifier for this classifier.
Date and time (UTC) the classifier was created.
Additional detail about the status.
The language used for the classifier.
Status Code
OK.
The classifier does not exist or is not available to the user.
Too Many Requests. The rate limit is exceeded for this service instance.
{ "classifier_id": "10D41B-nlc-1", "name": "My Classifier", "language": "en", "created": "2015-05-28T18:01:57.393Z", "url": "{url}/v1/classifiers/10D41B-nlc-1", "status": "Training", "status_description": "The classifier instance is in its training phase, not yet ready to accept classify requests" }
{ "classifier_id": "10D41B-nlc-1", "name": "My Classifier", "language": "en", "created": "2015-05-28T18:01:57.393Z", "url": "{url}/v1/classifiers/10D41B-nlc-1", "status": "Training", "status_description": "The classifier instance is in its training phase, not yet ready to accept classify requests" }
{ "code": "429", "error": "Error: Too Many Requests" }
{ "code": "429", "error": "Error: Too Many Requests" }
Delete classifier
DELETE /v1/classifiers/{classifier_id}
(naturalLanguageClassifier *NaturalLanguageClassifierV1) DeleteClassifier(deleteClassifierOptions *DeleteClassifierOptions) (response *core.DetailedResponse, err error)
(naturalLanguageClassifier *NaturalLanguageClassifierV1) DeleteClassifierWithContext(ctx context.Context, deleteClassifierOptions *DeleteClassifierOptions) (response *core.DetailedResponse, err error)
ServiceCall<Void> deleteClassifier(DeleteClassifierOptions deleteClassifierOptions)
deleteClassifier(params)
delete_classifier(self,
classifier_id: str,
**kwargs
) -> DetailedResponse
delete_classifier(classifier_id:)
func deleteClassifier(
classifierID: String,
headers: [String: String]? = nil,
completionHandler: @escaping (WatsonResponse<Void>?, WatsonError?) -> Void)
DeleteClassifier(string classifierId)
DeleteClassifier(Callback<object> callback, string classifierId)
Rate limit
This operation is limited to 80 requests per second.
Request
Instantiate the DeleteClassifierOptions
struct and set the fields to provide parameter values for the DeleteClassifier
method.
Use the DeleteClassifierOptions.Builder
to create a DeleteClassifierOptions
object that contains the parameter values for the deleteClassifier
method.
Path Parameters
Classifier ID to delete.
WithContext method only
A context.Context instance that you can use to specify a timeout for the operation or to cancel an in-flight request.
The DeleteClassifier options.
Classifier ID to delete.
The deleteClassifier options.
Classifier ID to delete.
parameters
Classifier ID to delete.
parameters
Classifier ID to delete.
parameters
Classifier ID to delete.
parameters
Classifier ID to delete.
parameters
Classifier ID to delete.
parameters
Classifier ID to delete.
curl -X DELETE -u "apikey:{apikey}" "{url}/v1/classifiers/10D41B-nlc-1"
IamAuthenticator authenticator = new IamAuthenticator( apikey: "{apikey}" ); NaturalLanguageClassifierService naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator); naturalLanguageClassifier.SetServiceUrl("{url}"); var result = service.DeleteClassifier( classifierId: "10D41B-nlc-1" ); Console.WriteLine(result.Response);
package main import ( "github.com/IBM/go-sdk-core/core" "github.com/watson-developer-cloud/go-sdk/naturallanguageclassifierv1" ) func main() { authenticator := &core.IamAuthenticator{ ApiKey: "{apikey}", } options := &naturallanguageclassifierv1.NaturalLanguageClassifierV1Options{ Authenticator: authenticator, } naturalLanguageClassifier, naturalLanguageClassifierErr := naturallanguageclassifierv1.NewNaturalLanguageClassifierV1(options) if naturalLanguageClassifierErr != nil { panic(naturalLanguageClassifierErr) } naturalLanguageClassifier.SetServiceURL("{url}") _, responseErr := naturalLanguageClassifier.DeleteClassifier( &naturallanguageclassifierv1.DeleteClassifierOptions{ ClassifierID: core.StringPtr("10D41B-nlc-1"), }, ) if responseErr != nil { panic(responseErr) } }
IamAuthenticator authenticator = new IamAuthenticator("{apikey}"); NaturalLanguageClassifier naturalLanguageClassifier = new NaturalLanguageClassifier(authenticator); naturalLanguageClassifier.setServiceUrl("{url}"); DeleteClassifierOptions deleteOptions = new DeleteClassifierOptions.Builder() .classifierId("10D41B-nlc-1") .build(); naturalLanguageClassifier.deleteClassifier(deleteOptions).execute();
const NaturalLanguageClassifierV1 = require('ibm-watson/natural-language-classifier/v1'); const { IamAuthenticator } = require('ibm-watson/auth'); const naturalLanguageClassifier = new NaturalLanguageClassifierV1({ authenticator: new IamAuthenticator({ apikey: '{apikey}', }), serviceUrl: '{url}', }); const deleteClassifierParams = { classifierId: '{classifier_id}', }; naturalLanguageClassifier.deleteClassifier(deleteClassifierParams) .then(result => { console.log(JSON.stringify(result, null, 2)); }) .catch(err => { console.log('error:', err); });
from ibm_watson import NaturalLanguageClassifierV1 from ibm_cloud_sdk_core.authenticators import IAMAuthenticator authenticator = IAMAuthenticator('{apikey}') natural_language_classifier = NaturalLanguageClassifierV1( authenticator=authenticator ) natural_language_classifier.set_service_url('{url}') natural_language_classifier.delete_classifier('10D41B-nlc-1')
require "ibm_watson/authenticators" require "ibm_watson/natural_language_classifier_v1" include IBMWatson authenticator = Authenticators::IamAuthenticator.new( apikey: "{apikey}" ) natural_language_classifier = NaturalLanguageClassifierV1.new( authenticator: authenticator ) natural_language_classifier.service_url = "{url}" natural_language_classifier.delete_classifier( classifier_id: "10D41B-nlc-1" )
let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}") let naturalLanguageClassifier = NaturalLanguageClassifier(authenticator: authenticator) naturalLanguageClassifier.serviceURL = "{url}" naturalLanguageClassifier.deleteClassifier(classifierID: "{classifier_id}") { _, error in if let error = error { print(error.localizedDescription) return } print("classifier deleted") }
var authenticator = new IamAuthenticator( apikey: "{apikey}" ); while (!authenticator.CanAuthenticate()) yield return null; var naturalLanguageClassifier = new NaturalLanguageClassifierService(authenticator); naturalLanguageClassifier.SetServiceUrl("{url}"); object deleteClassifierResponse = null; service.DeleteClassifier( callback: (DetailedResponse<object> response, IBMError error) => { Log.Debug("NaturalLanguageClassifierServiceV1", "DeleteClassifier result: {0}", response.Response); deleteClassifierResponse = response.Result; }, classifierId: "10D41B-nlc-1" ); while (deleteClassifierResponse == null) yield return null;
Response
Response type: object
Response type: object
Status Code
OK. Deleted.
The classifier does not exist or is not available to the user.
Too Many Requests. The rate limit is exceeded for this service instance.
{}
{}
{ "code": "429", "error": "Error: Too Many Requests" }
{ "code": "429", "error": "Error: Too Many Requests" }