Search in sources :

Example 6 with ToneAnalysis

use of com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneAnalysis 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();
    assertToneAnalysis(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 7 with ToneAnalysis

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

the class ToneAnalyzerIT method testtoneFromText.

/**
 * Test get tone from text.
 */
@Test
public void testtoneFromText() {
    ToneOptions options = new ToneOptions.Builder().text(text).addTone(ToneOptions.Tone.EMOTION).addTone(ToneOptions.Tone.LANGUAGE).addTone(ToneOptions.Tone.SOCIAL).build();
    ToneAnalysis tone = service.tone(options).execute();
    assertToneAnalysis(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 8 with ToneAnalysis

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

the class ToneAnalyzerTest method testtones.

/**
 * Test get tones.
 *
 * @throws InterruptedException the interrupted exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void testtones() throws InterruptedException, IOException {
    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! ";
    ToneAnalysis mockResponse = loadFixture(FIXTURE, ToneAnalysis.class);
    server.enqueue(jsonResponse(mockResponse));
    server.enqueue(jsonResponse(mockResponse));
    server.enqueue(jsonResponse(mockResponse));
    // execute request
    ToneOptions toneOptions = new ToneOptions.Builder().html(text).build();
    ToneAnalysis serviceResponse = service.tone(toneOptions).execute();
    // first request
    RecordedRequest request = server.takeRequest();
    String path = StringUtils.join(TONE_PATH, "?", VERSION_DATE, "=", VERSION_DATE_VALUE);
    assertEquals(path, request.getPath());
    assertNotNull(request.getHeader(HttpHeaders.AUTHORIZATION));
    assertEquals(serviceResponse, mockResponse);
    assertEquals(HttpMediaType.APPLICATION_JSON, request.getHeader(HttpHeaders.ACCEPT));
    // second request
    serviceResponse = service.tone(new ToneOptions.Builder().html(text).build()).execute();
    request = server.takeRequest();
    assertEquals(path, request.getPath());
    assertTrue(request.getHeader(HttpHeaders.CONTENT_TYPE).startsWith(HttpMediaType.TEXT_HTML));
    // third request
    ToneOptions toneOptions1 = new ToneOptions.Builder().html(text).addTone(ToneOptions.Tone.EMOTION).addTone(ToneOptions.Tone.LANGUAGE).addTone(ToneOptions.Tone.SOCIAL).build();
    serviceResponse = service.tone(toneOptions1).execute();
    request = server.takeRequest();
    path = path + "&tones=emotion,language,social";
    assertEquals(path, request.getPath());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) 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) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 9 with ToneAnalysis

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

the class ToneAnalyzerTest method testReadme.

/**
 * Test README.
 */
@Test
public void testReadme() throws InterruptedException, IOException {
    ToneAnalyzer service = new ToneAnalyzer(VERSION_DATE);
    service.setUsernameAndPassword("<username>", "<password>");
    // exclude
    service.setEndPoint(getMockWebServerUrl());
    // exclude
    ToneAnalysis mockResponse = loadFixture(FIXTURE, ToneAnalysis.class);
    // exclude
    server.enqueue(jsonResponse(mockResponse));
    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().html(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) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Aggregations

ToneAnalysis (com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneAnalysis)8 ToneOptions (com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneOptions)6 Test (org.junit.Test)5 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)3 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 HashMap (java.util.HashMap)2 Assistant (com.ibm.watson.developer_cloud.assistant.v1.Assistant)1 MessageOptions (com.ibm.watson.developer_cloud.assistant.v1.model.MessageOptions)1 MessageResponse (com.ibm.watson.developer_cloud.assistant.v1.model.MessageResponse)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 ServiceCallback (com.ibm.watson.developer_cloud.http.ServiceCallback)1 ToneAnalyzer (com.ibm.watson.developer_cloud.tone_analyzer.v3.ToneAnalyzer)1 ToneCategory (com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneCategory)1 ToneScore (com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneScore)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1