Search in sources :

Example 1 with Utterance

use of com.ibm.watson.developer_cloud.tone_analyzer.v3.model.Utterance 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());
}
Also used : Utterance(com.ibm.watson.developer_cloud.tone_analyzer.v3.model.Utterance) ToneChatOptions(com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneChatOptions) ArrayList(java.util.ArrayList) UtteranceAnalyses(com.ibm.watson.developer_cloud.tone_analyzer.v3.model.UtteranceAnalyses) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 2 with Utterance

use of com.ibm.watson.developer_cloud.tone_analyzer.v3.model.Utterance 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);
}
Also used : Utterance(com.ibm.watson.tone_analyzer.v3.model.Utterance) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) ToneChatOptions(com.ibm.watson.tone_analyzer.v3.model.ToneChatOptions) ArrayList(java.util.ArrayList) UtteranceAnalyses(com.ibm.watson.tone_analyzer.v3.model.UtteranceAnalyses) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator)

Example 3 with Utterance

use of com.ibm.watson.developer_cloud.tone_analyzer.v3.model.Utterance 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());
}
Also used : Utterance(com.ibm.watson.tone_analyzer.v3.model.Utterance) ToneChatOptions(com.ibm.watson.tone_analyzer.v3.model.ToneChatOptions) ArrayList(java.util.ArrayList) UtteranceAnalyses(com.ibm.watson.tone_analyzer.v3.model.UtteranceAnalyses) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 4 with Utterance

use of com.ibm.watson.developer_cloud.tone_analyzer.v3.model.Utterance 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));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) UtteranceAnalyses(com.ibm.watson.developer_cloud.tone_analyzer.v3.model.UtteranceAnalyses)

Example 5 with Utterance

use of com.ibm.watson.developer_cloud.tone_analyzer.v3.model.Utterance 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);
}
Also used : Utterance(com.ibm.watson.developer_cloud.tone_analyzer.v3.model.Utterance) ToneChatOptions(com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneChatOptions) ArrayList(java.util.ArrayList) UtteranceAnalyses(com.ibm.watson.developer_cloud.tone_analyzer.v3.model.UtteranceAnalyses) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Aggregations

ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 UtteranceAnalyses (com.ibm.watson.developer_cloud.tone_analyzer.v3.model.UtteranceAnalyses)4 ToneChatOptions (com.ibm.watson.tone_analyzer.v3.model.ToneChatOptions)4 Utterance (com.ibm.watson.tone_analyzer.v3.model.Utterance)4 UtteranceAnalyses (com.ibm.watson.tone_analyzer.v3.model.UtteranceAnalyses)4 ToneChatOptions (com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneChatOptions)3 Utterance (com.ibm.watson.developer_cloud.tone_analyzer.v3.model.Utterance)3 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 JsonObject (com.google.gson.JsonObject)1 Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)1 IamAuthenticator (com.ibm.cloud.sdk.core.security.IamAuthenticator)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Test (org.testng.annotations.Test)1