Skip to content

Commit 785f7bd

Browse files
Merge pull request #726 from watson-developer-cloud/develop
4.0.0 - Code generation
2 parents b6ede13 + f5fe6b5 commit 785f7bd

File tree

434 files changed

+30736
-14057
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

434 files changed

+30736
-14057
lines changed

.config.properties.enc

0 Bytes
Binary file not shown.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ bin/
1717
.gradletasknamecache
1818
docs
1919
.swagger-codegen-ignore
20-
.vscode/
20+
.vscode/
21+
conversation/src/test/java/com/ibm/watson/developer_cloud/conversation/v1/ConversationTest.java

.utility/push-javadoc-to-gh-pages.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" ]; then
44

55
git config --global user.email "[email protected]"
66
git config --global user.name "Watson Github Bot"
7-
git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com/watson-developer-cloud/java-sdk gh-pages > /dev/null
7+
git clone --quiet --branch=gh-pages https://${GITHUB_TOKEN_DOCS}@github.com/watson-developer-cloud/java-sdk gh-pages > /dev/null
88

99
pushd gh-pages
1010
# on tagged builds, $TRAVIS_BRANCH is the tag (e.g. v1.2.3), otherwise it's the branch name (e.g. master)

MIGRATION.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# 4.0
2+
3+
## Conversation
4+
5+
- No old version dates -- just current
6+
- All methods now take options objects, e.g.:
7+
8+
```java
9+
MessageRequest request = new MessageRequest.Builder()
10+
.inputText(message)
11+
.build();
12+
service.message(workspaceId, request).execute();
13+
```
14+
is now:
15+
16+
```java
17+
MessageOptions messageOptions = new MessageOptions.Builder()
18+
.workspaceId(workspaceId)
19+
.input(new InputData.Builder(message).build())
20+
.build();
21+
service.message(messageOptions).execute();
22+
```
23+
- `Context` is now a formal class that extends map.
24+
- Many classes have been renamed - mostly dropping "Response" from classnames.
25+
- `EntityResponse` is now `Entity`
26+
- `ExampleResponse` is now `Example`
27+
- `IntentResponse` is now Intent
28+
- `WorkspaceResponse` is now `Workspace`
29+
30+
_This renaming was done for simplicity and to improve consistency across SDKs going forward._
31+
32+
- Counterexample now has its own classes no longer overloaded on Example
33+
34+
## Tone Analyzer
35+
36+
- The method `getTone()` was replaced with: `tone()`.
37+
38+
For example:
39+
40+
```java
41+
public ServiceCall<ToneAnalysis> getTone(String text, ToneOptions options)
42+
```
43+
44+
Is now:
45+
```java
46+
public ServiceCall<ToneAnalysis> tone(ToneOptions options)
47+
```
48+
49+
`tone()` example:
50+
```java
51+
ToneOptions toneOptions = new ToneOptions.Builder()
52+
.text(text)
53+
.build();
54+
ToneAnalysis tone = service.tone(toneOptions).execute();
55+
```
56+
57+
- The method `getToneChat()` was replaced with: `toneChat()`.
58+
59+
For example:
60+
61+
```java
62+
public ServiceCall<ToneAnalysis> getChatTone(ToneChatRequest options)
63+
```
64+
65+
Is now:
66+
67+
```java
68+
public ServiceCall<UtteranceAnalyses> chatTone(ToneChatOptions options) {
69+
70+
```
71+
72+
`chatTone()` example:
73+
```java
74+
String[] texts = {
75+
"My charger isn't working.",
76+
"Thanks for reaching out. Can you give me some more detail about the issue?",
77+
"I put my charger in my tablet to charge it up last night and it keeps saying it isn't"
78+
+ " charging. The charging icon comes on, but it stays on even when I take the charger out. "
79+
+ "Which is ridiculous, it's brand new.",
80+
"I'm sorry you're having issues with charging. What kind of charger are you using?"
81+
};
82+
83+
List<Utterance> utterances = new ArrayList<>();
84+
for (int i = 0; i < texts.length; i++) {
85+
Utterance utterance = new Utterance.Builder()
86+
.text(texts[i])
87+
.user(users[i])
88+
.build();
89+
utterances.add(utterance);
90+
}
91+
ToneChatOptions toneChatOptions = new ToneChatOptions.Builder()
92+
.utterances(utterances)
93+
.build();
94+
95+
// Call the service
96+
UtteranceAnalyses utterancesTone = service.toneChat(toneChatOptions).execute();
97+
```

README.md

Lines changed: 5 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ APIs and SDKs that use cognitive computing to solve complex problems.
1414
* [Gradle](#gradle)
1515
* [Usage](#usage)
1616
* [Getting the Service Credentials](#getting-the-service-credentials)
17-
* [Android](#android)
1817
* IBM Watson Services
1918
* [Alchemy Language](alchemy)
2019
* [Alchemy Vision](alchemy)
@@ -35,8 +34,7 @@ APIs and SDKs that use cognitive computing to solve complex problems.
3534
* [Tone Analyzer](tone-analyzer)
3635
* [Tradeoff Analytics](tradeoff-analytics)
3736
* [Visual Recognition](visual-recognition)
38-
* [Reactive API call for v3.0.1](#introduce-reactive-api-call-for-v301)
39-
* [Breaking Changes for v3.0](#breaking-changes-for-v30)
37+
* [Changes for v4.0](#changes-for-v40)
4038
* [Using a Proxy](#using-a-proxy)
4139
* [Android](#android)
4240
* [Running in Bluemix](#running-in-bluemix)
@@ -143,103 +141,11 @@ To get your service credentials, follow these steps:
143141
1. On the left side of the page, click **Service Credentials**, and then **View credentials** to view your service credentials.
144142
1. Copy `url`, `username` and `password`(`api_key` for AlchemyAPI or Visual Recognition).
145143

146-
147-
## Introduce reactive API call for v3.0.1
148-
149-
To do a reactive call, you need to add `rx()`. With reactive you can use synchronous or asynchronous calls as you like, and you can combine multiple rest calls more efficiently.
150-
151-
Use callback way
152-
153-
```java
154-
service.getDialogs().rx().thenApply(new CompletableFuture.Fun<List<Dialog>, Integer>() {
155-
@Override
156-
public Integer apply(List<Dialog> dialogs) {
157-
return dialogs.size();
158-
}
159-
}).thenAccept(new CompletableFuture.Action<Integer>() {
160-
@Override
161-
public void accept(Integer integer) {
162-
System.out.println(integer);
163-
}
164-
});
165-
```
166-
167-
Use asynchronous callback way
168-
169-
```java
170-
service.getDialogs().rx().thenApplyAsync(new CompletableFuture.Fun<List<Dialog>, Integer>() {
171-
@Override
172-
public Integer apply(List<Dialog> dialogs) {
173-
return dialogs.size();
174-
}
175-
}).thenAccept(new CompletableFuture.Action<Integer>() {
176-
@Override
177-
public void accept(Integer size) {
178-
System.out.println(size);
179-
}
180-
});
181-
```
182-
183-
Use synchronous way
184-
185-
```java
186-
Integer size=service.getDialogs().rx().get().size();
187-
System.out.println(size);
188-
```
189-
190-
## Breaking Changes for v3.0
191-
192-
The version 3.0 is a major release focused on simplicity and consistency. Several breaking changes were introduced.
193-
194-
### Synchronous vs. Asynchronous
195-
196-
Before 3.0 all the API calls were synchronous.
197-
198-
```java
199-
List<Dialog> dialogs = dialogService.getDialogs();
200-
System.out.println(dialogs);
201-
```
202-
203-
To do a synchronous call, you need to add `execute()`.
204-
205-
```java
206-
List<Dialog> dialogs = dialogService.getDialogs().execute();
207-
System.out.println(dialogs);
208-
```
209-
210-
To do an asynchronous call, you need to specify a callback.
211-
212-
```java
213-
service.getDialogs().enqueue(new ServiceCallback<List<Dialog>>() {
214-
@Override
215-
public void onResponse(List<Dialog> response) {
216-
System.out.println(response);
217-
}
218-
219-
@Override
220-
public void onFailure(Exception e) {
221-
}}
222-
);
223-
```
224-
225-
See the [CHANGELOG](CHANGELOG.md) for the release notes.
144+
## Changes for v4.0
145+
Version 4.0 focuses on the move to programmatically-generated code for many of the services. See the [changelog](https://github.com/watson-developer-cloud/java-sdk/wiki/Changelog) for the details.
226146

227147
## Migration
228-
229-
To migrate to 3.0 from a previous version, simply add `.execute()` to the old methods.
230-
For example if you previously had
231-
232-
```java
233-
List<Dialog> dialogs = dialogService.getDialogs();
234-
System.out.println(dialogs);
235-
```
236-
237-
Just add `execute()` on the end, and your code will work exactly the same as before.
238-
239-
```java
240-
List<Dialog> dialogs = dialogService.getDialogs().execute();
241-
System.out.println(dialogs);
242-
```
148+
This version includes many breaking changes as a result of standardizing behavior across the new generated services. Full details on migration from previous versions can be found [here](https://github.com/watson-developer-cloud/java-sdk/wiki/Migration).
243149

244150
## Android
245151

@@ -305,7 +211,7 @@ For example, if you have the conversation service in Germany, the Endpoint may b
305211
You will need to call
306212

307213
```java
308-
Conversation service = new Conversation("<version-date>");
214+
ConversationService service = new ConversationService("<version-date>");
309215
service.sentEndPoint("https://gateway-fra.watsonplatform.net/conversation/api")
310216
```
311217

conversation/README.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,38 @@
2121
Use the [Conversation][conversation] service to identify intents, entities, and conduct conversations.
2222

2323
```java
24-
ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2017_03_02);
24+
ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2017_05_26);
2525
service.setUsernameAndPassword("<username>", "<password>");
2626

27-
MessageRequest newMessage = new MessageRequest.Builder().inputText("Hi").build();
28-
MessageResponse response = service.message("<workspace-id>", newMessage).execute();
27+
InputData input = new InputData.Builder("Hi").build();
28+
MessageOptions options = new MessageOptions.Builder(workspaceId).input(input).build();
29+
MessageResponse response = service.message(options).execute();
30+
System.out.println(response);
31+
```
32+
33+
Moving from Node 1 to Node 2.
34+
35+
```java
36+
Context context = null;
37+
38+
// first message
39+
MessageOptions newMessageOptions = new MessageOptions.Builder()
40+
.workspaceId("<workspace-id>")
41+
.input(new InputData.Builder("First message").build())
42+
.context(context)
43+
.build();
44+
45+
MessageResponse response = service.message(newMessageOptions).execute();
46+
47+
// second message
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();
53+
54+
response = service.message(newMessageOptions).execute();
55+
2956
System.out.println(response);
3057
```
3158

0 commit comments

Comments
 (0)