Introduction
IBM® has announced the deprecation of the Watson™ Tone Analyzer service, with all regions affected by this deprecation. As of 24 February 2022, the Tone Analyzer tile will be removed from the IBM Cloud® Platform for new customers; only existing customers will be able to access the product. The service will no longer be available as of 24 February 2023.
As an alternative, we encourage you to consider migrating to the IBM Watson™ Natural Language Understanding service on IBM Cloud®. With Natural Language Understanding, tone analysis is done by using a pre-built classifications model, which provides an easy way to detect language tones in written text. For more information, see migrating from Watson Tone Analyzer Customer Engagement endpoint to Natural Language Understanding.
The IBM Watson™ Tone Analyzer service uses linguistic analysis to detect emotional and language tones in written text. The service can analyze tone at both the document and sentence levels. You can use the service to understand how your written communications are perceived and then to improve the tone of your communications. Businesses can use the service to learn the tone of their customers' communications and to respond to each customer appropriately, or to understand and improve their customer conversations.
Note: Request logging is disabled for the Tone Analyzer service. Regardless of whether you set the X-Watson-Learning-Opt-Out
request header, the service does not log or retain data from requests and responses.
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>10.0.1</version>
</dependency>
Gradle
compile 'com.ibm.watson:ibm-watson:10.0.1'
GitHub
The code examples on this tab use the client library that is provided for Node.js.
Installation
npm install ibm-watson@^7.0.0
GitHub
The code examples on this tab use the client library that is provided for Python.
Installation
pip install --upgrade "ibm-watson>=6.0.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@v3.0.0
GitHub
The code examples on this tab use the client library that is provided for Swift.
Cocoapods
pod 'IBMWatsonToneAnalyzerV3', '~> 5.0.0'
Carthage
github "watson-developer-cloud/swift-sdk" ~> 5.0.0
Swift Package Manager
.package(url: "https://github.com/watson-developer-cloud/swift-sdk", from: "5.0.0")
GitHub
The code examples on this tab use the client library that is provided for .NET Standard.
Package Manager
Install-Package IBM.Watson.ToneAnalyzer.v3 -Version 6.0.0
.NET CLI
dotnet add package IBM.Watson.ToneAnalyzer.v3 --version 6.0.0
PackageReference
<PackageReference Include="IBM.Watson.ToneAnalyzer.v3" Version="6.0.0" />
GitHub
The code examples on this tab use the client library that is provided for Unity.
GitHub
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 Tone Analyzer instance that is hosted in Washington DC:
https://api.us-east.tone-analyzer.watson.cloud.ibm.com/instances/6bbda3b3-d572-45e1-8c54-22d6ed9e52c2
The following URLs represent the base URLs for Tone Analyzer. When you call the API, use the URL that corresponds to the location of your service instance.
- Dallas:
https://api.us-south.tone-analyzer.watson.cloud.ibm.com
- Washington DC:
https://api.us-east.tone-analyzer.watson.cloud.ibm.com
- Frankfurt:
https://api.eu-de.tone-analyzer.watson.cloud.ibm.com
- London:
https://api.eu-gb.tone-analyzer.watson.cloud.ibm.com
- Seoul:
https://api.kr-seo.tone-analyzer.watson.cloud.ibm.com
- Sydney:
https://api.au-syd.tone-analyzer.watson.cloud.ibm.com
- Tokyo:
https://api.jp-tok.tone-analyzer.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.tone-analyzer.watson.cloud.ibm.com/instances/{instance_id}"
Your service instance might not use this URL
Default URL
https://api.us-south.tone-analyzer.watson.cloud.ibm.com
Example for the Washington DC location
IamAuthenticator authenticator = new IamAuthenticator("{apikey}");
ToneAnalyzer toneAnalyzer = new ToneAnalyzer("{version}", authenticator);
toneAnalyzer.setServiceUrl("https://api.us-east.tone-analyzer.watson.cloud.ibm.com");
Default URL
https://api.us-south.tone-analyzer.watson.cloud.ibm.com
Example for the Washington DC location
const ToneAnalyzerV3 = require('ibm-watson/tone-analyzer/v3');
const { IamAuthenticator } = require('ibm-watson/auth');
const toneAnalyzer = new ToneAnalyzerV3({
version: '{version}',
authenticator: new IamAuthenticator({
apikey: '{apikey}',
}),
serviceUrl: 'https://api.us-east.tone-analyzer.watson.cloud.ibm.com',
});
Default URL
https://api.us-south.tone-analyzer.watson.cloud.ibm.com
Example for the Washington DC location
from ibm_watson import ToneAnalyzerV3
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('{apikey}')
tone_analyzer = ToneAnalyzerV3(
version='{version}',
authenticator=authenticator
)
tone_analyzer.set_service_url('https://api.us-east.tone-analyzer.watson.cloud.ibm.com')
Default URL
https://api.us-south.tone-analyzer.watson.cloud.ibm.com
Example for the Washington DC location
require "ibm_watson/authenticators"
require "ibm_watson/tone_analyzer_v3"
include IBMWatson
authenticator = Authenticators::IamAuthenticator.new(
apikey: "{apikey}"
)
tone_analyzer = ToneAnalyzerV3.new(
version: "{version}",
authenticator: authenticator
)
tone_analyzer.service_url = "https://api.us-east.tone-analyzer.watson.cloud.ibm.com"
Default URL
https://api.us-south.tone-analyzer.watson.cloud.ibm.com
Example for the Washington DC location
toneAnalyzer, toneAnalyzerErr := toneanalyzerv3.NewToneAnalyzerV3(options)
if toneAnalyzerErr != nil {
panic(toneAnalyzerErr)
}
toneAnalyzer.SetServiceURL("https://api.us-east.tone-analyzer.watson.cloud.ibm.com")
Default URL
https://api.us-south.tone-analyzer.watson.cloud.ibm.com
Example for the Washington DC location
let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}")
let toneAnalyzer = ToneAnalyzer(version: "{version}", authenticator: authenticator)
toneAnalyzer.serviceURL = "https://api.us-east.tone-analyzer.watson.cloud.ibm.com"
Default URL
https://api.us-south.tone-analyzer.watson.cloud.ibm.com
Example for the Washington DC location
IamAuthenticator authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
ToneAnalyzerService toneAnalyzer = new ToneAnalyzerService("{version}", authenticator);
toneAnalyzer.SetServiceUrl("https://api.us-east.tone-analyzer.watson.cloud.ibm.com");
Default URL
https://api.us-south.tone-analyzer.watson.cloud.ibm.com
Example for the Washington DC location
var authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
while (!authenticator.CanAuthenticate())
yield return null;
var toneAnalyzer = new ToneAnalyzerService("{version}", authenticator);
toneAnalyzer.SetServiceUrl("https://api.us-east.tone-analyzer.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}");
ToneAnalyzer toneAnalyzer = new ToneAnalyzer("{version}", authenticator);
toneAnalyzer.setServiceUrl("{url}");
HttpConfigOptions configOptions = new HttpConfigOptions.Builder()
.disableSslVerification(true)
.build();
toneAnalyzer.configureClient(configOptions);
Example to disable SSL verification
const ToneAnalyzerV3 = require('ibm-watson/tone-analyzer/v3');
const { IamAuthenticator } = require('ibm-watson/auth');
const toneAnalyzer = new ToneAnalyzerV3({
version: '{version}',
authenticator: new IamAuthenticator({
apikey: '{apikey}',
}),
serviceUrl: '{url}',
disableSslVerification: true,
});
Example to disable SSL verification
from ibm_watson import ToneAnalyzerV3
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('{apikey}')
tone_analyzer = ToneAnalyzerV3(
version='{version}',
authenticator=authenticator
)
tone_analyzer.set_service_url('{url}')
tone_analyzer.set_disable_ssl_verification(True)
Example to disable SSL verification
require "ibm_watson/authenticators"
require "ibm_watson/tone_analyzer_v3"
include IBMWatson
authenticator = Authenticators::IamAuthenticator.new(
apikey: "{apikey}"
)
tone_analyzer = ToneAnalyzerV3.new(
version: "{version}",
authenticator: authenticator
)
tone_analyzer.service_url = "{url}"
tone_analyzer.configure_http_client(disable_ssl_verification: true)
Example to disable SSL verification
toneAnalyzer, toneAnalyzerErr := toneanalyzerv3.NewToneAnalyzerV3(options)
if toneAnalyzerErr != nil {
panic(toneAnalyzerErr)
}
toneAnalyzer.SetServiceURL("{url}")
toneAnalyzer.DisableSSLVerification()
Example to disable SSL verification
let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}")
let toneAnalyzer = ToneAnalyzer(version: "{version}", authenticator: authenticator)
toneAnalyzer.serviceURL = "{url}"
toneAnalyzer.disableSSLVerification()
Example to disable SSL verification
IamAuthenticator authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
ToneAnalyzerService toneAnalyzer = new ToneAnalyzerService("{version}", authenticator);
toneAnalyzer.SetServiceUrl("{url}");
toneAnalyzer.DisableSslVerification(true);
Example to disable SSL verification
var authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
while (!authenticator.CanAuthenticate())
yield return null;
var toneAnalyzer = new ToneAnalyzerService("{version}", authenticator);
toneAnalyzer.SetServiceUrl("{url}");
toneAnalyzer.DisableSslVerification = true;
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}/v3/{method}"
SDK managing the IAM token. Replace {apikey}
, {version}
, and {url}
.
IamAuthenticator authenticator = new IamAuthenticator("{apikey}");
ToneAnalyzer toneAnalyzer = new ToneAnalyzer("{version}", authenticator);
toneAnalyzer.setServiceUrl("{url}");
SDK managing the IAM token. Replace {apikey}
, {version}
, and {url}
.
const ToneAnalyzerV3 = require('ibm-watson/tone-analyzer/v3');
const { IamAuthenticator } = require('ibm-watson/auth');
const toneAnalyzer = new ToneAnalyzerV3({
version: '{version}',
authenticator: new IamAuthenticator({
apikey: '{apikey}',
}),
serviceUrl: '{url}',
});
SDK managing the IAM token. Replace {apikey}
, {version}
, and {url}
.
from ibm_watson import ToneAnalyzerV3
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('{apikey}')
tone_analyzer = ToneAnalyzerV3(
version='{version}',
authenticator=authenticator
)
tone_analyzer.set_service_url('{url}')
SDK managing the IAM token. Replace {apikey}
, {version}
, and {url}
.
require "ibm_watson/authenticators"
require "ibm_watson/tone_analyzer_v3"
include IBMWatson
authenticator = Authenticators::IamAuthenticator.new(
apikey: "{apikey}"
)
tone_analyzer = ToneAnalyzerV3.new(
version: "{version}",
authenticator: authenticator
)
tone_analyzer.service_url = "{url}"
SDK managing the IAM token. Replace {apikey}
, {version}
, and {url}
.
import (
"github.com/IBM/go-sdk-core/core"
"github.com/watson-developer-cloud/go-sdk/toneanalyzerv3"
)
func main() {
authenticator := &core.IamAuthenticator{
ApiKey: "{apikey}",
}
options := &toneanalyzerv3.ToneAnalyzerV3Options{
Version: "{version}",
Authenticator: authenticator,
}
toneAnalyzer, toneAnalyzerErr := toneanalyzerv3.NewToneAnalyzerV3(options)
if toneAnalyzerErr != nil {
panic(toneAnalyzerErr)
}
toneAnalyzer.SetServiceURL("{url}")
}
SDK managing the IAM token. Replace {apikey}
, {version}
, and {url}
.
let authenticator = WatsonIAMAuthenticator(apiKey: "{apikey}")
let toneAnalyzer = ToneAnalyzer(version: "{version}", authenticator: authenticator)
toneAnalyzer.serviceURL = "{url}"
SDK managing the IAM token. Replace {apikey}
, {version}
, and {url}
.
IamAuthenticator authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
ToneAnalyzerService toneAnalyzer = new ToneAnalyzerService("{version}", authenticator);
toneAnalyzer.SetServiceUrl("{url}");
SDK managing the IAM token. Replace {apikey}
, {version}
, and {url}
.
var authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
while (!authenticator.CanAuthenticate())
yield return null;
var toneAnalyzer = new ToneAnalyzerService("{version}", authenticator);
toneAnalyzer.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.tone-analyzer.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.
Versioning
API requests require a version parameter that takes a date in the format version=YYYY-MM-DD
. When the API is updated with any breaking changes, the service introduces a new version date for the API.
Send the version parameter with every API request. The service uses the API version for the date you specify, or the most recent version before that date. Don't default to the current date. Instead, specify a date that matches a version that is compatible with your app, and don't change it until your app is ready for a later version.
Specify the version to use on API requests with the version parameter when you create the service instance. The service uses the API version for the date you specify, or the most recent version before that date. Don't default to the current date. Instead, specify a date that matches a version that is compatible with your app, and don't change it until your app is ready for a later version.
This documentation describes the current version of Tone Analyzer, 2017-09-21
. In some cases, differences in earlier versions are noted in the descriptions of parameters and response models.
Error handling
Tone Analyzer 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. |
sub_code string |
A service-specific error code. |
error string |
General description of an error. |
help string |
A URL to documentation explaining the cause and possibly solutions for the 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 Tone Analyzer 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 Tone Analyzer 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 Tone Analyzer 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 Tone Analyzer 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 Tone Analyzer 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 Tone Analyzer 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
toneAnalyzer.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/toneanalyzerv3"
// Instantiate a service
toneAnalyzer, toneAnalyzerErr := toneanalyzerv3.NewToneAnalyzerV3(options)
// Check for errors
if toneAnalyzerErr != nil {
panic(toneAnalyzerErr)
}
// Call a method
result, _, responseErr := toneAnalyzer.MethodName(&methodOptions)
// Check for errors
if responseErr != nil {
panic(responseErr)
}
Example error handling
toneAnalyzer.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
toneAnalyzer.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}/v3/{method}"
Example header parameter in a request
ReturnType returnValue = toneAnalyzer.methodName(parameters)
.addHeader("Custom-Header", "{header_value}")
.execute();
Example header parameter in a request
const parameters = {
{parameters}
};
toneAnalyzer.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 = tone_analyzer.methodName(
parameters,
headers = {
'Custom-Header': '{header_value}'
})
Example header parameter in a request
response = tone_analyzer.headers(
"Custom-Header" => "{header_value}"
).methodName(parameters)
Example header parameter in a request
result, _, responseErr := toneAnalyzer.MethodName(
&methodOptions{
Headers: map[string]string{
"Accept": "application/json",
},
},
)
Example header parameter in a request
let customHeader: [String: String] = ["Custom-Header": "{header_value}"]
toneAnalyzer.methodName(parameters, headers: customHeader) {
response, error in
}
Example header parameter in a request
IamAuthenticator authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
ToneAnalyzerService toneAnalyzer = new ToneAnalyzerService("{version}", authenticator);
toneAnalyzer.SetServiceUrl("{url}");
toneAnalyzer.WithHeader("Custom-Header", "header_value");
Example header parameter in a request
var authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
while (!authenticator.CanAuthenticate())
yield return null;
var toneAnalyzer = new ToneAnalyzerService("{version}", authenticator);
toneAnalyzer.SetServiceUrl("{url}");
toneAnalyzer.WithHeader("Custom-Header", "header_value");
Response details
The Tone Analyzer 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}/v3/{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 = toneAnalyzer.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
toneAnalyzer.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
tone_analyzer.set_detailed_response(True)
response = tone_analyzer.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 = tone_analyzer.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/toneanalyzerv3"
)
result, response, responseErr := toneAnalyzer.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
toneAnalyzer.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 = toneAnalyzer.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()
{
toneAnalyzer.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
Data collection is disabled for the Tone Analyzer service. Regardless of whether you set the X-Watson-Learning-Opt-Out request header, the service does not log or retain data from requests and responses.
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");
toneAnalyzer.setDefaultHeaders(headers);
Example request
const ToneAnalyzerV3 = require('ibm-watson/tone-analyzer/v3');
const { IamAuthenticator } = require('ibm-watson/auth');
const toneAnalyzer = new ToneAnalyzerV3({
version: '{version}',
authenticator: new IamAuthenticator({
apikey: '{apikey}',
}),
serviceUrl: '{url}',
headers: {
'X-Watson-Learning-Opt-Out': 'true'
}
});
Example request
tone_analyzer.set_default_headers({'x-watson-learning-opt-out': "true"})
Example request
tone_analyzer.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")
toneAnalyzer.SetDefaultHeaders(headers)
Example request
toneAnalyzer.defaultHeaders["X-Watson-Learning-Opt-Out"] = "true"
Example request
IamAuthenticator authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
ToneAnalyzerService toneAnalyzer = new ToneAnalyzerService("{version}", authenticator);
toneAnalyzer.SetServiceUrl("{url}");
toneAnalyzer.WithHeader("X-Watson-Learning-Opt-Out", "true");
Example request
var authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
while (!authenticator.CanAuthenticate())
yield return null;
var toneAnalyzer = new ToneAnalyzerService("{version}", authenticator);
toneAnalyzer.SetServiceUrl("{url}");
toneAnalyzer.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 = toneAnalyzer.method(parameters).execute();
Example asynchronous request
toneAnalyzer.method(parameters).enqueue(new ServiceCallback<ReturnType>() {
@Override public void onResponse(ReturnType response) {
. . .
}
@Override public void onFailure(Exception e) {
. . .
}
});
Example synchronous request
response = tone_analyzer.method_name(parameters)
or
response = tone_analyzer.await.method_name(parameters)
Example asynchronous request
response = tone_analyzer.async.method_name(parameters)
Methods
Analyze general tone (GET)
Use the general-purpose endpoint to analyze the tone of your input content. The service analyzes the content for emotional and language tones. The method always analyzes the tone of the full document; by default, it also analyzes the tone of each individual sentence of the content.
You can submit no more than 128 KB of total input content and no more than 1000 individual sentences in plain text format. The service analyzes the first 1000 sentences for document-level analysis and only the first 100 sentences for sentence-level analysis.
Use this GET
method to analyze smaller quantities of plain text content. Use the Analyze general tone POST
method to analyze larger amounts of content in any of the available formats.
Per the HTTP specification, the default encoding for plain text is ISO-8859-1 (effectively, the ASCII character set). Include the charset
parameter to indicate the character encoding of the input text; for example: Content-Type: text/plain;charset=utf-8
.
See also: Using the general-purpose endpoint.
GET /v3/tone
Request
Custom Headers
The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.2017-09-21
: Acceptsen
orfr
.2016-05-19
: Accepts onlyen
.
Allowable values: [
en
,fr
]Default:
en
The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. You can use different languages for Content-Language and Accept-Language.Allowable values: [
ar
,de
,en
,es
,fr
,it
,ja
,ko
,pt-br
,zh-cn
,zh-tw
]Default:
en
Query Parameters
Plain text input that contains the content to be analyzed. You must URL-encode the input.
Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is
2017-09-21
.Indicates whether the service is to return an analysis of each individual sentence in addition to its analysis of the full document. If
true
(the default), the service returns results for each sentence.Default:
true
2017-09-21
: Deprecated. The service continues to accept the parameter for backward-compatibility, but the parameter no longer affects the response.2016-05-19
: A comma-separated list of tones for which the service is to return its analysis of the input; the indicated tones apply both to the full document and to individual sentences of the document. You can specify one or more of the valid values. Omit the parameter to request results for all three tones.Allowable values: [
emotion
,language
,social
]
curl -X GET -u "apikey:{apikey}" "{url}/v3/tone?version=2017-09-21&text=Team,%20I%20know%20that%20times%20are%20tough!%20Product%20sales%20have%20been%20disappointing%20for%20the%20past%20three%20quarters.%20We%20have%20a%20competitive%20product,%20but%20we%20need%20to%20do%20a%20better%20job%20of%20selling%20it!"
Response
The tone analysis results for the input from the general-purpose endpoint.
The results of the analysis for the full input content
An array of
SentenceAnalysis
objects that provides the results of the analysis for the individual sentences of the input content. The service returns results only for the first 100 sentences of the input. The field is omitted if thesentences
parameter of the request is set tofalse
.
Status Code
OK. The request succeeded. If the input is partially correct, the response can include
warning
orerror
fields with appropriate messages.Bad Request. A required input parameter is null or a specified input parameter or header value is invalid or not supported.
Unauthorized. Access is denied due to invalid service credentials.
Not Found. A requested item or parameter does not exist.
Too Many Requests. The service is throttling your request because your IBM Cloud ID submitted more than 1200 requests per minute.
Internal Server Error. The service encountered an internal error.
{ "document_tone": { "tones": [ { "score": 0.6165, "tone_id": "sadness", "tone_name": "Sadness" }, { "score": 0.829888, "tone_id": "analytical", "tone_name": "Analytical" } ] }, "sentences_tone": [ { "sentence_id": 0, "text": "Team, I know that times are tough!", "tones": [ { "score": 0.801827, "tone_id": "analytical", "tone_name": "Analytical" } ] }, { "sentence_id": 1, "text": "Product sales have been disappointing for the past three quarters.", "tones": [ { "score": 0.771241, "tone_id": "sadness", "tone_name": "Sadness" }, { "score": 0.687768, "tone_id": "analytical", "tone_name": "Analytical" } ] }, { "sentence_id": 2, "text": "We have a competitive product, but we need to do a better job of selling it!", "tones": [ { "score": 0.506763, "tone_id": "analytical", "tone_name": "Analytical" } ] } ] }
Analyze general tone
Use the general-purpose endpoint to analyze the tone of your input content. The service analyzes the content for emotional and language tones. The method always analyzes the tone of the full document; by default, it also analyzes the tone of each individual sentence of the content.
You can submit no more than 128 KB of total input content and no more than 1000 individual sentences in JSON, plain text, or HTML format. The service analyzes the first 1000 sentences for document-level analysis and only the first 100 sentences for sentence-level analysis.
Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8; per the HTTP specification, the default encoding for plain text and HTML is ISO-8859-1 (effectively, the ASCII character set). When specifying a content type of plain text or HTML, include the charset
parameter to indicate the character encoding of the input text; for example: Content-Type: text/plain;charset=utf-8
. For text/html
, the service removes HTML tags and analyzes only the textual content.
See also: Using the general-purpose endpoint.
Use the general-purpose endpoint to analyze the tone of your input content. The service analyzes the content for emotional and language tones. The method always analyzes the tone of the full document; by default, it also analyzes the tone of each individual sentence of the content.
You can submit no more than 128 KB of total input content and no more than 1000 individual sentences in JSON, plain text, or HTML format. The service analyzes the first 1000 sentences for document-level analysis and only the first 100 sentences for sentence-level analysis.
Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8; per the HTTP specification, the default encoding for plain text and HTML is ISO-8859-1 (effectively, the ASCII character set). When specifying a content type of plain text or HTML, include the charset
parameter to indicate the character encoding of the input text; for example: Content-Type: text/plain;charset=utf-8
. For text/html
, the service removes HTML tags and analyzes only the textual content.
See also: Using the general-purpose endpoint.
Use the general-purpose endpoint to analyze the tone of your input content. The service analyzes the content for emotional and language tones. The method always analyzes the tone of the full document; by default, it also analyzes the tone of each individual sentence of the content.
You can submit no more than 128 KB of total input content and no more than 1000 individual sentences in JSON, plain text, or HTML format. The service analyzes the first 1000 sentences for document-level analysis and only the first 100 sentences for sentence-level analysis.
Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8; per the HTTP specification, the default encoding for plain text and HTML is ISO-8859-1 (effectively, the ASCII character set). When specifying a content type of plain text or HTML, include the charset
parameter to indicate the character encoding of the input text; for example: Content-Type: text/plain;charset=utf-8
. For text/html
, the service removes HTML tags and analyzes only the textual content.
See also: Using the general-purpose endpoint.
Use the general-purpose endpoint to analyze the tone of your input content. The service analyzes the content for emotional and language tones. The method always analyzes the tone of the full document; by default, it also analyzes the tone of each individual sentence of the content.
You can submit no more than 128 KB of total input content and no more than 1000 individual sentences in JSON, plain text, or HTML format. The service analyzes the first 1000 sentences for document-level analysis and only the first 100 sentences for sentence-level analysis.
Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8; per the HTTP specification, the default encoding for plain text and HTML is ISO-8859-1 (effectively, the ASCII character set). When specifying a content type of plain text or HTML, include the charset
parameter to indicate the character encoding of the input text; for example: Content-Type: text/plain;charset=utf-8
. For text/html
, the service removes HTML tags and analyzes only the textual content.
See also: Using the general-purpose endpoint.
Use the general-purpose endpoint to analyze the tone of your input content. The service analyzes the content for emotional and language tones. The method always analyzes the tone of the full document; by default, it also analyzes the tone of each individual sentence of the content.
You can submit no more than 128 KB of total input content and no more than 1000 individual sentences in JSON, plain text, or HTML format. The service analyzes the first 1000 sentences for document-level analysis and only the first 100 sentences for sentence-level analysis.
Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8; per the HTTP specification, the default encoding for plain text and HTML is ISO-8859-1 (effectively, the ASCII character set). When specifying a content type of plain text or HTML, include the charset
parameter to indicate the character encoding of the input text; for example: Content-Type: text/plain;charset=utf-8
. For text/html
, the service removes HTML tags and analyzes only the textual content.
See also: Using the general-purpose endpoint.
POST /v3/tone
ServiceCall<ToneAnalysis> tone(ToneOptions toneOptions)
tone(params)
tone(self,
tone_input: Union['ToneInput', str, TextIO],
*,
content_type: str = None,
sentences: bool = None,
tones: List[str] = None,
content_language: str = None,
accept_language: str = None,
**kwargs
) -> DetailedResponse
Tone(System.IO.MemoryStream toneInput, string contentType = null, bool? sentences = null, List<string> tones = null, string contentLanguage = null, string acceptLanguage = null)
Request
Use the ToneOptions.Builder
to create a ToneOptions
object that contains the parameter values for the tone
method.
Custom Headers
The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.2017-09-21
: Acceptsen
orfr
.2016-05-19
: Accepts onlyen
.
Allowable values: [
en
,fr
]Default:
en
The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. You can use different languages for Content-Language and Accept-Language.Allowable values: [
ar
,de
,en
,es
,fr
,it
,ja
,ko
,pt-br
,zh-cn
,zh-tw
]Default:
en
Allowable values: [
application/json
,text/plain
,text/html
]
Query Parameters
Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is
2017-09-21
.Indicates whether the service is to return an analysis of each individual sentence in addition to its analysis of the full document. If
true
(the default), the service returns results for each sentence.Default:
true
2017-09-21
: Deprecated. The service continues to accept the parameter for backward-compatibility, but the parameter no longer affects the response.2016-05-19
: A comma-separated list of tones for which the service is to return its analysis of the input; the indicated tones apply both to the full document and to individual sentences of the document. You can specify one or more of the valid values. Omit the parameter to request results for all three tones.Allowable values: [
emotion
,language
,social
]
JSON, plain text, or HTML input that contains the content to be analyzed. For JSON input, provide an object of type ToneInput
.
The input content that the service is to analyze.
The tone options.
JSON, plain text, or HTML input that contains the content to be analyzed. For JSON input, provide an object of type
ToneInput
.The input content that the service is to analyze.
toneInput
JSON, plain text, or HTML input that contains the content to be analyzed. For JSON input, provide an object of type
ToneInput
.The type of the input. A character encoding can be specified by including a
charset
parameter. For example, 'text/plain;charset=utf-8'.Allowable values: [
application/json
,text/plain
,text/html
]Indicates whether the service is to return an analysis of each individual sentence in addition to its analysis of the full document. If
true
(the default), the service returns results for each sentence.Default:
true
2017-09-21
: Deprecated. The service continues to accept the parameter for backward-compatibility, but the parameter no longer affects the response.2016-05-19
: A comma-separated list of tones for which the service is to return its analysis of the input; the indicated tones apply both to the full document and to individual sentences of the document. You can specify one or more of the valid values. Omit the parameter to request results for all three tones.Allowable values: [
emotion
,language
,social
]The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.2017-09-21
: Acceptsen
orfr
.2016-05-19
: Accepts onlyen
.
Allowable values: [
en
,fr
]Default:
en
The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. You can use different languages for Content-Language and Accept-Language.Allowable values: [
ar
,de
,en
,es
,fr
,it
,ja
,ko
,pt-br
,zh-cn
,zh-tw
]Default:
en
parameters
JSON, plain text, or HTML input that contains the content to be analyzed. For JSON input, provide an object of type
ToneInput
.The input content that the service is to analyze.
toneInput
The type of the input. A character encoding can be specified by including a
charset
parameter. For example, 'text/plain;charset=utf-8'.Allowable values: [
application/json
,text/plain
,text/html
]Indicates whether the service is to return an analysis of each individual sentence in addition to its analysis of the full document. If
true
(the default), the service returns results for each sentence.Default:
true
2017-09-21
: Deprecated. The service continues to accept the parameter for backward-compatibility, but the parameter no longer affects the response.2016-05-19
: A comma-separated list of tones for which the service is to return its analysis of the input; the indicated tones apply both to the full document and to individual sentences of the document. You can specify one or more of the valid values. Omit the parameter to request results for all three tones.Allowable values: [
emotion
,language
,social
]The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.2017-09-21
: Acceptsen
orfr
.2016-05-19
: Accepts onlyen
.
Allowable values: [
en
,fr
]Default:
en
The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. You can use different languages for Content-Language and Accept-Language.Allowable values: [
ar
,de
,en
,es
,fr
,it
,ja
,ko
,pt-br
,zh-cn
,zh-tw
]Default:
en
parameters
Input for the general-purpose endpoint.
The input content that the service is to analyze.
tone_input
The type of the input. A character encoding can be specified by including a
charset
parameter. For example, 'text/plain;charset=utf-8'.Allowable values: [
application/json
,text/plain
,text/html
]Indicates whether the service is to return an analysis of each individual sentence in addition to its analysis of the full document. If
true
(the default), the service returns results for each sentence.Default:
true
2017-09-21
: Deprecated. The service continues to accept the parameter for backward-compatibility, but the parameter no longer affects the response.2016-05-19
: A comma-separated list of tones for which the service is to return its analysis of the input; the indicated tones apply both to the full document and to individual sentences of the document. You can specify one or more of the valid values. Omit the parameter to request results for all three tones.Allowable values: [
emotion
,language
,social
]The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.2017-09-21
: Acceptsen
orfr
.2016-05-19
: Accepts onlyen
.
Allowable values: [
en
,fr
]Default:
en
The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. You can use different languages for Content-Language and Accept-Language.Allowable values: [
ar
,de
,en
,es
,fr
,it
,ja
,ko
,pt-br
,zh-cn
,zh-tw
]Default:
en
parameters
JSON, plain text, or HTML input that contains the content to be analyzed. For JSON input, provide an object of type
ToneInput
.The type of the input. A character encoding can be specified by including a
charset
parameter. For example, 'text/plain;charset=utf-8'.Allowable values: [
application/json
,text/plain
,text/html
]Indicates whether the service is to return an analysis of each individual sentence in addition to its analysis of the full document. If
true
(the default), the service returns results for each sentence.Default:
true
2017-09-21
: Deprecated. The service continues to accept the parameter for backward-compatibility, but the parameter no longer affects the response.2016-05-19
: A comma-separated list of tones for which the service is to return its analysis of the input; the indicated tones apply both to the full document and to individual sentences of the document. You can specify one or more of the valid values. Omit the parameter to request results for all three tones.Allowable values: [
emotion
,language
,social
]The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.2017-09-21
: Acceptsen
orfr
.2016-05-19
: Accepts onlyen
.
Allowable values: [
en
,fr
]Default:
en
The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. You can use different languages for Content-Language and Accept-Language.Allowable values: [
ar
,de
,en
,es
,fr
,it
,ja
,ko
,pt-br
,zh-cn
,zh-tw
]Default:
en
curl -X POST -u "apikey:{apikey}" --header "Content-Type: application/json" --data-binary @tone.json "{url}/v3/tone?version=2017-09-21"
Download sample file tone.json
IamAuthenticator authenticator = new IamAuthenticator( apikey: "{apikey}" ); ToneAnalyzerService toneAnalyzer = new ToneAnalyzerService("2017-09-21", authenticator); toneAnalyzer.SetServiceUrl("{url}"); ToneInput toneInput = new ToneInput() { Text = "Team, I know that times are tough! Product sales have been disappointing for the past three quarters. We have a competitive product, but we need to do a better job of selling it!" }; var result = toneAnalyzer.Tone( toneInput: toneInput ); Console.WriteLine(result.Response);
IamAuthenticator authenticator = new IamAuthenticator("{apikey}"); ToneAnalyzer toneAnalyzer = new ToneAnalyzer("2017-09-21", authenticator); toneAnalyzer.setServiceUrl("{url}"); String text = "Team, I know that times are tough! Product " + "sales have been disappointing for the past three " + "quarters. We have a competitive product, but we " + "need to do a better job of selling it!"; ToneOptions toneOptions = new ToneOptions.Builder() .text(text) .build(); ToneAnalysis toneAnalysis = toneAnalyzer.tone(toneOptions).execute().getResult(); System.out.println(toneAnalysis);
const ToneAnalyzerV3 = require('ibm-watson/tone-analyzer/v3'); const { IamAuthenticator } = require('ibm-watson/auth'); const toneAnalyzer = new ToneAnalyzerV3({ version: '2017-09-21', authenticator: new IamAuthenticator({ apikey: '{apikey}', }), serviceUrl: '{url}', }); const text = 'Team, I know that times are tough! Product ' + 'sales have been disappointing for the past three ' + 'quarters. We have a competitive product, but we ' + 'need to do a better job of selling it!'; const toneParams = { toneInput: { 'text': text }, contentType: 'application/json', }; toneAnalyzer.tone(toneParams) .then(toneAnalysis => { console.log(JSON.stringify(toneAnalysis, null, 2)); }) .catch(err => { console.log('error:', err); });
import json from ibm_watson import ToneAnalyzerV3 from ibm_cloud_sdk_core.authenticators import IAMAuthenticator authenticator = IAMAuthenticator('{apikey}') tone_analyzer = ToneAnalyzerV3( version='2017-09-21', authenticator=authenticator ) tone_analyzer.set_service_url('{url}') text = 'Team, I know that times are tough! Product '\ 'sales have been disappointing for the past three '\ 'quarters. We have a competitive product, but we '\ 'need to do a better job of selling it!' tone_analysis = tone_analyzer.tone( {'text': text}, content_type='application/json' ).get_result() print(json.dumps(tone_analysis, indent=2))
Response
The tone analysis results for the input from the general-purpose endpoint.
The results of the analysis for the full input content
An array of
SentenceAnalysis
objects that provides the results of the analysis for the individual sentences of the input content. The service returns results only for the first 100 sentences of the input. The field is omitted if thesentences
parameter of the request is set tofalse
.
The tone analysis results for the input from the general-purpose endpoint.
The results of the analysis for the full input content.
2017-09-21
: An array ofToneScore
objects that provides the results of the analysis for each qualifying tone of the document. The array includes results for any tone whose score is at least 0.5. The array is empty if no tone has a score that meets this threshold.2016-05-19
: Not returned.The score for the tone.
2017-09-21
: The score that is returned lies in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the content.2016-05-19
: The score that is returned lies in the range of 0 to 1. A score less than 0.5 indicates that the tone is unlikely to be perceived in the content; a score greater than 0.75 indicates a high likelihood that the tone is perceived.
The unique, non-localized identifier of the tone.
2017-09-21
: The service can return results for the following tone IDs:anger
,fear
,joy
, andsadness
(emotional tones);analytical
,confident
, andtentative
(language tones). The service returns results only for tones whose scores meet a minimum threshold of 0.5.2016-05-19
: The service can return results for the following tone IDs of the different categories: for theemotion
category:anger
,disgust
,fear
,joy
, andsadness
; for thelanguage
category:analytical
,confident
, andtentative
; for thesocial
category:openness_big5
,conscientiousness_big5
,extraversion_big5
,agreeableness_big5
, andemotional_range_big5
. The service returns scores for all tones of a category, regardless of their values.
The user-visible, localized name of the tone.
tones
2017-09-21
: Not returned.2016-05-19
: An array ofToneCategory
objects that provides the results of the tone analysis for the full document of the input content. The service returns results only for the tones specified with thetones
parameter of the request.An array of
ToneScore
objects that provides the results for the tones of the category.The score for the tone.
2017-09-21
: The score that is returned lies in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the content.2016-05-19
: The score that is returned lies in the range of 0 to 1. A score less than 0.5 indicates that the tone is unlikely to be perceived in the content; a score greater than 0.75 indicates a high likelihood that the tone is perceived.
The unique, non-localized identifier of the tone.
2017-09-21
: The service can return results for the following tone IDs:anger
,fear
,joy
, andsadness
(emotional tones);analytical
,confident
, andtentative
(language tones). The service returns results only for tones whose scores meet a minimum threshold of 0.5.2016-05-19
: The service can return results for the following tone IDs of the different categories: for theemotion
category:anger
,disgust
,fear
,joy
, andsadness
; for thelanguage
category:analytical
,confident
, andtentative
; for thesocial
category:openness_big5
,conscientiousness_big5
,extraversion_big5
,agreeableness_big5
, andemotional_range_big5
. The service returns scores for all tones of a category, regardless of their values.
The user-visible, localized name of the tone.
tones
The unique, non-localized identifier of the category for the results. The service can return results for the following category IDs:
emotion_tone
,language_tone
, andsocial_tone
.The user-visible, localized name of the category.
toneCategories
2017-09-21
: A warning message if the overall content exceeds 128 KB or contains more than 1000 sentences. The service analyzes only the first 1000 sentences for document-level analysis and the first 100 sentences for sentence-level analysis.2016-05-19
: Not returned.
documentTone
An array of
SentenceAnalysis
objects that provides the results of the analysis for the individual sentences of the input content. The service returns results only for the first 100 sentences of the input. The field is omitted if thesentences
parameter of the request is set tofalse
.The unique identifier of a sentence of the input content. The first sentence has ID 0, and the ID of each subsequent sentence is incremented by one.
The text of the input sentence.
2017-09-21
: An array ofToneScore
objects that provides the results of the analysis for each qualifying tone of the sentence. The array includes results for any tone whose score is at least 0.5. The array is empty if no tone has a score that meets this threshold.2016-05-19
: Not returned.The score for the tone.
2017-09-21
: The score that is returned lies in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the content.2016-05-19
: The score that is returned lies in the range of 0 to 1. A score less than 0.5 indicates that the tone is unlikely to be perceived in the content; a score greater than 0.75 indicates a high likelihood that the tone is perceived.
The unique, non-localized identifier of the tone.
2017-09-21
: The service can return results for the following tone IDs:anger
,fear
,joy
, andsadness
(emotional tones);analytical
,confident
, andtentative
(language tones). The service returns results only for tones whose scores meet a minimum threshold of 0.5.2016-05-19
: The service can return results for the following tone IDs of the different categories: for theemotion
category:anger
,disgust
,fear
,joy
, andsadness
; for thelanguage
category:analytical
,confident
, andtentative
; for thesocial
category:openness_big5
,conscientiousness_big5
,extraversion_big5
,agreeableness_big5
, andemotional_range_big5
. The service returns scores for all tones of a category, regardless of their values.
The user-visible, localized name of the tone.
tones
2017-09-21
: Not returned.2016-05-19
: An array ofToneCategory
objects that provides the results of the tone analysis for the sentence. The service returns results only for the tones specified with thetones
parameter of the request.An array of
ToneScore
objects that provides the results for the tones of the category.The score for the tone.
2017-09-21
: The score that is returned lies in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the content.2016-05-19
: The score that is returned lies in the range of 0 to 1. A score less than 0.5 indicates that the tone is unlikely to be perceived in the content; a score greater than 0.75 indicates a high likelihood that the tone is perceived.
The unique, non-localized identifier of the tone.
2017-09-21
: The service can return results for the following tone IDs:anger
,fear
,joy
, andsadness
(emotional tones);analytical
,confident
, andtentative
(language tones). The service returns results only for tones whose scores meet a minimum threshold of 0.5.2016-05-19
: The service can return results for the following tone IDs of the different categories: for theemotion
category:anger
,disgust
,fear
,joy
, andsadness
; for thelanguage
category:analytical
,confident
, andtentative
; for thesocial
category:openness_big5
,conscientiousness_big5
,extraversion_big5
,agreeableness_big5
, andemotional_range_big5
. The service returns scores for all tones of a category, regardless of their values.
The user-visible, localized name of the tone.
tones
The unique, non-localized identifier of the category for the results. The service can return results for the following category IDs:
emotion_tone
,language_tone
, andsocial_tone
.The user-visible, localized name of the category.
toneCategories
2017-09-21
: Not returned.2016-05-19
: The offset of the first character of the sentence in the overall input content.2017-09-21
: Not returned.2016-05-19
: The offset of the last character of the sentence in the overall input content.
sentencesTone
The tone analysis results for the input from the general-purpose endpoint.
The results of the analysis for the full input content.
2017-09-21
: An array ofToneScore
objects that provides the results of the analysis for each qualifying tone of the document. The array includes results for any tone whose score is at least 0.5. The array is empty if no tone has a score that meets this threshold.2016-05-19
: Not returned.The score for the tone.
2017-09-21
: The score that is returned lies in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the content.2016-05-19
: The score that is returned lies in the range of 0 to 1. A score less than 0.5 indicates that the tone is unlikely to be perceived in the content; a score greater than 0.75 indicates a high likelihood that the tone is perceived.
The unique, non-localized identifier of the tone.
2017-09-21
: The service can return results for the following tone IDs:anger
,fear
,joy
, andsadness
(emotional tones);analytical
,confident
, andtentative
(language tones). The service returns results only for tones whose scores meet a minimum threshold of 0.5.2016-05-19
: The service can return results for the following tone IDs of the different categories: for theemotion
category:anger
,disgust
,fear
,joy
, andsadness
; for thelanguage
category:analytical
,confident
, andtentative
; for thesocial
category:openness_big5
,conscientiousness_big5
,extraversion_big5
,agreeableness_big5
, andemotional_range_big5
. The service returns scores for all tones of a category, regardless of their values.
The user-visible, localized name of the tone.
tones
2017-09-21
: Not returned.2016-05-19
: An array ofToneCategory
objects that provides the results of the tone analysis for the full document of the input content. The service returns results only for the tones specified with thetones
parameter of the request.An array of
ToneScore
objects that provides the results for the tones of the category.The score for the tone.
2017-09-21
: The score that is returned lies in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the content.2016-05-19
: The score that is returned lies in the range of 0 to 1. A score less than 0.5 indicates that the tone is unlikely to be perceived in the content; a score greater than 0.75 indicates a high likelihood that the tone is perceived.
The unique, non-localized identifier of the tone.
2017-09-21
: The service can return results for the following tone IDs:anger
,fear
,joy
, andsadness
(emotional tones);analytical
,confident
, andtentative
(language tones). The service returns results only for tones whose scores meet a minimum threshold of 0.5.2016-05-19
: The service can return results for the following tone IDs of the different categories: for theemotion
category:anger
,disgust
,fear
,joy
, andsadness
; for thelanguage
category:analytical
,confident
, andtentative
; for thesocial
category:openness_big5
,conscientiousness_big5
,extraversion_big5
,agreeableness_big5
, andemotional_range_big5
. The service returns scores for all tones of a category, regardless of their values.
The user-visible, localized name of the tone.
tones
The unique, non-localized identifier of the category for the results. The service can return results for the following category IDs:
emotion_tone
,language_tone
, andsocial_tone
.The user-visible, localized name of the category.
tone_categories
2017-09-21
: A warning message if the overall content exceeds 128 KB or contains more than 1000 sentences. The service analyzes only the first 1000 sentences for document-level analysis and the first 100 sentences for sentence-level analysis.2016-05-19
: Not returned.
document_tone
An array of
SentenceAnalysis
objects that provides the results of the analysis for the individual sentences of the input content. The service returns results only for the first 100 sentences of the input. The field is omitted if thesentences
parameter of the request is set tofalse
.The unique identifier of a sentence of the input content. The first sentence has ID 0, and the ID of each subsequent sentence is incremented by one.
The text of the input sentence.
2017-09-21
: An array ofToneScore
objects that provides the results of the analysis for each qualifying tone of the sentence. The array includes results for any tone whose score is at least 0.5. The array is empty if no tone has a score that meets this threshold.2016-05-19
: Not returned.The score for the tone.
2017-09-21
: The score that is returned lies in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the content.2016-05-19
: The score that is returned lies in the range of 0 to 1. A score less than 0.5 indicates that the tone is unlikely to be perceived in the content; a score greater than 0.75 indicates a high likelihood that the tone is perceived.
The unique, non-localized identifier of the tone.
2017-09-21
: The service can return results for the following tone IDs:anger
,fear
,joy
, andsadness
(emotional tones);analytical
,confident
, andtentative
(language tones). The service returns results only for tones whose scores meet a minimum threshold of 0.5.2016-05-19
: The service can return results for the following tone IDs of the different categories: for theemotion
category:anger
,disgust
,fear
,joy
, andsadness
; for thelanguage
category:analytical
,confident
, andtentative
; for thesocial
category:openness_big5
,conscientiousness_big5
,extraversion_big5
,agreeableness_big5
, andemotional_range_big5
. The service returns scores for all tones of a category, regardless of their values.
The user-visible, localized name of the tone.
tones
2017-09-21
: Not returned.2016-05-19
: An array ofToneCategory
objects that provides the results of the tone analysis for the sentence. The service returns results only for the tones specified with thetones
parameter of the request.An array of
ToneScore
objects that provides the results for the tones of the category.The score for the tone.
2017-09-21
: The score that is returned lies in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the content.2016-05-19
: The score that is returned lies in the range of 0 to 1. A score less than 0.5 indicates that the tone is unlikely to be perceived in the content; a score greater than 0.75 indicates a high likelihood that the tone is perceived.
The unique, non-localized identifier of the tone.
2017-09-21
: The service can return results for the following tone IDs:anger
,fear
,joy
, andsadness
(emotional tones);analytical
,confident
, andtentative
(language tones). The service returns results only for tones whose scores meet a minimum threshold of 0.5.2016-05-19
: The service can return results for the following tone IDs of the different categories: for theemotion
category:anger
,disgust
,fear
,joy
, andsadness
; for thelanguage
category:analytical
,confident
, andtentative
; for thesocial
category:openness_big5
,conscientiousness_big5
,extraversion_big5
,agreeableness_big5
, andemotional_range_big5
. The service returns scores for all tones of a category, regardless of their values.
The user-visible, localized name of the tone.
tones
The unique, non-localized identifier of the category for the results. The service can return results for the following category IDs:
emotion_tone
,language_tone
, andsocial_tone
.The user-visible, localized name of the category.
tone_categories
2017-09-21
: Not returned.2016-05-19
: The offset of the first character of the sentence in the overall input content.2017-09-21
: Not returned.2016-05-19
: The offset of the last character of the sentence in the overall input content.
sentences_tone
The tone analysis results for the input from the general-purpose endpoint.
The results of the analysis for the full input content.
2017-09-21
: An array ofToneScore
objects that provides the results of the analysis for each qualifying tone of the document. The array includes results for any tone whose score is at least 0.5. The array is empty if no tone has a score that meets this threshold.2016-05-19
: Not returned.The score for the tone.
2017-09-21
: The score that is returned lies in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the content.2016-05-19
: The score that is returned lies in the range of 0 to 1. A score less than 0.5 indicates that the tone is unlikely to be perceived in the content; a score greater than 0.75 indicates a high likelihood that the tone is perceived.
The unique, non-localized identifier of the tone.
2017-09-21
: The service can return results for the following tone IDs:anger
,fear
,joy
, andsadness
(emotional tones);analytical
,confident
, andtentative
(language tones). The service returns results only for tones whose scores meet a minimum threshold of 0.5.2016-05-19
: The service can return results for the following tone IDs of the different categories: for theemotion
category:anger
,disgust
,fear
,joy
, andsadness
; for thelanguage
category:analytical
,confident
, andtentative
; for thesocial
category:openness_big5
,conscientiousness_big5
,extraversion_big5
,agreeableness_big5
, andemotional_range_big5
. The service returns scores for all tones of a category, regardless of their values.
The user-visible, localized name of the tone.
tones
2017-09-21
: Not returned.2016-05-19
: An array ofToneCategory
objects that provides the results of the tone analysis for the full document of the input content. The service returns results only for the tones specified with thetones
parameter of the request.An array of
ToneScore
objects that provides the results for the tones of the category.The score for the tone.
2017-09-21
: The score that is returned lies in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the content.2016-05-19
: The score that is returned lies in the range of 0 to 1. A score less than 0.5 indicates that the tone is unlikely to be perceived in the content; a score greater than 0.75 indicates a high likelihood that the tone is perceived.
The unique, non-localized identifier of the tone.
2017-09-21
: The service can return results for the following tone IDs:anger
,fear
,joy
, andsadness
(emotional tones);analytical
,confident
, andtentative
(language tones). The service returns results only for tones whose scores meet a minimum threshold of 0.5.2016-05-19
: The service can return results for the following tone IDs of the different categories: for theemotion
category:anger
,disgust
,fear
,joy
, andsadness
; for thelanguage
category:analytical
,confident
, andtentative
; for thesocial
category:openness_big5
,conscientiousness_big5
,extraversion_big5
,agreeableness_big5
, andemotional_range_big5
. The service returns scores for all tones of a category, regardless of their values.
The user-visible, localized name of the tone.
tones
The unique, non-localized identifier of the category for the results. The service can return results for the following category IDs:
emotion_tone
,language_tone
, andsocial_tone
.The user-visible, localized name of the category.
tone_categories
2017-09-21
: A warning message if the overall content exceeds 128 KB or contains more than 1000 sentences. The service analyzes only the first 1000 sentences for document-level analysis and the first 100 sentences for sentence-level analysis.2016-05-19
: Not returned.
document_tone
An array of
SentenceAnalysis
objects that provides the results of the analysis for the individual sentences of the input content. The service returns results only for the first 100 sentences of the input. The field is omitted if thesentences
parameter of the request is set tofalse
.The unique identifier of a sentence of the input content. The first sentence has ID 0, and the ID of each subsequent sentence is incremented by one.
The text of the input sentence.
2017-09-21
: An array ofToneScore
objects that provides the results of the analysis for each qualifying tone of the sentence. The array includes results for any tone whose score is at least 0.5. The array is empty if no tone has a score that meets this threshold.2016-05-19
: Not returned.The score for the tone.
2017-09-21
: The score that is returned lies in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the content.2016-05-19
: The score that is returned lies in the range of 0 to 1. A score less than 0.5 indicates that the tone is unlikely to be perceived in the content; a score greater than 0.75 indicates a high likelihood that the tone is perceived.
The unique, non-localized identifier of the tone.
2017-09-21
: The service can return results for the following tone IDs:anger
,fear
,joy
, andsadness
(emotional tones);analytical
,confident
, andtentative
(language tones). The service returns results only for tones whose scores meet a minimum threshold of 0.5.2016-05-19
: The service can return results for the following tone IDs of the different categories: for theemotion
category:anger
,disgust
,fear
,joy
, andsadness
; for thelanguage
category:analytical
,confident
, andtentative
; for thesocial
category:openness_big5
,conscientiousness_big5
,extraversion_big5
,agreeableness_big5
, andemotional_range_big5
. The service returns scores for all tones of a category, regardless of their values.
The user-visible, localized name of the tone.
tones
2017-09-21
: Not returned.2016-05-19
: An array ofToneCategory
objects that provides the results of the tone analysis for the sentence. The service returns results only for the tones specified with thetones
parameter of the request.An array of
ToneScore
objects that provides the results for the tones of the category.The score for the tone.
2017-09-21
: The score that is returned lies in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the content.2016-05-19
: The score that is returned lies in the range of 0 to 1. A score less than 0.5 indicates that the tone is unlikely to be perceived in the content; a score greater than 0.75 indicates a high likelihood that the tone is perceived.
The unique, non-localized identifier of the tone.
2017-09-21
: The service can return results for the following tone IDs:anger
,fear
,joy
, andsadness
(emotional tones);analytical
,confident
, andtentative
(language tones). The service returns results only for tones whose scores meet a minimum threshold of 0.5.2016-05-19
: The service can return results for the following tone IDs of the different categories: for theemotion
category:anger
,disgust
,fear
,joy
, andsadness
; for thelanguage
category:analytical
,confident
, andtentative
; for thesocial
category:openness_big5
,conscientiousness_big5
,extraversion_big5
,agreeableness_big5
, andemotional_range_big5
. The service returns scores for all tones of a category, regardless of their values.
The user-visible, localized name of the tone.
tones
The unique, non-localized identifier of the category for the results. The service can return results for the following category IDs:
emotion_tone
,language_tone
, andsocial_tone
.The user-visible, localized name of the category.
tone_categories
2017-09-21
: Not returned.2016-05-19
: The offset of the first character of the sentence in the overall input content.2017-09-21
: Not returned.2016-05-19
: The offset of the last character of the sentence in the overall input content.
sentences_tone
The tone analysis results for the input from the general-purpose endpoint.
The results of the analysis for the full input content.
2017-09-21
: An array ofToneScore
objects that provides the results of the analysis for each qualifying tone of the document. The array includes results for any tone whose score is at least 0.5. The array is empty if no tone has a score that meets this threshold.2016-05-19
: Not returned.The score for the tone.
2017-09-21
: The score that is returned lies in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the content.2016-05-19
: The score that is returned lies in the range of 0 to 1. A score less than 0.5 indicates that the tone is unlikely to be perceived in the content; a score greater than 0.75 indicates a high likelihood that the tone is perceived.
The unique, non-localized identifier of the tone.
2017-09-21
: The service can return results for the following tone IDs:anger
,fear
,joy
, andsadness
(emotional tones);analytical
,confident
, andtentative
(language tones). The service returns results only for tones whose scores meet a minimum threshold of 0.5.2016-05-19
: The service can return results for the following tone IDs of the different categories: for theemotion
category:anger
,disgust
,fear
,joy
, andsadness
; for thelanguage
category:analytical
,confident
, andtentative
; for thesocial
category:openness_big5
,conscientiousness_big5
,extraversion_big5
,agreeableness_big5
, andemotional_range_big5
. The service returns scores for all tones of a category, regardless of their values.
The user-visible, localized name of the tone.
Tones
2017-09-21
: Not returned.2016-05-19
: An array ofToneCategory
objects that provides the results of the tone analysis for the full document of the input content. The service returns results only for the tones specified with thetones
parameter of the request.An array of
ToneScore
objects that provides the results for the tones of the category.The score for the tone.
2017-09-21
: The score that is returned lies in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the content.2016-05-19
: The score that is returned lies in the range of 0 to 1. A score less than 0.5 indicates that the tone is unlikely to be perceived in the content; a score greater than 0.75 indicates a high likelihood that the tone is perceived.
The unique, non-localized identifier of the tone.
2017-09-21
: The service can return results for the following tone IDs:anger
,fear
,joy
, andsadness
(emotional tones);analytical
,confident
, andtentative
(language tones). The service returns results only for tones whose scores meet a minimum threshold of 0.5.2016-05-19
: The service can return results for the following tone IDs of the different categories: for theemotion
category:anger
,disgust
,fear
,joy
, andsadness
; for thelanguage
category:analytical
,confident
, andtentative
; for thesocial
category:openness_big5
,conscientiousness_big5
,extraversion_big5
,agreeableness_big5
, andemotional_range_big5
. The service returns scores for all tones of a category, regardless of their values.
The user-visible, localized name of the tone.
Tones
The unique, non-localized identifier of the category for the results. The service can return results for the following category IDs:
emotion_tone
,language_tone
, andsocial_tone
.The user-visible, localized name of the category.
ToneCategories
2017-09-21
: A warning message if the overall content exceeds 128 KB or contains more than 1000 sentences. The service analyzes only the first 1000 sentences for document-level analysis and the first 100 sentences for sentence-level analysis.2016-05-19
: Not returned.
DocumentTone
An array of
SentenceAnalysis
objects that provides the results of the analysis for the individual sentences of the input content. The service returns results only for the first 100 sentences of the input. The field is omitted if thesentences
parameter of the request is set tofalse
.The unique identifier of a sentence of the input content. The first sentence has ID 0, and the ID of each subsequent sentence is incremented by one.
The text of the input sentence.
2017-09-21
: An array ofToneScore
objects that provides the results of the analysis for each qualifying tone of the sentence. The array includes results for any tone whose score is at least 0.5. The array is empty if no tone has a score that meets this threshold.2016-05-19
: Not returned.The score for the tone.
2017-09-21
: The score that is returned lies in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the content.2016-05-19
: The score that is returned lies in the range of 0 to 1. A score less than 0.5 indicates that the tone is unlikely to be perceived in the content; a score greater than 0.75 indicates a high likelihood that the tone is perceived.
The unique, non-localized identifier of the tone.
2017-09-21
: The service can return results for the following tone IDs:anger
,fear
,joy
, andsadness
(emotional tones);analytical
,confident
, andtentative
(language tones). The service returns results only for tones whose scores meet a minimum threshold of 0.5.2016-05-19
: The service can return results for the following tone IDs of the different categories: for theemotion
category:anger
,disgust
,fear
,joy
, andsadness
; for thelanguage
category:analytical
,confident
, andtentative
; for thesocial
category:openness_big5
,conscientiousness_big5
,extraversion_big5
,agreeableness_big5
, andemotional_range_big5
. The service returns scores for all tones of a category, regardless of their values.
The user-visible, localized name of the tone.
Tones
2017-09-21
: Not returned.2016-05-19
: An array ofToneCategory
objects that provides the results of the tone analysis for the sentence. The service returns results only for the tones specified with thetones
parameter of the request.An array of
ToneScore
objects that provides the results for the tones of the category.The score for the tone.
2017-09-21
: The score that is returned lies in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the content.2016-05-19
: The score that is returned lies in the range of 0 to 1. A score less than 0.5 indicates that the tone is unlikely to be perceived in the content; a score greater than 0.75 indicates a high likelihood that the tone is perceived.
The unique, non-localized identifier of the tone.
2017-09-21
: The service can return results for the following tone IDs:anger
,fear
,joy
, andsadness
(emotional tones);analytical
,confident
, andtentative
(language tones). The service returns results only for tones whose scores meet a minimum threshold of 0.5.2016-05-19
: The service can return results for the following tone IDs of the different categories: for theemotion
category:anger
,disgust
,fear
,joy
, andsadness
; for thelanguage
category:analytical
,confident
, andtentative
; for thesocial
category:openness_big5
,conscientiousness_big5
,extraversion_big5
,agreeableness_big5
, andemotional_range_big5
. The service returns scores for all tones of a category, regardless of their values.
The user-visible, localized name of the tone.
Tones
The unique, non-localized identifier of the category for the results. The service can return results for the following category IDs:
emotion_tone
,language_tone
, andsocial_tone
.The user-visible, localized name of the category.
ToneCategories
2017-09-21
: Not returned.2016-05-19
: The offset of the first character of the sentence in the overall input content.2017-09-21
: Not returned.2016-05-19
: The offset of the last character of the sentence in the overall input content.
SentencesTone
Status Code
OK. The request succeeded. If the input is partially correct, the response can include
warning
orerror
fields with appropriate messages.Bad Request. A required input parameter is null or a specified input parameter or header value is invalid or not supported.
Unauthorized. Access is denied due to invalid service credentials.
Not Found. A requested item or parameter does not exist.
Too Many Requests. The service is throttling your request because your IBM Cloud ID submitted more than 1200 requests per minute.
Internal Server Error. The service encountered an internal error.
{ "document_tone": { "tones": [ { "score": 0.6165, "tone_id": "sadness", "tone_name": "Sadness" }, { "score": 0.829888, "tone_id": "analytical", "tone_name": "Analytical" } ] }, "sentences_tone": [ { "sentence_id": 0, "text": "Team, I know that times are tough!", "tones": [ { "score": 0.801827, "tone_id": "analytical", "tone_name": "Analytical" } ] }, { "sentence_id": 1, "text": "Product sales have been disappointing for the past three quarters.", "tones": [ { "score": 0.771241, "tone_id": "sadness", "tone_name": "Sadness" }, { "score": 0.687768, "tone_id": "analytical", "tone_name": "Analytical" } ] }, { "sentence_id": 2, "text": "We have a competitive product, but we need to do a better job of selling it!", "tones": [ { "score": 0.506763, "tone_id": "analytical", "tone_name": "Analytical" } ] } ] }
{ "document_tone": { "tones": [ { "score": 0.6165, "tone_id": "sadness", "tone_name": "Sadness" }, { "score": 0.829888, "tone_id": "analytical", "tone_name": "Analytical" } ] }, "sentences_tone": [ { "sentence_id": 0, "text": "Team, I know that times are tough!", "tones": [ { "score": 0.801827, "tone_id": "analytical", "tone_name": "Analytical" } ] }, { "sentence_id": 1, "text": "Product sales have been disappointing for the past three quarters.", "tones": [ { "score": 0.771241, "tone_id": "sadness", "tone_name": "Sadness" }, { "score": 0.687768, "tone_id": "analytical", "tone_name": "Analytical" } ] }, { "sentence_id": 2, "text": "We have a competitive product, but we need to do a better job of selling it!", "tones": [ { "score": 0.506763, "tone_id": "analytical", "tone_name": "Analytical" } ] } ] }
Analyze customer-engagement tone
Use the customer-engagement endpoint to analyze the tone of customer service and customer support conversations. For each utterance of a conversation, the method reports the most prevalent subset of the following seven tones: sad, frustrated, satisfied, excited, polite, impolite, and sympathetic.
If you submit more than 50 utterances, the service returns a warning for the overall content and analyzes only the first 50 utterances. If you submit a single utterance that contains more than 500 characters, the service returns an error for that utterance and does not analyze the utterance. The request fails if all utterances have more than 500 characters. Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8.
See also: Using the customer-engagement endpoint.
Use the customer-engagement endpoint to analyze the tone of customer service and customer support conversations. For each utterance of a conversation, the method reports the most prevalent subset of the following seven tones: sad, frustrated, satisfied, excited, polite, impolite, and sympathetic.
If you submit more than 50 utterances, the service returns a warning for the overall content and analyzes only the first 50 utterances. If you submit a single utterance that contains more than 500 characters, the service returns an error for that utterance and does not analyze the utterance. The request fails if all utterances have more than 500 characters. Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8.
See also: Using the customer-engagement endpoint.
Use the customer-engagement endpoint to analyze the tone of customer service and customer support conversations. For each utterance of a conversation, the method reports the most prevalent subset of the following seven tones: sad, frustrated, satisfied, excited, polite, impolite, and sympathetic.
If you submit more than 50 utterances, the service returns a warning for the overall content and analyzes only the first 50 utterances. If you submit a single utterance that contains more than 500 characters, the service returns an error for that utterance and does not analyze the utterance. The request fails if all utterances have more than 500 characters. Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8.
See also: Using the customer-engagement endpoint.
Use the customer-engagement endpoint to analyze the tone of customer service and customer support conversations. For each utterance of a conversation, the method reports the most prevalent subset of the following seven tones: sad, frustrated, satisfied, excited, polite, impolite, and sympathetic.
If you submit more than 50 utterances, the service returns a warning for the overall content and analyzes only the first 50 utterances. If you submit a single utterance that contains more than 500 characters, the service returns an error for that utterance and does not analyze the utterance. The request fails if all utterances have more than 500 characters. Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8.
See also: Using the customer-engagement endpoint.
Use the customer-engagement endpoint to analyze the tone of customer service and customer support conversations. For each utterance of a conversation, the method reports the most prevalent subset of the following seven tones: sad, frustrated, satisfied, excited, polite, impolite, and sympathetic.
If you submit more than 50 utterances, the service returns a warning for the overall content and analyzes only the first 50 utterances. If you submit a single utterance that contains more than 500 characters, the service returns an error for that utterance and does not analyze the utterance. The request fails if all utterances have more than 500 characters. Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8.
See also: Using the customer-engagement endpoint.
POST /v3/tone_chat
ServiceCall<UtteranceAnalyses> toneChat(ToneChatOptions toneChatOptions)
toneChat(params)
tone_chat(self,
utterances: List['Utterance'],
*,
content_language: str = None,
accept_language: str = None,
**kwargs
) -> DetailedResponse
ToneChat(List<Utterance> utterances, string contentLanguage = null, string acceptLanguage = null)
Request
Use the ToneChatOptions.Builder
to create a ToneChatOptions
object that contains the parameter values for the toneChat
method.
Custom Headers
The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.2017-09-21
: Acceptsen
orfr
.2016-05-19
: Accepts onlyen
.
Allowable values: [
en
,fr
]Default:
en
The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. You can use different languages for Content-Language and Accept-Language.Allowable values: [
ar
,de
,en
,es
,fr
,it
,ja
,ko
,pt-br
,zh-cn
,zh-tw
]Default:
en
Query Parameters
Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is
2017-09-21
.
An object that contains the content to be analyzed.
An array of
Utterance
objects that provides the input content that the service is to analyze.
The toneChat options.
An array of
Utterance
objects that provides the input content that the service is to analyze.An utterance contributed by a user in the conversation that is to be analyzed. The utterance can contain multiple sentences.
A string that identifies the user who contributed the utterance specified by the
text
parameter.
utterances
The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.2017-09-21
: Acceptsen
orfr
.2016-05-19
: Accepts onlyen
.
Allowable values: [
en
,fr
]Default:
en
The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. You can use different languages for Content-Language and Accept-Language.Allowable values: [
ar
,de
,en
,es
,fr
,it
,ja
,ko
,pt-br
,zh-cn
,zh-tw
]Default:
en
parameters
An array of
Utterance
objects that provides the input content that the service is to analyze.An utterance contributed by a user in the conversation that is to be analyzed. The utterance can contain multiple sentences.
A string that identifies the user who contributed the utterance specified by the
text
parameter.
utterances
The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.2017-09-21
: Acceptsen
orfr
.2016-05-19
: Accepts onlyen
.
Allowable values: [
en
,fr
]Default:
en
The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. You can use different languages for Content-Language and Accept-Language.Allowable values: [
ar
,de
,en
,es
,fr
,it
,ja
,ko
,pt-br
,zh-cn
,zh-tw
]Default:
en
parameters
An array of
Utterance
objects that provides the input content that the service is to analyze.An utterance contributed by a user in the conversation that is to be analyzed. The utterance can contain multiple sentences.
A string that identifies the user who contributed the utterance specified by the
text
parameter.
utterances
The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.2017-09-21
: Acceptsen
orfr
.2016-05-19
: Accepts onlyen
.
Allowable values: [
en
,fr
]Default:
en
The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. You can use different languages for Content-Language and Accept-Language.Allowable values: [
ar
,de
,en
,es
,fr
,it
,ja
,ko
,pt-br
,zh-cn
,zh-tw
]Default:
en
parameters
An array of
Utterance
objects that provides the input content that the service is to analyze.An utterance contributed by a user in the conversation that is to be analyzed. The utterance can contain multiple sentences.
A string that identifies the user who contributed the utterance specified by the
text
parameter.
utterances
The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.2017-09-21
: Acceptsen
orfr
.2016-05-19
: Accepts onlyen
.
Allowable values: [
en
,fr
]Default:
en
The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example,
en-US
is interpreted asen
. You can use different languages for Content-Language and Accept-Language.Allowable values: [
ar
,de
,en
,es
,fr
,it
,ja
,ko
,pt-br
,zh-cn
,zh-tw
]Default:
en
curl -X POST -u "apikey:{apikey}" --header "Content-Type: application/json" --data-binary @tone-chat.json "{url}/v3/tone_chat?version=2017-09-21"
Download sample file tone-chat.json
IamAuthenticator authenticator = new IamAuthenticator( apikey: "{apikey}" ); ToneAnalyzerService toneAnalyzer = new ToneAnalyzerService("2017-09-21", authenticator); toneAnalyzer.SetServiceUrl("{url}"); var utterances = new List<Utterance>() { new Utterance() { Text = "Hello, I'm having a problem with your product.", User = "customer" }, new Utterance() { Text = "OK, let me know what's going on, please.", User = "agent" }, new Utterance() { Text = "Well, nothing is working :(", User = "customer" }, new Utterance() { Text = "Sorry to hear that.", User = "agent" } }; var result = toneAnalyzer.ToneChat( utterances: utterances ); Console.WriteLine(result.Response);
IamAuthenticator authenticator = new IamAuthenticator("{apikey}"); ToneAnalyzer toneAnalyzer = new ToneAnalyzer("2017-09-21", authenticator); toneAnalyzer.setServiceUrl("{url}"); List<Utterance> utterances = new ArrayList<Utterance>(); utterances.add(new Utterance.Builder() .text("Hello, I'm having a problem with your product.") .user("customer") .build()); utterances.add(new Utterance.Builder() .text("OK, let me know what's going on, please.") .user("agent") .build()); utterances.add(new Utterance.Builder() .text("Well, nothing is working :(") .user("customer") .build()); utterances.add(new Utterance.Builder() .text("Sorry to hear that.") .user("agent") .build()); ToneChatOptions toneChatOptions = new ToneChatOptions.Builder() .utterances(utterances) .build(); UtteranceAnalyses utteranceAnalyses = toneAnalyzer.toneChat(toneChatOptions).execute().getResult(); System.out.println(utteranceAnalyses);
const ToneAnalyzerV3 = require('ibm-watson/tone-analyzer/v3'); const { IamAuthenticator } = require('ibm-watson/auth'); const toneAnalyzer = new ToneAnalyzerV3({ version: '2017-09-21', authenticator: new IamAuthenticator({ apikey: '{apikey}', }), serviceUrl: '{url}', }); const toneChatParams = { utterances: [ { text: "Hello, I'm having a problem with your product.", user: "customer", }, { text: "OK, let me know what's going on, please.", user: "agent", }, { text: "Well, nothing is working :(", user: "customer", }, { text: "Sorry to hear that.", user: "agent", }, ], }; toneAnalyzer.toneChat(toneChatParams) .then(utteranceAnalyses => { console.log(JSON.stringify(utteranceAnalyses, null, 2)); }) .catch(err => { console.log('error:', err); });
import json from ibm_watson import ToneAnalyzerV3 from ibm_cloud_sdk_core.authenticators import IAMAuthenticator authenticator = IAMAuthenticator('{apikey}') tone_analyzer = ToneAnalyzerV3( version='2017-09-21', authenticator=authenticator ) tone_analyzer.set_service_url('{url}') utterances = [ { "text": "Hello, I'm having a problem with your product.", "user": "customer" }, { "text": "OK, let me know what's going on, please.", "user": "agent" }, { "text": "Well, nothing is working :(", "user": "customer" }, { "text": "Sorry to hear that.", "user": "agent" } ] utterance_analyses = tone_analyzer.tone_chat(utterances).get_result() print(json.dumps(utterance_analyses, indent=2))
Response
The results of the analysis for the utterances of the input content.
An array of
UtteranceAnalysis
objects that provides the results for each utterance of the input.2017-09-21
: A warning message if the content contains more than 50 utterances. The service analyzes only the first 50 utterances.2016-05-19
: Not returned.
The results of the analysis for the utterances of the input content.
An array of
UtteranceAnalysis
objects that provides the results for each utterance of the input.The unique identifier of the utterance. The first utterance has ID 0, and the ID of each subsequent utterance is incremented by one.
The text of the utterance.
An array of
ToneChatScore
objects that provides results for the most prevalent tones of the utterance. The array includes results for any tone whose score is at least 0.5. The array is empty if no tone has a score that meets this threshold.The score for the tone in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the utterance.
The unique, non-localized identifier of the tone for the results. The service returns results only for tones whose scores meet a minimum threshold of 0.5.
Possible values: [
excited
,frustrated
,impolite
,polite
,sad
,satisfied
,sympathetic
]The user-visible, localized name of the tone.
tones
2017-09-21
: An error message if the utterance contains more than 500 characters. The service does not analyze the utterance.2016-05-19
: Not returned.
utterancesTone
2017-09-21
: A warning message if the content contains more than 50 utterances. The service analyzes only the first 50 utterances.2016-05-19
: Not returned.
The results of the analysis for the utterances of the input content.
An array of
UtteranceAnalysis
objects that provides the results for each utterance of the input.The unique identifier of the utterance. The first utterance has ID 0, and the ID of each subsequent utterance is incremented by one.
The text of the utterance.
An array of
ToneChatScore
objects that provides results for the most prevalent tones of the utterance. The array includes results for any tone whose score is at least 0.5. The array is empty if no tone has a score that meets this threshold.The score for the tone in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the utterance.
The unique, non-localized identifier of the tone for the results. The service returns results only for tones whose scores meet a minimum threshold of 0.5.
Possible values: [
excited
,frustrated
,impolite
,polite
,sad
,satisfied
,sympathetic
]The user-visible, localized name of the tone.
tones
2017-09-21
: An error message if the utterance contains more than 500 characters. The service does not analyze the utterance.2016-05-19
: Not returned.
utterances_tone
2017-09-21
: A warning message if the content contains more than 50 utterances. The service analyzes only the first 50 utterances.2016-05-19
: Not returned.
The results of the analysis for the utterances of the input content.
An array of
UtteranceAnalysis
objects that provides the results for each utterance of the input.The unique identifier of the utterance. The first utterance has ID 0, and the ID of each subsequent utterance is incremented by one.
The text of the utterance.
An array of
ToneChatScore
objects that provides results for the most prevalent tones of the utterance. The array includes results for any tone whose score is at least 0.5. The array is empty if no tone has a score that meets this threshold.The score for the tone in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the utterance.
The unique, non-localized identifier of the tone for the results. The service returns results only for tones whose scores meet a minimum threshold of 0.5.
Possible values: [
excited
,frustrated
,impolite
,polite
,sad
,satisfied
,sympathetic
]The user-visible, localized name of the tone.
tones
2017-09-21
: An error message if the utterance contains more than 500 characters. The service does not analyze the utterance.2016-05-19
: Not returned.
utterances_tone
2017-09-21
: A warning message if the content contains more than 50 utterances. The service analyzes only the first 50 utterances.2016-05-19
: Not returned.
The results of the analysis for the utterances of the input content.
An array of
UtteranceAnalysis
objects that provides the results for each utterance of the input.The unique identifier of the utterance. The first utterance has ID 0, and the ID of each subsequent utterance is incremented by one.
The text of the utterance.
An array of
ToneChatScore
objects that provides results for the most prevalent tones of the utterance. The array includes results for any tone whose score is at least 0.5. The array is empty if no tone has a score that meets this threshold.The score for the tone in the range of 0.5 to 1. A score greater than 0.75 indicates a high likelihood that the tone is perceived in the utterance.
The unique, non-localized identifier of the tone for the results. The service returns results only for tones whose scores meet a minimum threshold of 0.5.
Possible values: [
excited
,frustrated
,impolite
,polite
,sad
,satisfied
,sympathetic
]The user-visible, localized name of the tone.
Tones
2017-09-21
: An error message if the utterance contains more than 500 characters. The service does not analyze the utterance.2016-05-19
: Not returned.
UtterancesTone
2017-09-21
: A warning message if the content contains more than 50 utterances. The service analyzes only the first 50 utterances.2016-05-19
: Not returned.
Status Code
OK. The request succeeded. If the input is partially correct, the response can include
warning
orerror
fields with appropriate messages.Bad Request. A required input parameter is null or a specified input parameter or header value is invalid or not supported. The response is also returned if all utterances of the input have more than 500 characters.
Unauthorized. Access is denied due to invalid service credentials.
Not Found. A requested item or parameter does not exist.
Too Many Requests. The service is throttling your request because your IBM Cloud ID submitted more than 1200 requests per minute.
Internal Server Error. The service encountered an internal error.
{ "utterances_tone": [ { "utterance_id": 0, "utterance_text": "Hello, I'm having a problem with your product.", "tones": [ { "score": 0.686361, "tone_id": "polite", "tone_name": "Polite" } ] }, { "utterance_id": 1, "utterance_text": "OK, let me know what's going on, please.", "tones": [ { "score": 0.92724, "tone_id": "polite", "tone_name": "Polite" } ] }, { "utterance_id": 2, "utterance_text": "Well, nothing is working :(", "tones": [ { "score": 0.997795, "tone_id": "sad", "tone_name": "sad" } ] }, { "utterance_id": 3, "utterance_text": "Sorry to hear that.", "tones": [ { "score": 0.730982, "tone_id": "polite", "tone_name": "Polite" }, { "score": 0.672499, "tone_id": "sympathetic", "tone_name": "Sympathetic" } ] } ] }
{ "utterances_tone": [ { "utterance_id": 0, "utterance_text": "Hello, I'm having a problem with your product.", "tones": [ { "score": 0.686361, "tone_id": "polite", "tone_name": "Polite" } ] }, { "utterance_id": 1, "utterance_text": "OK, let me know what's going on, please.", "tones": [ { "score": 0.92724, "tone_id": "polite", "tone_name": "Polite" } ] }, { "utterance_id": 2, "utterance_text": "Well, nothing is working :(", "tones": [ { "score": 0.997795, "tone_id": "sad", "tone_name": "sad" } ] }, { "utterance_id": 3, "utterance_text": "Sorry to hear that.", "tones": [ { "score": 0.730982, "tone_id": "polite", "tone_name": "Polite" }, { "score": 0.672499, "tone_id": "sympathetic", "tone_name": "Sympathetic" } ] } ] }