Skip to content

Commit 35adaf9

Browse files
committed
Update README examples
1 parent be7c9f2 commit 35adaf9

5 files changed

Lines changed: 55 additions & 39 deletions

File tree

‎conversation/README.md‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,25 @@ System.out.println(response);
3333
Moving from Node 1 to Node 2.
3434

3535
```java
36-
37-
Map<String, Object> context = new HashMap<String, Object>();
36+
Context context = null;
3837

3938
// first message
40-
MessageRequest newMessage = new MessageRequest.Builder()
41-
.input(new InputData.Builder("First message").build())
42-
.context(context)
43-
.build();
39+
MessageOptions newMessageOptions = new MessageOptions.Builder()
40+
.workspaceId("<workspace-id>")
41+
.input(new InputData.Builder("First message").build())
42+
.context(context)
43+
.build();
4444

45-
MessageResponse response = service.message("<workspace-id>", newMessage).execute();
45+
MessageResponse response = service.message(newMessageOptions).execute();
4646

4747
// second message
48-
newMessage = new MessageRequest.Builder()
49-
.input(new InputData.Builder("Second message").build())
50-
.context(response.getContext()) // output context from the first message
51-
.build();
48+
newMessageOptions = new MessageOptions.Builder()
49+
.workspaceId("<workspace-id>")
50+
.input(new InputData.Builder("Second message").build())
51+
.context(response.getContext()) // output context from the first message
52+
.build();
5253

53-
response = service.message("<workspace-id>", newMessage).execute();
54+
response = service.message(newMessageOptions).execute();
5455

5556
System.out.println(response);
5657
```

‎examples/conversation_tone_analyzer_integration/src/main/java/com/ibm/watson/developer_cloud/conversation_tone_analyzer_integration/v1/ToneConversationIntegrationV1.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneAnalysis;
2727

2828
/**
29-
* Example of how to call the {@link ConversationService#message(String, MessageRequest)}
29+
* Example of how to call the {@link ConversationService#message(String, MessageRequest)}
3030
* method asynchronously.
3131
*
3232
* @version v1
@@ -37,19 +37,20 @@ public static void main(String[] args) throws Exception {
3737

3838
// load the properties file
3939
Properties props = new Properties();
40-
props.load(FileUtils.openInputStream(new File("tone_conversation_integration.properties")));
40+
props.load(FileUtils.openInputStream(new File("tone_conversation_integration.properties.example")));
4141

4242
// instantiate the conversation service
43-
ConversationService conversationService = new ConversationService(ConversationService.VERSION_DATE_2016_07_11);
43+
final ConversationService conversationService = new ConversationService(ConversationService
44+
.VERSION_DATE_2016_07_11);
4445
conversationService.setUsernameAndPassword(
45-
props.getProperty("CONVERSATION_USERNAME", "<conversation_username>"),
46+
props.getProperty("CONVERSATION_USERNAME", "<conversation_username>"),
4647
props.getProperty("CONVERSATION_PASSWORD", "<conversation_password>")
4748
);
4849

4950
// instantiate the tone analyzer service
5051
ToneAnalyzer toneService = new ToneAnalyzer(ToneAnalyzer.VERSION_DATE_2016_05_19);
5152
toneService.setUsernameAndPassword(
52-
props.getProperty("TONE_ANALYZER_USERNAME", "<tone_analyzer_username>"),
53+
props.getProperty("TONE_ANALYZER_USERNAME", "<tone_analyzer_username>"),
5354
props.getProperty("TONE_ANALYZER_PASSWORD", "<tone_analyzer_password>")
5455
);
5556

‎speech-to-text/README.md‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ service.setUsernameAndPassword("<username>", "<password>");
2525

2626
File audio = new File("src/test/resources/sample1.wav");
2727

28-
SpeechResults transcript = service.recognize(audio, HttpMediaType.AUDIO_WAV).execute();
28+
RecognizeOptions options = new RecognizeOptions.Builder()
29+
.contentType(HttpMediaType.AUDIO_WAV)
30+
.build();
31+
32+
SpeechResults transcript = service.recognize(audio, options).execute();
2933
System.out.println(transcript);
3034
```
3135

@@ -38,21 +42,22 @@ Speech to Text supports WebSocket, the url is:
3842
SpeechToText service = new SpeechToText();
3943
service.setUsernameAndPassword("<username>", "<password>");
4044

41-
File audio = new File("src/test/resources/sample1.wav");
45+
InputStream audio = new FileInputStream("src/test/resources/sample1.wav");
4246

4347
RecognizeOptions options = new RecognizeOptions.Builder()
44-
.interimResults(true)
45-
.contentType(HttpMediaType.AUDIO_WAV)
46-
.build();
48+
.interimResults(true)
49+
.contentType(HttpMediaType.AUDIO_WAV)
50+
.build();
51+
52+
service.recognizeUsingWebSocket(audio, options, new BaseRecognizeCallback() {
53+
@Override
54+
public void onTranscription(SpeechResults speechResults) {
55+
System.out.println(speechResults);
56+
}
57+
});
4758

48-
service.recognizeUsingWebSocket(audio, options, new BaseRecognizeCallback() {
49-
@Override
50-
public void onTranscription(SpeechResults speechResults) {
51-
System.out.println(speechResults);
52-
}
53-
);
54-
// wait 20 seconds for the asynchronous response
55-
Thread.sleep(20000);
59+
// wait 20 seconds for the asynchronous response
60+
Thread.sleep(20000);
5661
```
5762
#### Microphone example
5863
Use your microphone to recognize audio for 30 seconds.

‎tradeoff-analytics/README.md‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,18 @@ String screen = "screen";
3434
List<Column> columns = new ArrayList<Column>();
3535
problem.setColumns(columns);
3636

37-
columns.add(new NumericColumn().withRange(0, 100).withKey(price).withGoal(Goal.MIN).withObjective(true));
38-
columns.add(new NumericColumn().withKey(screen).withGoal(Goal.MAX).withObjective(true));
39-
columns.add(new NumericColumn().withKey(ram).withGoal(Goal.MAX));
37+
columns.add(new NumericColumn()
38+
.range(0, 100)
39+
.key(price)
40+
.goal(Goal.MIN)
41+
.objective(true));
42+
columns.add(new NumericColumn()
43+
.key(screen)
44+
.goal(Goal.MAX)
45+
.objective(true));
46+
columns.add(new NumericColumn()
47+
.key(ram)
48+
.goal(Goal.MAX));
4049

4150
// Define the options to choose
4251
List<Option> options = new ArrayList<Option>();
@@ -46,19 +55,19 @@ HashMap<String, Object> galaxySpecs = new HashMap<String, Object>();
4655
galaxySpecs.put(price, 50);
4756
galaxySpecs.put(ram, 45);
4857
galaxySpecs.put(screen, 5);
49-
options.add(new Option("1", "Galaxy S4").withValues(galaxySpecs));
58+
options.add(new Option("1", "Galaxy S4").values(galaxySpecs));
5059

5160
HashMap<String, Object> iphoneSpecs = new HashMap<String, Object>();
5261
iphoneSpecs.put(price, 99);
5362
iphoneSpecs.put(ram, 40);
5463
iphoneSpecs.put(screen, 4);
55-
options.add(new Option("2", "iPhone 5").withValues(iphoneSpecs));
64+
options.add(new Option("2", "iPhone 5").values(iphoneSpecs));
5665

5766
HashMap<String, Object> optimusSpecs = new HashMap<String, Object>();
5867
optimusSpecs.put(price, 10);
5968
optimusSpecs.put(ram, 300);
6069
optimusSpecs.put(screen, 5);
61-
options.add(new Option("3", "LG Optimus G").withValues(optimusSpecs));
70+
options.add(new Option("3", "LG Optimus G").values(optimusSpecs));
6271

6372
// Call the service and get the resolution
6473
Dilemma dilemma = service.dilemmas(problem).execute();

‎visual-recognition/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ VisualRecognition service = new VisualRecognition(VisualRecognition.VERSION_DATE
2727
service.setApiKey("<api-key>");
2828

2929
System.out.println("Classify an image");
30-
ClassifyImagesOptions options = new ClassifyImagesOptions.Builder()
31-
.images(new File("src/test/resources/visual_recognition/car.png"))
30+
ClassifyOptions options = new ClassifyOptions.Builder()
31+
.imagesFile(new File(SINGLE_IMAGE_FILE))
3232
.build();
33-
VisualClassification result = service.classify(options).execute();
33+
ClassifiedImages result = service.classify(options).execute();
3434
System.out.println(result);
3535
```
3636

0 commit comments

Comments
 (0)