Skip to content

Commit 2be0957

Browse files
committed
Add newest generated Tone Analyzer code and update tests
1 parent 202ef1f commit 2be0957

File tree

16 files changed

+54
-86
lines changed

16 files changed

+54
-86
lines changed

tone-analyzer/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzer.java

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 IBM Corp. All Rights Reserved.
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -12,7 +12,6 @@
1212
*/
1313
package com.ibm.watson.developer_cloud.tone_analyzer.v3;
1414

15-
import com.ibm.watson.developer_cloud.util.RequestUtils;
1615
import com.google.gson.JsonObject;
1716
import com.ibm.watson.developer_cloud.http.RequestBuilder;
1817
import com.ibm.watson.developer_cloud.http.ServiceCall;
@@ -22,39 +21,16 @@
2221
import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneOptions;
2322
import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.UtteranceAnalyses;
2423
import com.ibm.watson.developer_cloud.util.GsonSingleton;
24+
import com.ibm.watson.developer_cloud.util.RequestUtils;
2525
import com.ibm.watson.developer_cloud.util.ResponseConverterUtils;
2626
import com.ibm.watson.developer_cloud.util.Validator;
2727

2828
/**
29-
* ### Service Overview
3029
* The IBM Watson Tone Analyzer service uses linguistic analysis to detect emotional and language tones in written text.
3130
* The service can analyze tone at both the document and sentence levels. You can use the service to understand how your
3231
* written communications are perceived and then to improve the tone of your communications. Businesses can use the
3332
* service to learn the tone of their customers' communications and to respond to each customer appropriately, or to
3433
* understand and improve their customer conversations.
35-
* ### API Usage
36-
* The following information provides details about using the service to analyze tone:
37-
* * **The tone method:** The service offers `GET` and `POST /v3/tone` methods that use the general purpose endpoint to
38-
* analyze the tone of input content. The methods accept content in JSON, plain text, or HTML format.
39-
* * **The tone_chat method:** The service offers a `POST /v3/tone_chat` method that uses the customer engagement
40-
* endpoint to analyze the tone of customer service and customer support conversations. The method accepts content in
41-
* JSON format.
42-
* * **Authentication:** You authenticate to the service by using your service credentials. You can use your credentials
43-
* to authenticate via a proxy server that resides in IBM Cloud, or you can use your credentials to obtain a token and
44-
* contact the service directly. See [Service credentials for Watson
45-
* services](https://console.bluemix.net/docs/services/watson/getting-started-credentials.html) and [Tokens for
46-
* authentication](https://console.bluemix.net/docs/services/watson/getting-started-tokens.html).
47-
* * **Request Logging:** By default, all Watson services log requests and their results. Data is collected only to
48-
* improve the Watson services. If you do not want to share your data, set the header parameter
49-
* `X-Watson-Learning-Opt-Out` to `true` for each request. Data is collected for any request that omits this header. See
50-
* [Controlling request logging for Watson
51-
* services](https://console.bluemix.net/docs/services/watson/getting-started-logging.html).
52-
*
53-
* For more information about the service, see [About Tone
54-
* Analyzer](https://console.bluemix.net/docs/services/tone-analyzer/index.html).
55-
*
56-
* **Note:** Method descriptions apply to the latest version of the interface, `2017-09-21`. Where necessary, parameters
57-
* and models describe differences between versions `2017-09-21` and `2016-05-19`.
5834
*
5935
* @version v3
6036
* @see <a href="http://www.ibm.com/watson/developercloud/tone-analyzer.html">Tone Analyzer</a>
@@ -98,20 +74,18 @@ public ToneAnalyzer(String versionDate, String username, String password) {
9874
}
9975

10076
/**
101-
* Analyze general purpose tone.
77+
* Analyze general tone.
10278
*
103-
* Uses the general purpose endpoint to analyze the tone of your input content. The service analyzes the content for
79+
* Use the general purpose endpoint to analyze the tone of your input content. The service analyzes the content for
10480
* emotional and language tones. The method always analyzes the tone of the full document; by default, it also
10581
* analyzes the tone of each individual sentence of the content. You can submit no more than 128 KB of total input
10682
* content and no more than 1000 individual sentences in JSON, plain text, or HTML format. The service analyzes the
107-
* first 1000 sentences for document-level analysis and only the first 100 sentences for sentence-level analysis. Use
108-
* the `POST` request method to analyze larger amounts of content in any of the available formats. Use the `GET`
109-
* request method to analyze smaller quantities of plain text content. Per the JSON specification, the default
110-
* character encoding for JSON content is effectively always UTF-8; per the HTTP specification, the default encoding
111-
* for plain text and HTML is ISO-8859-1 (effectively, the ASCII character set). When specifying a content type of
112-
* plain text or HTML, include the `charset` parameter to indicate the character encoding of the input text; for
113-
* example: `Content-Type: text/plain;charset=utf-8`. For `text/html`, the service removes HTML tags and analyzes only
114-
* the textual content.
83+
* first 1000 sentences for document-level analysis and only the first 100 sentences for sentence-level analysis. Per
84+
* the JSON specification, the default character encoding for JSON content is effectively always UTF-8; per the HTTP
85+
* specification, the default encoding for plain text and HTML is ISO-8859-1 (effectively, the ASCII character set).
86+
* When specifying a content type of plain text or HTML, include the `charset` parameter to indicate the character
87+
* encoding of the input text; for example: `Content-Type: text/plain;charset=utf-8`. For `text/html`, the service
88+
* removes HTML tags and analyzes only the textual content.
11589
*
11690
* @param toneOptions the {@link ToneOptions} containing the options for the call
11791
* @return a {@link ServiceCall} with a response type of {@link ToneAnalysis}

tone-analyzer/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/DocumentAnalysis.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 IBM Corp. All Rights Reserved.
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at

tone-analyzer/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/SentenceAnalysis.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 IBM Corp. All Rights Reserved.
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at

tone-analyzer/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneAnalysis.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 IBM Corp. All Rights Reserved.
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at

tone-analyzer/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneCategory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 IBM Corp. All Rights Reserved.
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at

tone-analyzer/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneChatOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 IBM Corp. All Rights Reserved.
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at

tone-analyzer/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneChatScore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 IBM Corp. All Rights Reserved.
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at

tone-analyzer/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneInput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 IBM Corp. All Rights Reserved.
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at

tone-analyzer/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 IBM Corp. All Rights Reserved.
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at

tone-analyzer/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneScore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 IBM Corp. All Rights Reserved.
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at

tone-analyzer/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/Utterance.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 IBM Corp. All Rights Reserved.
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at

tone-analyzer/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/UtteranceAnalyses.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 IBM Corp. All Rights Reserved.
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at

tone-analyzer/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/UtteranceAnalysis.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 IBM Corp. All Rights Reserved.
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -23,7 +23,7 @@
2323
public class UtteranceAnalysis extends GenericModel {
2424

2525
@SerializedName("utterance_id")
26-
private String utteranceId;
26+
private Long utteranceId;
2727
@SerializedName("utterance_text")
2828
private String utteranceText;
2929
private List<ToneChatScore> tones;
@@ -37,7 +37,7 @@ public class UtteranceAnalysis extends GenericModel {
3737
*
3838
* @return the utteranceId
3939
*/
40-
public String getUtteranceId() {
40+
public Long getUtteranceId() {
4141
return utteranceId;
4242
}
4343

@@ -82,7 +82,7 @@ public String getError() {
8282
*
8383
* @param utteranceId the new utteranceId
8484
*/
85-
public void setUtteranceId(final String utteranceId) {
85+
public void setUtteranceId(final long utteranceId) {
8686
this.utteranceId = utteranceId;
8787
}
8888

tone-analyzer/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 IBM Corp. All Rights Reserved.
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at

tone-analyzer/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerIT.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,22 @@ public class ToneAnalyzerIT extends WatsonServiceTest {
3737

3838
/** The service. */
3939
private ToneAnalyzer service;
40-
private static final String VERSION_DATE_2016_05_19 = "2016-05-19";
40+
private static final String VERSION_DATE_VALUE = "2017-09-21";
4141
private String text = "I know the times are difficult! Our sales have been "
4242
+ "disappointing for the past three quarters for our data analytics "
4343
+ "product suite. We have a competitive data analytics product "
4444
+ "suite in the industry. But we need to do our job selling it! ";
4545

4646
private String[] users = { "customer", "agent", "customer", "agent" };
47-
private String[] texts =
48-
{ "My charger isn't working.", "Thanks for reaching out. Can you give me some more detail about the issue?",
49-
"I put my charger in my tablet to charge it up last night and it keeps saying it isn't"
50-
+ " charging. The charging icon comes on, but it stays on even when I take the charger out. "
51-
+ "Which is ridiculous, it's brand new.",
52-
"I'm sorry you're having issues with charging. What kind of charger are you using?" };
47+
private String[] texts = { "My charger isn't working.",
48+
"Thanks for reaching out. Can you give me some more detail about the issue?",
49+
"I put my charger in my tablet to charge it up last night and it keeps saying it isn't"
50+
+ " charging. The charging icon comes on, but it stays on even when I take the charger out. "
51+
+ "Which is ridiculous, it's brand new.",
52+
"I'm sorry you're having issues with charging. What kind of charger are you using?" };
5353

5454
/*
5555
* (non-Javadoc)
56-
*
5756
* @see com.ibm.watson.developer_cloud.WatsonServiceTest#setUp()
5857
*/
5958
@Override
@@ -66,7 +65,7 @@ public void setUp() throws Exception {
6665
Assume.assumeFalse("config.properties doesn't have valid credentials.",
6766
(username == null) || username.equals(PLACEHOLDER));
6867

69-
service = new ToneAnalyzer(VERSION_DATE_2016_05_19);
68+
service = new ToneAnalyzer(VERSION_DATE_VALUE);
7069
service.setUsernameAndPassword(username, getProperty("tone_analyzer.v3.password"));
7170
service.setEndPoint(getProperty("tone_analyzer.v3.url"));
7271
service.setDefaultHeaders(getDefaultHeaders());
@@ -155,7 +154,7 @@ public void testtoneFromHtml() {
155154
private void assertToneAnalysis(ToneAnalysis tone) {
156155
Assert.assertNotNull(tone);
157156
Assert.assertNotNull(tone.getDocumentTone());
158-
Assert.assertEquals(3, tone.getDocumentTone().getToneCategories().size());
157+
Assert.assertEquals(2, tone.getDocumentTone().getTones().size());
159158
Assert.assertNotNull(tone.getSentencesTone());
160159
Assert.assertEquals(4, tone.getSentencesTone().size());
161160
Assert.assertEquals("I know the times are difficult!", tone.getSentencesTone().get(0).getText());
@@ -178,7 +177,6 @@ public void testGetChatTone() {
178177
.utterances(utterances)
179178
.build();
180179

181-
182180
UtteranceAnalyses utterancesTone = service.toneChat(toneChatOptions).execute();
183181

184182
Assert.assertNotNull(utterancesTone);

tone-analyzer/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerTest.java

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,17 @@ public class ToneAnalyzerTest extends WatsonServiceUnitTest {
4848

4949
/** The service. */
5050
private ToneAnalyzer service;
51-
private static final String VERSION_DATE_2016_05_19 = "2016-05-19";
51+
private static final String VERSION_DATE_VALUE = "2017-09-21";
5252

5353
/*
5454
* (non-Javadoc)
55-
*
5655
* @see com.ibm.watson.developer_cloud.WatsonServiceTest#setUp()
5756
*/
5857
@Override
5958
@Before
6059
public void setUp() throws Exception {
6160
super.setUp();
62-
service = new ToneAnalyzer(VERSION_DATE_2016_05_19);
61+
service = new ToneAnalyzer(VERSION_DATE_VALUE);
6362
service.setApiKey("");
6463
service.setEndPoint(getMockWebServerUrl());
6564

@@ -71,25 +70,23 @@ public void setUp() throws Exception {
7170
@Test
7271
public void testReadme() throws InterruptedException, IOException {
7372

74-
// final String VERSION_DATE = "2016-05-19";
7573
ToneAnalyzer service = new ToneAnalyzer(VERSION_DATE);
7674
service.setUsernameAndPassword("<username>", "<password>");
7775

7876
service.setEndPoint(getMockWebServerUrl()); // exclude
7977
ToneAnalysis mockResponse = loadFixture(FIXTURE, ToneAnalysis.class); // exclude
8078
server.enqueue(jsonResponse(mockResponse)); // exclude
8179

82-
String text =
83-
"I know the times are difficult! Our sales have been "
84-
+ "disappointing for the past three quarters for our data analytics "
85-
+ "product suite. We have a competitive data analytics product "
86-
+ "suite in the industry. But we need to do our job selling it! "
87-
+ "We need to acknowledge and fix our sales challenges. "
88-
+ "We can’t blame the economy for our lack of execution! "
89-
+ "We are missing critical sales opportunities. "
90-
+ "Our product is in no way inferior to the competitor products. "
91-
+ "Our clients are hungry for analytical tools to improve their "
92-
+ "business outcomes. Economy has nothing to do with it.";
80+
String text = "I know the times are difficult! Our sales have been "
81+
+ "disappointing for the past three quarters for our data analytics "
82+
+ "product suite. We have a competitive data analytics product "
83+
+ "suite in the industry. But we need to do our job selling it! "
84+
+ "We need to acknowledge and fix our sales challenges. "
85+
+ "We can’t blame the economy for our lack of execution! "
86+
+ "We are missing critical sales opportunities. "
87+
+ "Our product is in no way inferior to the competitor products. "
88+
+ "Our clients are hungry for analytical tools to improve their "
89+
+ "business outcomes. Economy has nothing to do with it.";
9390

9491
// Call the service and get the tone
9592
ToneOptions toneOptions = new ToneOptions.Builder().html(text).build();
@@ -105,7 +102,6 @@ public void testtoneWithNull() {
105102
service.tone(null);
106103
}
107104

108-
109105
/**
110106
* Test get tones.
111107
*
@@ -131,7 +127,7 @@ public void testtones() throws InterruptedException, IOException {
131127
// first request
132128
RecordedRequest request = server.takeRequest();
133129

134-
String path = StringUtils.join(TONE_PATH, "?", VERSION_DATE, "=", VERSION_DATE_2016_05_19);
130+
String path = StringUtils.join(TONE_PATH, "?", VERSION_DATE, "=", VERSION_DATE_VALUE);
135131
assertEquals(path, request.getPath());
136132
assertNotNull(request.getHeader(HttpHeaders.AUTHORIZATION));
137133
assertEquals(serviceResponse, mockResponse);
@@ -168,13 +164,13 @@ public void testGetChatTones() throws IOException, InterruptedException {
168164
String[] users = { "customer", "agent", "customer", "agent" };
169165

170166
String[] texts = {
171-
"My charger isn't working.",
172-
"Thanks for reaching out. Can you give me some more detail about the issue?",
173-
"I put my charger in my tablet to charge it up last night and it keeps saying it isn't"
167+
"My charger isn't working.",
168+
"Thanks for reaching out. Can you give me some more detail about the issue?",
169+
"I put my charger in my tablet to charge it up last night and it keeps saying it isn't"
174170
+ " charging. The charging icon comes on, but it stays on even when I take the charger out. "
175171
+ "Which is ridiculous, it's brand new.",
176-
"I'm sorry you're having issues with charging. What kind of charger are you using?"
177-
};
172+
"I'm sorry you're having issues with charging. What kind of charger are you using?"
173+
};
178174

179175
List<Utterance> utterances = new ArrayList<>();
180176
for (int i = 0; i < texts.length; i++) {
@@ -200,7 +196,7 @@ public void testGetChatTones() throws IOException, InterruptedException {
200196
// first request
201197
RecordedRequest request = server.takeRequest();
202198

203-
String path = StringUtils.join(CHAT_TONE_PATH, "?", VERSION_DATE, "=", VERSION_DATE_2016_05_19);
199+
String path = StringUtils.join(CHAT_TONE_PATH, "?", VERSION_DATE, "=", VERSION_DATE_VALUE);
204200
assertEquals(path, request.getPath());
205201
assertNotNull(request.getHeader(HttpHeaders.AUTHORIZATION));
206202
assertEquals(serviceResponse, mockResponse);

0 commit comments

Comments
 (0)