use of com.ibm.watson.developer_cloud.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.developer_cloud.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.developer_cloud.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.developer_cloud.tone_analyzer.v3.model.ToneChatOptions in project java-sdk by watson-developer-cloud.
the class ToneAnalyzer method toneChat.
/**
* 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.
*
* @param toneChatOptions the {@link ToneChatOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link UtteranceAnalyses}
*/
public ServiceCall<UtteranceAnalyses> toneChat(ToneChatOptions toneChatOptions) {
Validator.notNull(toneChatOptions, "toneChatOptions cannot be null");
String[] pathSegments = { "v3/tone_chat" };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.query(VERSION, versionDate);
if (toneChatOptions.contentLanguage() != null) {
builder.header("Content-Language", toneChatOptions.contentLanguage());
}
if (toneChatOptions.acceptLanguage() != null) {
builder.header("Accept-Language", toneChatOptions.acceptLanguage());
}
final JsonObject contentJson = new JsonObject();
contentJson.add("utterances", GsonSingleton.getGson().toJsonTree(toneChatOptions.utterances()));
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(UtteranceAnalyses.class));
}
use of com.ibm.watson.developer_cloud.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