use of com.ibm.watson.tone_analyzer.v3.model.ToneAnalysis 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);
}
use of com.ibm.watson.tone_analyzer.v3.model.ToneAnalysis in project java-sdk by watson-developer-cloud.
the class AssistantToneAnalyzerIntegrationExample method main.
public static void main(String[] args) throws Exception {
// instantiate the assistant service
Assistant assistantService = new Assistant("2018-02-16");
assistantService.setUsernameAndPassword("<username>", "<password>");
// instantiate the tone analyzer service
ToneAnalyzer toneService = new ToneAnalyzer("2017-09-21");
toneService.setUsernameAndPassword("<username>", "<password>");
// workspace id
String workspaceId = "<workspace-id>";
// maintain history in the context variable - will add a history variable to
// each of the emotion, social
// and language tones
boolean maintainHistory = false;
/**
* Input for the Assistant service: input (String): an input string (the user's conversation turn) and context
* (Map<String,Object>: any context that needs to be maintained - either added by the client app or passed in the
* response from the Assistant service on the previous conversation turn.
*/
String input = "I am happy";
Map<String, Object> context = new HashMap<>();
// UPDATE CONTEXT HERE IF CONTINUING AN ONGOING CONVERSATION
// set local context variable to the context from the last response from the
// Assistant Service
// (see the getContext() method of the MessageResponse class in
// com.ibm.watson.developer_cloud.assistant.v1.model)
// async call to Tone Analyzer
ToneOptions toneOptions = new ToneOptions.Builder().text(input).build();
toneService.tone(toneOptions).enqueue(new ServiceCallback<ToneAnalysis>() {
@Override
public void onResponse(ToneAnalysis toneResponsePayload) {
// update context with the tone data returned by the Tone Analyzer
ToneDetection.updateUserTone(context, toneResponsePayload, maintainHistory);
// call Assistant Service with the input and tone-aware context
MessageOptions messageOptions = new MessageOptions.Builder(workspaceId).input(new InputData.Builder(input).build()).context(context).build();
assistantService.message(messageOptions).enqueue(new ServiceCallback<MessageResponse>() {
@Override
public void onResponse(MessageResponse response) {
System.out.println(response);
}
@Override
public void onFailure(Exception e) {
}
});
}
@Override
public void onFailure(Exception e) {
}
});
}
use of com.ibm.watson.tone_analyzer.v3.model.ToneAnalysis 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);
}
use of com.ibm.watson.tone_analyzer.v3.model.ToneAnalysis 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);
}
use of com.ibm.watson.tone_analyzer.v3.model.ToneAnalysis 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);
}
Aggregations