use of com.ibm.watson.tone_analyzer.v3.model.ToneChatOptions in project java-sdk by watson-developer-cloud.
the class ToneAnalyzerIT method testGetChatTone.
/**
* Test to get chat tones from jsonText.
*/
@Test
public void testGetChatTone() {
List<Utterance> utterances = new ArrayList<>();
for (int i = 0; i < texts.length; i++) {
Utterance utterance = new Utterance.Builder().text(texts[i]).user(users[i]).build();
utterances.add(utterance);
}
ToneChatOptions toneChatOptions = new ToneChatOptions.Builder().utterances(utterances).build();
UtteranceAnalyses utterancesTone = service.toneChat(toneChatOptions).execute();
Assert.assertNotNull(utterancesTone);
Assert.assertNotNull(utterancesTone.getUtterancesTone());
Assert.assertEquals(4, utterancesTone.getUtterancesTone().size());
Assert.assertEquals("My charger isn't working.", utterancesTone.getUtterancesTone().get(0).getUtteranceText());
}
use of com.ibm.watson.tone_analyzer.v3.model.ToneChatOptions in project java-sdk by watson-developer-cloud.
the class ToneAnalyzerChatExample method main.
public static void main(String[] args) {
Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
ToneAnalyzer service = new ToneAnalyzer("2017-09-21", authenticator);
String[] texts = { "My charger isn't working.", "Thanks for reaching out. Can you give me some more detail about the issue?", "I put my charger in my tablet to charge it up last night and it keeps saying it isn't" + " charging. The charging icon comes on, but it stays on even when I take the charger out. " + "Which is ridiculous, it's brand new.", "I'm sorry you're having issues with charging. What kind of charger are you using?" };
List<Utterance> utterances = new ArrayList<>();
for (int i = 0; i < texts.length; i++) {
Utterance utterance = new Utterance.Builder().text(texts[i]).build();
utterances.add(utterance);
}
ToneChatOptions toneChatOptions = new ToneChatOptions.Builder().utterances(utterances).build();
// Call the service
UtteranceAnalyses utterancesTone = service.toneChat(toneChatOptions).execute().getResult();
System.out.println(utterancesTone);
}
use of com.ibm.watson.tone_analyzer.v3.model.ToneChatOptions in project java-sdk by watson-developer-cloud.
the class ToneAnalyzerIT method testGetChatTone.
/**
* Test to get chat tones from jsonText.
*/
@Test
public void testGetChatTone() {
List<Utterance> utterances = new ArrayList<>();
for (int i = 0; i < texts.length; i++) {
Utterance utterance = new Utterance.Builder().text(texts[i]).user(users[i]).build();
utterances.add(utterance);
}
ToneChatOptions toneChatOptions = new ToneChatOptions.Builder().utterances(utterances).build();
UtteranceAnalyses utterancesTone = service.toneChat(toneChatOptions).execute().getResult();
Assert.assertNotNull(utterancesTone);
Assert.assertNotNull(utterancesTone.getUtterancesTone());
Assert.assertEquals(4, utterancesTone.getUtterancesTone().size());
Assert.assertEquals("My charger isn't working.", utterancesTone.getUtterancesTone().get(0).getUtteranceText());
}
use of com.ibm.watson.tone_analyzer.v3.model.ToneChatOptions in project java-sdk by watson-developer-cloud.
the class ToneAnalyzer method toneChat.
/**
* Analyze customer-engagement tone.
*
* <p>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.
*
* <p>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.
*
* <p>**See also:** [Using the customer-engagement
* endpoint](https://cloud.ibm.com/docs/tone-analyzer?topic=tone-analyzer-utco#utco).
*
* @param toneChatOptions the {@link ToneChatOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link UtteranceAnalyses}
*/
public ServiceCall<UtteranceAnalyses> toneChat(ToneChatOptions toneChatOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(toneChatOptions, "toneChatOptions cannot be null");
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v3/tone_chat"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("tone_analyzer", "v3", "toneChat");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (toneChatOptions.contentLanguage() != null) {
builder.header("Content-Language", toneChatOptions.contentLanguage());
}
if (toneChatOptions.acceptLanguage() != null) {
builder.header("Accept-Language", toneChatOptions.acceptLanguage());
}
builder.query("version", String.valueOf(this.version));
final JsonObject contentJson = new JsonObject();
contentJson.add("utterances", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(toneChatOptions.utterances()));
builder.bodyJson(contentJson);
ResponseConverter<UtteranceAnalyses> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<UtteranceAnalyses>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.tone_analyzer.v3.model.ToneChatOptions in project java-sdk by watson-developer-cloud.
the class ToneAnalyzerIT method testChatExample.
/**
* Test ChatExample.
*/
@Test
public void testChatExample() {
String[] texts = { "My charger isn't working.", "Thanks for reaching out. Can you give me some more detail about the issue?", "I put my charger in my tablet to charge it up last night and it keeps saying it isn't" + " charging. The charging icon comes on, but it stays on even when I take the charger out. " + "Which is ridiculous, it's brand new.", "I'm sorry you're having issues with charging. What kind of charger are you using?" };
List<Utterance> utterances = new ArrayList<>();
for (int i = 0; i < texts.length; i++) {
Utterance utterance = new Utterance.Builder().text(texts[i]).user(users[i]).build();
utterances.add(utterance);
}
ToneChatOptions toneChatOptions = new ToneChatOptions.Builder().utterances(utterances).build();
// Call the service
UtteranceAnalyses utterancesTone = service.toneChat(toneChatOptions).execute();
System.out.println(utterancesTone);
}
Aggregations