GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - mashmn/java-sdk: :bowtie: Java SDK to use the IBM Watson services. It supports Android.

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

1,604 Commits
1,604 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.utility
.utility
 
 
alchemy
alchemy
 
 
android-utils
android-utils
 
 
conversation
conversation
 
 
core
core
 
 
dialog
dialog
 
 
discovery
discovery
 
 
document-conversion
document-conversion
 
 
examples
examples
 
 
gradle/wrapper
gradle/wrapper
 
 
java-sdk
java-sdk
 
 
language-translation
language-translation
 
 
language-translator
language-translator
 
 
natural-language-classifier
natural-language-classifier
 
 
natural-language-understanding
natural-language-understanding
 
 
personality-insights
personality-insights
 
 
retrieve-and-rank
retrieve-and-rank
 
 
speech-to-text
speech-to-text
 
 
text-to-speech
text-to-speech
 
 
tone-analyzer
tone-analyzer
 
 
tradeoff-analytics
tradeoff-analytics
 
 
visual-recognition
visual-recognition
 
 
.config.properties.enc
.config.properties.enc
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
RELEASE.md
RELEASE.md
 
 
build.gradle
build.gradle
 
 
checkstyle.xml
checkstyle.xml
 
 
gradle.properties
gradle.properties
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
settings.gradle
settings.gradle
 
 
utils.gradle
utils.gradle
 
 

Repository files navigation

Watson Developer Cloud Java SDK

Build Status Maven Central CLA assistant

The Java SDK uses the Watson Developer Cloud services, a collection of REST APIs and SDKs that use cognitive computing to solve complex problems.

Table of Contents

  • Installation
    • Maven
    • Gradle
  • Usage
  • Getting the Service Credentials
  • Questions
  • Android
  • IBM Watson Services
    • Alchemy Language
    • Alchemy Vision
    • Alchemy Data News
    • Concept Insights
    • Conversation
    • Dialog
    • Discovery
    • Document Conversion
    • Language Translation
    • Language Translator
    • Natural Language Classifier
    • Natural Language Understanding
    • Personality Insights
    • Retrieve and Rank
    • Speech to Text
    • Text to Speech
    • Tone Analyzer
    • Tradeoff Analytics
    • Visual Recognition
  • Reactive API call for v3.0.1
  • Breaking Changes for v3.0
  • Android
  • Running in Bluemix
  • Default Headers
  • Eclipse and Intellij
  • License
  • Contributing

Installation

Maven

All the services:

<dependency>
	<groupId>com.ibm.watson.developer_cloud</groupId>
	<artifactId>java-sdk</artifactId>
	<version>3.7.0</version>
</dependency>

Only Retrieve and Rank:

<dependency>
	<groupId>com.ibm.watson.developer_cloud</groupId>
	<artifactId>retrieve-and-rank</artifactId>
	<version>3.7.0</version>
</dependency>
Gradle

All the services:

'com.ibm.watson.developer_cloud:java-sdk:3.7.0'

Only Retrieve and Rank:

'com.ibm.watson.developer_cloud:retrieve-and-rank:3.7.0'

Only Visual Recognition:

'com.ibm.watson.developer_cloud:visual-recognition:3.7.0'

Snapshots of the development version are available in Sonatype's snapshots repository.

JAR

Download the jar with dependencies here.

Now, you are ready to see some examples.

Usage

The examples within each service assume that you already have service credentials. If not, you will have to create a service in Bluemix.

If you are running your application in Bluemix, you don't need to specify the credentials; the library will get them for you by looking at the VCAP_SERVICES environment variable.

Getting the Service Credentials

You will need the username and password (api_key for AlchemyAPI) credentials for each service. Service credentials are different from your Bluemix account username and password.

To get your service credentials, follow these steps:

  1. Log in to Bluemix at https://bluemix.net.

  2. Create an instance of the service:

    1. In the Bluemix Catalog, select the service you want to use.
    2. Under Add Service, type a unique name for the service instance in the Service name field. For example, type my-service-name. Leave the default values for the other options.
    3. Click Create.
  3. Copy your credentials:

    1. On the left side of the page, click Service Credentials to view your service credentials.
    2. Copy username and password(api_key for AlchemyAPI).

Once you have credentials, copy config.properties.example to src/test/resources/config.properties, and fill them in as necessary.

Questions

If you are having difficulties using the APIs or you have a question about the IBM Watson Services, please ask a question on dW Answers or Stack Overflow.

Introduce reactive API call for v3.0.1

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.

Use callback way

service.getDialogs().rx().thenApply(new CompletableFuture.Fun<List<Dialog>, Integer>() {
  @Override
  public Integer apply(List<Dialog> dialogs) {
    return dialogs.size();
  }
}).thenAccept(new CompletableFuture.Action<Integer>() {
  @Override
  public void accept(Integer integer) {
    System.out.println(integer);
  }
});

Use asynchronous callback way

service.getDialogs().rx().thenApplyAsync(new CompletableFuture.Fun<List<Dialog>, Integer>() {
  @Override
  public Integer apply(List<Dialog> dialogs) {
    return dialogs.size();
  }
}).thenAccept(new CompletableFuture.Action<Integer>() {
  @Override
  public void accept(Integer size) {
    System.out.println(size);
  }
});

Use synchronous way

Integer size=service.getDialogs().rx().get().size();
System.out.println(size);

Breaking Changes for v3.0

The version 3.0 is a major release focused on simplicity and consistency. Several breaking changes were introduced.

Synchronous vs. Asynchronous

Before 3.0 all the API calls were synchronous.

List<Dialog> dialogs = dialogService.getDialogs();
System.out.println(dialogs);

To do a synchronous call, you need to add execute().

List<Dialog> dialogs = dialogService.getDialogs().execute();
System.out.println(dialogs);

To do an asynchronous call, you need to specify a callback.

service.getDialogs().enqueue(new ServiceCallback<List<Dialog>>() {
  @Override
  public void onResponse(List<Dialog> response) {
    System.out.println(response);
  }

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

See the CHANGELOG for the release notes.

Migration

To migrate to 3.0 from a previous version, simply add .execute() to the old methods. For example if you previously had

List<Dialog> dialogs = dialogService.getDialogs();
System.out.println(dialogs);

Just add execute() on the end, and your code will work exactly the same as before.

List<Dialog> dialogs = dialogService.getDialogs().execute();
System.out.println(dialogs);

Android

The library supports Android 2.3 and above. For Java, the minimum requirement is 1.7.
It depends on OkHttp and gson.

Running in Bluemix

When running in Bluemix, the library will automatically get the credentials from VCAP_SERVICES. If you have more than one plan, you can use BluemixUtils to get the service credentials for an specific plan.

PersonalityInsights service = new PersonalityInsights();
String apiKey = BluemixUtils.getAPIKey(service.getName(), BluemixUtils.PLAN_STANDARD);
service.setApiKey(apiKey);

Default Headers

Default headers can be specified at any time by using the setDefaultHeaders(Map<String, String> headers) method.

The example below sends the X-Watson-Learning-Opt-Out header in every request preventing Watson from using the payload to improve the service.

PersonalityInsights service = new PersonalityInsights();

Map<String, String> headers = new HashMap<String, String>();
headers.put(HttpHeaders.X_WATSON_LEARNING_OPT_OUT, 1);

service.setDefaultHeaders(headers);

// All the api calls from now on will send the default headers

Build + Test

To build and test the project you can use Gradle (version 1.x).

Gradle:

$ cd java-sdk
$ gradle jar  # build jar file (build/libs/watson-developer-cloud-3.7.0.jar)
$ gradle test # run tests
$ gradle check # performs quality checks on source files and generates reports
$ gradle testReport # run tests and generate the aggregated test report (build/reports/allTests)
$ gradle codeCoverageReport # run tests and generate the code coverage report (build/reports/jacoco)

Working with Eclipse and Intellij IDEA

If you want to work on the code in an IDE instead of a text editor you can easily create project files with gradle:

$ gradle idea     # Intellij IDEA
$ gradle eclipse  # Eclipse

Open Source @ IBM

Find more open source projects on the IBM Github Page

License

This library is licensed under Apache 2.0. Full license text is available in LICENSE.

Contributing

See CONTRIBUTING.md.

About

:bowtie: Java SDK to use the IBM Watson services. It supports Android.

watson-developer-cloud.github.io/java-sdk/

Resources

Readme
Apache-2.0 license

Contributing

Contributing
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.