Skip to content

Commit

Permalink
feat(examples): generated code
Browse files Browse the repository at this point in the history
chore(examples): manual changes
  • Loading branch information
germanattanasio committed Feb 24, 2020
1 parent cae0d2c commit 2d93247
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public void onResponse(Response<MessageResponse> response) {
}

@Override
public void onFailure(Exception e) { }
public void onFailure(Exception e) {
}
});

// RxJava
Single<Response<MessageResponse>> observableRequest
= service.message(options).reactiveRequest();
Single<Response<MessageResponse>> observableRequest = service.message(options).reactiveRequest();
observableRequest
.subscribeOn(Schedulers.single())
.subscribe(new Consumer<Response<MessageResponse>>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.ibm.cloud.sdk.core.http.Response;
import com.ibm.cloud.sdk.core.http.ServiceCallback;


/**
* Example of how to integrate the Watson Assistant and Tone Analyzer services.
*/
Expand Down Expand Up @@ -91,12 +90,14 @@ public void onResponse(Response<MessageResponse> response) {
}

@Override
public void onFailure(Exception e) { }
public void onFailure(Exception e) {
}
});
}

@Override
public void onFailure(Exception e) { }
public void onFailure(Exception e) {
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ToneDetection {
/**
* Thresholds for identifying meaningful tones returned by the Watson Tone Analyzer. Current values are based on the
* recommendations made by the Watson Tone Analyzer at
* https://cloud.ibm.com/docs/services/tone-analyzer?topic=tone-analyzer-utgpe These thresholds can be
* https://cloud.ibm.com/docs/tone-analyzer?topic=tone-analyzer-utgpe These thresholds can be
* adjusted to client/domain requirements.
*/
private static final Double PRIMARY_EMOTION_SCORE_THRESHOLD = 0.5;
Expand All @@ -41,7 +41,8 @@ public class ToneDetection {
/**
* Instantiates a new tone detection.
*/
private ToneDetection() { }
private ToneDetection() {
}

/**
* Labels for the tone categories returned by the Watson Tone Analyzer.
Expand Down Expand Up @@ -138,7 +139,7 @@ public static Map<String, Object> initUser() {
* greater than or equal to the EMOTION_SCORE_THRESHOLD; otherwise primary emotion will be 'neutral'.
*
* @param user a json object representing user information (tone) to be used in conversing with the Assistant
* Service
* Service
* @param emotionTone a json object containing the emotion tones in the payload returned by the Tone Analyzer
*/
@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -185,7 +186,7 @@ private static void updateEmotionTone(Map<String, Object> user, List<ToneScore>
* updateLanguageTone updates the user with the language tones interpreted based on the specified thresholds.
*
* @param user a json object representing user information (tone) to be used in conversing with the Assistant
* Service
* Service
* @param languageTone a json object containing the language tones in the payload returned by the Tone Analyzer
*/
@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -234,7 +235,7 @@ private static void updateLanguageTone(Map<String, Object> user, List<ToneScore>
* updateSocialTone updates the user with the social tones interpreted based on the specified thresholds.
*
* @param user a json object representing user information (tone) to be used in conversing with the Assistant
* Service
* Service
* @param socialTone a json object containing the social tones in the payload returned by the Tone Analyzer
* @param maintainHistory the maintain history
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static void main(String[] args) {
String environmentName = "watson_developer_cloud_test_environment";
CreateEnvironmentOptions createOptions = new CreateEnvironmentOptions.Builder()
.name(environmentName)
.size(0L) /* FREE */
.size(0L) /* FREE */
.build();
Environment createResponse = discovery.createEnvironment(createOptions).execute().getResult();
environmentId = createResponse.getEnvironmentId();
Expand All @@ -97,8 +97,8 @@ public static void main(String[] args) {
//find the default configuration
System.out.println("Finding the default configuration");
ListConfigurationsOptions listConfigsOptions = new ListConfigurationsOptions.Builder(environmentId).build();
ListConfigurationsResponse listConfigsResponse
= discovery.listConfigurations(listConfigsOptions).execute().getResult();
ListConfigurationsResponse listConfigsResponse = discovery.listConfigurations(listConfigsOptions).execute()
.getResult();
for (Configuration configuration : listConfigsResponse.getConfigurations()) {
if (configuration.getName().equals(DEFAULT_CONFIG_NAME)) {
configurationId = configuration.getConfigurationId();
Expand All @@ -110,10 +110,9 @@ public static void main(String[] args) {
//create a new collection
System.out.println("Creating a new collection...");
String collectionName = "my_watson_developer_cloud_collection";
CreateCollectionOptions createCollectionOptions =
new CreateCollectionOptions.Builder(environmentId, collectionName)
.configurationId(configurationId)
.build();
CreateCollectionOptions createCollectionOptions = new CreateCollectionOptions.Builder(environmentId, collectionName)
.configurationId(configurationId)
.build();
Collection collection = discovery.createCollection(createCollectionOptions).execute().getResult();
collectionId = collection.getCollectionId();
System.out.println("Created a collection ID: " + collectionId);
Expand All @@ -122,8 +121,7 @@ public static void main(String[] args) {
System.out.println("Waiting for collection to be ready...");
boolean collectionReady = false;
while (!collectionReady) {
GetCollectionOptions getCollectionOptions =
new GetCollectionOptions.Builder(environmentId, collectionId).build();
GetCollectionOptions getCollectionOptions = new GetCollectionOptions.Builder(environmentId, collectionId).build();
Collection getCollectionResponse = discovery.getCollection(getCollectionOptions).execute().getResult();
collectionReady = getCollectionResponse.getStatus().equals(Collection.Status.ACTIVE);
try {
Expand All @@ -141,20 +139,19 @@ public static void main(String[] args) {
String documentJson = "{\"field\":\"value\"}";
InputStream documentStream = new ByteArrayInputStream(documentJson.getBytes());

AddDocumentOptions.Builder createDocumentBuilder =
new AddDocumentOptions.Builder(environmentId, collectionId);
AddDocumentOptions.Builder createDocumentBuilder = new AddDocumentOptions.Builder(environmentId, collectionId);
createDocumentBuilder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
DocumentAccepted createDocumentResponse
= discovery.addDocument(createDocumentBuilder.build()).execute().getResult();
DocumentAccepted createDocumentResponse = discovery.addDocument(createDocumentBuilder.build()).execute()
.getResult();
documentId = createDocumentResponse.getDocumentId();
System.out.println("Created a document ID: " + documentId);

//wait for document to be ready
System.out.println("Waiting for document to be ready...");
boolean documentReady = false;
while (!documentReady) {
GetDocumentStatusOptions getDocumentStatusOptions =
new GetDocumentStatusOptions.Builder(environmentId, collectionId, documentId).build();
GetDocumentStatusOptions getDocumentStatusOptions = new GetDocumentStatusOptions.Builder(environmentId,
collectionId, documentId).build();
DocumentStatus getDocumentResponse = discovery.getDocumentStatus(getDocumentStatusOptions).execute().getResult();
documentReady = !getDocumentResponse.getStatus().equals(DocumentStatus.Status.PROCESSING);
try {
Expand All @@ -179,8 +176,7 @@ public static void main(String[] args) {

//cleanup the collection created
System.out.println("Deleting the collection...");
DeleteCollectionOptions deleteOptions =
new DeleteCollectionOptions.Builder(environmentId, collectionId).build();
DeleteCollectionOptions deleteOptions = new DeleteCollectionOptions.Builder(environmentId, collectionId).build();
discovery.deleteCollection(deleteOptions).execute();
System.out.println("Collection deleted!");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ public static void main(String[] args) throws InterruptedException, FileNotFound
.customizationId(id)
.corpusName("corpus-1")
.build();
for (
int x = 0;
x < 30 && !service.getCorpus(getOptions).execute().getResult().getStatus().equals(Corpus.Status.ANALYZED);
x++
) {
for (int x = 0; x < 30 && !service.getCorpus(getOptions).execute().getResult().getStatus().equals(
Corpus.Status.ANALYZED); x++) {
Thread.sleep(5000);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ private void cleanFinal() {

}


private static CountDownLatch lock = new CountDownLatch(1);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

public class ToneAnalyzerExample {


public static void main(String[] args) {
Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
ToneAnalyzer service = new ToneAnalyzer("2017-09-21", authenticator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public static void main(String[] args) throws FileNotFoundException {
ClassifiedImages result = service.classify(options).execute().getResult();
System.out.println(result);


System.out.println("Create a classifier with positive and negative images");
CreateClassifierOptions createOptions = new CreateClassifierOptions.Builder()
.name("foo")
Expand Down

0 comments on commit 2d93247

Please sign in to comment.