Search in sources :

Example 1 with ToneOptions

use of com.ibm.watson.tone_analyzer.v3.model.ToneOptions in project java-sdk by watson-developer-cloud.

the class ToneAnalyzerIT method testToneExample.

/**
 * Test ToneExample.
 */
@Test
public void testToneExample() {
    String text = "I know the times are difficult! Our sales have been " + "disappointing for the past three quarters for our data analytics " + "product suite. We have a competitive data analytics product " + "suite in the industry. But we need to do our job selling it! " + "We need to acknowledge and fix our sales challenges. " + "We can’t blame the economy for our lack of execution! " + "We are missing critical sales opportunities. " + "Our product is in no way inferior to the competitor products. " + "Our clients are hungry for analytical tools to improve their " + "business outcomes. Economy has nothing to do with it.";
    // Call the service and get the tone
    ToneOptions tonOptions = new ToneOptions.Builder().text(text).build();
    ToneAnalysis tone = service.tone(tonOptions).execute();
    System.out.println(tone);
}
Also used : ToneAnalysis(com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneAnalysis) ToneOptions(com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 2 with ToneOptions

use of com.ibm.watson.tone_analyzer.v3.model.ToneOptions in project java-sdk by watson-developer-cloud.

the class ToneAnalyzerExample method main.

public static void main(String[] args) {
    ToneAnalyzer service = new ToneAnalyzer("2017-09-21");
    service.setUsernameAndPassword("<username>", "<password>");
    String text = "I know the times are difficult! Our sales have been " + "disappointing for the past three quarters for our data analytics " + "product suite. We have a competitive data analytics product " + "suite in the industry. But we need to do our job selling it! " + "We need to acknowledge and fix our sales challenges. " + "We can’t blame the economy for our lack of execution! " + "We are missing critical sales opportunities. " + "Our product is in no way inferior to the competitor products. " + "Our clients are hungry for analytical tools to improve their " + "business outcomes. Economy has nothing to do with it.";
    // Call the service and get the tone
    ToneOptions toneOptions = new ToneOptions.Builder().text(text).build();
    ToneAnalysis tone = service.tone(toneOptions).execute();
    System.out.println(tone);
}
Also used : ToneAnalysis(com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneAnalysis) ToneOptions(com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneOptions)

Example 3 with ToneOptions

use of com.ibm.watson.tone_analyzer.v3.model.ToneOptions in project java-sdk by watson-developer-cloud.

the class ToneAnalyzerTest method testToneWOptions.

@Test
public void testToneWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"document_tone\": {\"tones\": [{\"score\": 5, \"tone_id\": \"toneId\", \"tone_name\": \"toneName\"}], \"tone_categories\": [{\"tones\": [{\"score\": 5, \"tone_id\": \"toneId\", \"tone_name\": \"toneName\"}], \"category_id\": \"categoryId\", \"category_name\": \"categoryName\"}], \"warning\": \"warning\"}, \"sentences_tone\": [{\"sentence_id\": 10, \"text\": \"text\", \"tones\": [{\"score\": 5, \"tone_id\": \"toneId\", \"tone_name\": \"toneName\"}], \"tone_categories\": [{\"tones\": [{\"score\": 5, \"tone_id\": \"toneId\", \"tone_name\": \"toneName\"}], \"category_id\": \"categoryId\", \"category_name\": \"categoryName\"}], \"input_from\": 9, \"input_to\": 7}]}";
    String tonePath = "/v3/tone";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the ToneInput model
    ToneInput toneInputModel = new ToneInput.Builder().text("testString").build();
    // Construct an instance of the ToneOptions model
    ToneOptions toneOptionsModel = new ToneOptions.Builder().toneInput(toneInputModel).sentences(true).tones(new java.util.ArrayList<String>(java.util.Arrays.asList("emotion"))).contentLanguage("en").acceptLanguage("en").build();
    // Invoke operation with valid options model (positive test)
    Response<ToneAnalysis> response = toneAnalyzerService.tone(toneOptionsModel).execute();
    assertNotNull(response);
    ToneAnalysis responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("version"), "testString");
    assertEquals(Boolean.valueOf(query.get("sentences")), Boolean.valueOf(true));
    assertEquals(query.get("tones"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("emotion")), ","));
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, tonePath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ToneAnalysis(com.ibm.watson.tone_analyzer.v3.model.ToneAnalysis) ToneOptions(com.ibm.watson.tone_analyzer.v3.model.ToneOptions) ToneInput(com.ibm.watson.tone_analyzer.v3.model.ToneInput) Test(org.testng.annotations.Test)

Example 4 with ToneOptions

use of com.ibm.watson.tone_analyzer.v3.model.ToneOptions in project java-sdk by watson-developer-cloud.

the class ToneAnalyzerIT method testToneExample.

/**
 * Test ToneExample.
 */
@Test
public void testToneExample() {
    String text = "I know the times are difficult! Our sales have been " + "disappointing for the past three quarters for our data analytics " + "product suite. We have a competitive data analytics product " + "suite in the industry. But we need to do our job selling it! " + "We need to acknowledge and fix our sales challenges. " + "We can’t blame the economy for our lack of execution! " + "We are missing critical sales opportunities. " + "Our product is in no way inferior to the competitor products. " + "Our clients are hungry for analytical tools to improve their " + "business outcomes. Economy has nothing to do with it.";
    // Call the service and get the tone
    ToneOptions tonOptions = new ToneOptions.Builder().text(text).build();
    ToneAnalysis tone = service.tone(tonOptions).execute().getResult();
    Assert.assertNotNull(tone);
// System.out.println(tone);
}
Also used : ToneAnalysis(com.ibm.watson.tone_analyzer.v3.model.ToneAnalysis) ToneOptions(com.ibm.watson.tone_analyzer.v3.model.ToneOptions) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 5 with ToneOptions

use of com.ibm.watson.tone_analyzer.v3.model.ToneOptions in project java-sdk by watson-developer-cloud.

the class ToneAnalyzerIT method testtoneFromHtml.

/**
 * Test get tone from html.
 */
@Test
public void testtoneFromHtml() {
    ToneOptions options = new ToneOptions.Builder().html(text).build();
    ToneAnalysis tone = service.tone(options).execute().getResult();
    assertToneAnalysis(tone);
}
Also used : ToneAnalysis(com.ibm.watson.tone_analyzer.v3.model.ToneAnalysis) ToneOptions(com.ibm.watson.tone_analyzer.v3.model.ToneOptions) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 ToneAnalysis (com.ibm.watson.tone_analyzer.v3.model.ToneAnalysis)7 ToneAnalysis (com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneAnalysis)6 ToneOptions (com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneOptions)6 ToneOptions (com.ibm.watson.tone_analyzer.v3.model.ToneOptions)6 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)3 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)3 Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)2 IamAuthenticator (com.ibm.cloud.sdk.core.security.IamAuthenticator)2 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 Response (com.ibm.cloud.sdk.core.http.Response)1 ServiceCallback (com.ibm.cloud.sdk.core.http.ServiceCallback)1 Assistant (com.ibm.watson.assistant.v1.Assistant)1 Context (com.ibm.watson.assistant.v1.model.Context)1 MessageInput (com.ibm.watson.assistant.v1.model.MessageInput)1 MessageOptions (com.ibm.watson.assistant.v1.model.MessageOptions)1 MessageResponse (com.ibm.watson.assistant.v1.model.MessageResponse)1 ToneAnalyzer (com.ibm.watson.tone_analyzer.v3.ToneAnalyzer)1