Skip to content

Commit ee0ac15

Browse files
😒 update javadoc and organize imports for tone example
1 parent 06a03b5 commit ee0ac15

File tree

2 files changed

+72
-90
lines changed

2 files changed

+72
-90
lines changed

examples/java/com/ibm/watson/developer_cloud/conversation_tone_analyzer_integration/v1/ConversationToneAnalyzerIntegrationExample.java

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
11
/**
22
* Copyright 2015 IBM Corp. All Rights Reserved.
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
76
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0
98
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
1512
*/
16-
package com.ibm.watson.developer_cloud.conversation.v1;
13+
package com.ibm.watson.developer_cloud.conversation_tone_analyzer_integration.v1;
1714

1815
import java.util.HashMap;
1916
import java.util.Map;
2017

18+
import com.ibm.watson.developer_cloud.conversation.v1.ConversationService;
2119
import com.ibm.watson.developer_cloud.conversation.v1.model.MessageRequest;
2220
import com.ibm.watson.developer_cloud.conversation.v1.model.MessageResponse;
23-
import com.ibm.watson.developer_cloud.conversation.v1.ConversationService;
2421
import com.ibm.watson.developer_cloud.http.ServiceCallback;
25-
import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.*;
2622
import com.ibm.watson.developer_cloud.tone_analyzer.v3.ToneAnalyzer;
27-
28-
import com.ibm.watson.developer_cloud.conversation.v1.ToneDetection;
23+
import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneAnalysis;
2924

3025
/**
31-
* Example of how to call the
32-
* {@link ConversationService#message(String, MessageRequest)} method
33-
* synchronous, asynchronous, and using react.
34-
*
26+
* Example of how to call the {@link ConversationService#message(String, MessageRequest)} method synchronous,
27+
* asynchronous, and using react.
28+
*
3529
* @version v1
3630
*/
3731
public class ConversationToneAnalyzerIntegrationExample {
@@ -55,11 +49,9 @@ public static void main(String[] args) throws Exception {
5549
Boolean maintainHistory = false;
5650

5751
/**
58-
* Input for the conversation service: input (String): an input string (the
59-
* user's conversation turn) and context (Map<String,Object>: any context
60-
* that needs to be maintained - either added by the client app or passed in
61-
* the response from the conversation service on the previous conversation
62-
* turn.
52+
* Input for the conversation service: input (String): an input string (the user's conversation turn) and context
53+
* (Map<String,Object>: any context that needs to be maintained - either added by the client app or passed in the
54+
* response from the conversation service on the previous conversation turn.
6355
*/
6456
String input = "I am happy";
6557
Map<String, Object> context = new HashMap<String, Object>();
@@ -87,14 +79,12 @@ public void onResponse(MessageResponse response) {
8779
}
8880

8981
@Override
90-
public void onFailure(Exception e) {
91-
}
82+
public void onFailure(Exception e) { }
9283
});
9384
}
9485

9586
@Override
96-
public void onFailure(Exception e) {
97-
}
87+
public void onFailure(Exception e) { }
9888
});
9989
}
10090
}

examples/java/com/ibm/watson/developer_cloud/conversation_tone_analyzer_integration/v1/ToneDetection.java

Lines changed: 55 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
/**
22
* Copyright 2015 IBM Corp. All Rights Reserved.
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
76
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0
98
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
1512
*/
16-
package com.ibm.watson.developer_cloud.conversation.v1;
13+
package com.ibm.watson.developer_cloud.conversation_tone_analyzer_integration.v1;
1714

1815
import java.util.ArrayList;
1916
import java.util.HashMap;
@@ -24,14 +21,16 @@
2421
import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneCategory;
2522
import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneScore;
2623

24+
/**
25+
* ToneDetection.
26+
*/
2727
public class ToneDetection {
2828

2929
/**
30-
* Thresholds for identifying meaningful tones returned by the Watson Tone
31-
* Analyzer. Current values are based on the recommendations made by the
32-
* Watson Tone Analyzer at
33-
* https://www.ibm.com/watson/developercloud/doc/tone-analyzer/understanding-tone.shtml
34-
* These thresholds can be adjusted to client/domain requirements.
30+
* Thresholds for identifying meaningful tones returned by the Watson Tone Analyzer. Current values are based on the
31+
* recommendations made by the Watson Tone Analyzer at
32+
* https://www.ibm.com/watson/developercloud/doc/tone-analyzer/understanding-tone.shtml These thresholds can be
33+
* adjusted to client/domain requirements.
3534
*/
3635
private static final Double PRIMARY_EMOTION_SCORE_THRESHOLD = 0.5;
3736
private static final Double LANGUAGE_HIGH_SCORE_THRESHOLD = 0.75;
@@ -40,24 +39,28 @@ public class ToneDetection {
4039
private static final Double SOCIAL_LOW_SCORE_THRESHOLD = 0.25;
4140

4241
/**
43-
* Labels for the tone categories returned by the Watson Tone Analyzer
42+
* Instantiates a new tone detection.
43+
*/
44+
private ToneDetection() { }
45+
46+
/**
47+
* Labels for the tone categories returned by the Watson Tone Analyzer.
4448
*/
4549
private static final String EMOTION_TONE_LABEL = "emotion_tone";
4650
private static final String LANGUAGE_TONE_LABEL = "language_tone";
4751
private static final String SOCIAL_TONE_LABEL = "social_tone";
4852

4953
/**
50-
* updateUserTone processes the Tone Analyzer payload to pull out the emotion,
51-
* language and social tones, and identify the meaningful tones (i.e., those
52-
* tones that meet the specified thresholds). The conversationPayload json
53-
* object is updated to include these tones.
54-
*
55-
* @param conversationPayload
56-
* json object returned by the Watson Conversation Service
57-
* @param toneAnalyzerPayload
58-
* json object returned by the Watson Tone Analyzer Service
59-
* @returns conversationPayload where the user object has been updated with
60-
* tone information from the toneAnalyzerPayload
54+
* updateUserTone processes the Tone Analyzer payload to pull out the emotion, language and social tones, and identify
55+
* the meaningful tones (i.e., those tones that meet the specified thresholds). The conversationPayload json object is
56+
* updated to include these tones.
57+
*
58+
* @param context the context
59+
* @param toneAnalyzerPayload json object returned by the Watson Tone Analyzer Service
60+
* @param maintainHistory the maintain history
61+
* @return the map
62+
* @returns conversationPayload where the user object has been updated with tone information from the
63+
* toneAnalyzerPayload
6164
*/
6265
public static Map<String, Object> updateUserTone(Map<String, Object> context, ToneAnalysis toneAnalyzerPayload,
6366
Boolean maintainHistory) {
@@ -100,13 +103,12 @@ public static Map<String, Object> updateUserTone(Map<String, Object> context, To
100103
}
101104

102105
/**
103-
* initUser initializes a user containing tone data (from the Watson Tone
104-
* Analyzer)
105-
*
106-
* @returns user with the emotion, language and social tones. The current tone
107-
* identifies the tone for a specific conversation turn, and the
108-
* history provides the conversation for all tones up to the current
109-
* tone for a conversation instance with a user.
106+
* initUser initializes a user containing tone data (from the Watson Tone Analyzer).
107+
*
108+
* @return the map
109+
* @returns user with the emotion, language and social tones. The current tone identifies the tone for a specific
110+
* conversation turn, and the history provides the conversation for all tones up to the current tone for a
111+
* conversation instance with a user.
110112
*/
111113
public static Map<String, Object> initUser() {
112114

@@ -132,16 +134,12 @@ public static Map<String, Object> initUser() {
132134
}
133135

134136
/**
135-
* updateEmotionTone updates the user emotion tone with the primary emotion -
136-
* the emotion tone that has a score greater than or equal to the
137-
* EMOTION_SCORE_THRESHOLD; otherwise primary emotion will be 'neutral'
138-
*
139-
* @param user
140-
* a json object representing user information (tone) to be used in
141-
* conversing with the Conversation Service
142-
* @param emotionTone
143-
* a json object containing the emotion tones in the payload returned
144-
* by the Tone Analyzer
137+
* updateEmotionTone updates the user emotion tone with the primary emotion - the emotion tone that has a score
138+
* greater than or equal to the EMOTION_SCORE_THRESHOLD; otherwise primary emotion will be 'neutral'.
139+
*
140+
* @param user a json object representing user information (tone) to be used in conversing with the Conversation
141+
* Service
142+
* @param emotionTone a json object containing the emotion tones in the payload returned by the Tone Analyzer
145143
*/
146144
@SuppressWarnings("unchecked")
147145
private static void updateEmotionTone(Map<String, Object> user, List<ToneScore> emotionTone,
@@ -184,16 +182,13 @@ private static void updateEmotionTone(Map<String, Object> user, List<ToneScore>
184182
}
185183

186184
/**
187-
* updateLanguageTone updates the user with the language tones interpreted
188-
* based on the specified thresholds
189-
*
190-
* @param user
191-
* a json object representing user information (tone) to be used in
192-
* conversing with the Conversation Service
193-
* @param languageTone
194-
* a json object containing the language tones in the payload
195-
* returned by the Tone Analyzer
185+
* updateLanguageTone updates the user with the language tones interpreted based on the specified thresholds.
186+
*
187+
* @param user a json object representing user information (tone) to be used in conversing with the Conversation
188+
* Service
189+
* @param languageTone a json object containing the language tones in the payload returned by the Tone Analyzer
196190
*/
191+
@SuppressWarnings("unchecked")
197192
private static void updateLanguageTone(Map<String, Object> user, List<ToneScore> languageTone,
198193
Boolean maintainHistory) {
199194

@@ -219,7 +214,6 @@ private static void updateLanguageTone(Map<String, Object> user, List<ToneScore>
219214
}
220215

221216
// update user language tone
222-
@SuppressWarnings("unchecked")
223217
Map<String, Object> language = (Map<String, Object>) ((Map<String, Object>) user.get("tone")).get("language");
224218

225219
// the current language pulled from tone
@@ -237,16 +231,14 @@ private static void updateLanguageTone(Map<String, Object> user, List<ToneScore>
237231
}
238232

239233
/**
240-
* updateSocialTone updates the user with the social tones interpreted based
241-
* on the specified thresholds
242-
*
243-
* @param user
244-
* a json object representing user information (tone) to be used in
245-
* conversing with the Conversation Service
246-
* @param socialTone
247-
* a json object containing the social tones in the payload returned
248-
* by the Tone Analyzer
234+
* updateSocialTone updates the user with the social tones interpreted based on the specified thresholds.
235+
*
236+
* @param user a json object representing user information (tone) to be used in conversing with the Conversation
237+
* Service
238+
* @param socialTone a json object containing the social tones in the payload returned by the Tone Analyzer
239+
* @param maintainHistory the maintain history
249240
*/
241+
@SuppressWarnings("unchecked")
250242
public static void updateSocialTone(Map<String, Object> user, List<ToneScore> socialTone, Boolean maintainHistory) {
251243

252244
List<String> currentSocial = new ArrayList<String>();

0 commit comments

Comments
 (0)