Scala client library to use the Watson Developer Cloud services, a collection of REST APIs and SDKs that use cognitive computing to solve complex problems.
- Installation
- Usage
- Getting the Service Credentials
- Questions
- Examples
- IBM Watson Services
- Alchemy Language
- Alchemy Vision
- Alchemy Data News
- Concept Insights
- Dialog
- Document Conversion
- Language Identification
- Language Translation
- Machine Translation
- Natural Language Classifier
- Personality Insights
- Relationship Extraction
- Retrieve and Rank
- Speech to Text
- Text to Speech
- Tone Analyzer
- Tradeoff Analytics
- Visual Insights
- Visual Recognition
- Running in Bluemix
- Build + Test
- Eclipse and Intellij
- Open Source @ IBM
- License
- Contributing
The examples below 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.
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:
-
Log in to Bluemix at https://bluemix.net.
-
Create an instance of the service:
- In the Bluemix Catalog, select the service you want to use.
- 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. - Click Create.
-
Copy your credentials:
- On the left side of the page, click Service Credentials to view your service credentials.
- Copy
username
andpassword
(api_key
for AlchemyAPI).
Once you have credentials, copy config.properties.example to src/test/resources/config.properties, and fill them in as necessary.
To use manual username and password
If you are having difficulties using the APIs or have a question about the IBM Watson Services, please ask a question on dW Answers or Stack Overflow.
The Watson Developer Cloud offers a variety of services for building cognitive applications.
Select a domain, then identify or select the language of text, and then translate the text from one supported language to another.
Example: Translate 'hello' from English to Spanish using the Language Translation service.
val service = new LanguageTranslation(new VCAPServicesConfig());
val translationResult = service.translate("hello", "en", "es");
Use Natural Language Classifier service to create a classifier instance by providing a set of representative strings and a set of one or more correct classes for each as training. Then use the trained classifier to classify your new question for best matching answers or to retrieve next actions for your application.
val service = new NaturalLanguageClassifier(new VCAPServicesConfig());
val classification = service.classify("<classifier-id>", "Is it sunny?");
Note: You will need to create and train a classifier in order to be able to classify phrases.
Use linguistic analytics to infer personality and social characteristics, including Big Five, Needs, and Values, from text.
Example: Analyze text and get a personality profile using the Personality Insights service.
val service = new PersonalityInsights(new VCAPServicesConfig());
// Demo content from Moby Dick by Hermann Melville (Chapter 1)
val text = "Call me Ishmael. Some years ago-never mind how long precisely-having "
+ "little or no money in my purse, and nothing particular to interest me on shore, "
+ "I thought I would sail about a little and see the watery part of the world. "
+ "It is a way I have of driving off the spleen and regulating the circulation. "
+ "Whenever I find myself growing grim about the mouth; whenever it is a damp, "
+ "drizzly November in my soul; whenever I find myself involuntarily pausing before "
+ "coffin warehouses, and bringing up the rear of every funeral I meet; and especially "
+ "whenever my hypos get such an upper hand of me, that it requires a strong moral "
+ "principle to prevent me from deliberately stepping into the street, and methodically "
+ "knocking people's hats off-then, I account it high time to get to sea as soon as I can. "
+ "This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself "
+ "upon his sword; I quietly take to the ship. There is nothing surprising in this. "
+ "If they but knew it, almost all men in their degree, some time or other, cherish "
+ "very nearly the same feelings towards the ocean with me. There now is your insular "
+ "city of the Manhattoes, belted round by wharves as Indian isles by coral reefs-commerce surrounds "
+ "it with her surf. Right and left, the streets take you waterward.";
val profile = service.getProfile(text);
Note: Don't forget to update the text
variable! Also, if you experience
authentication errors, remember that the Personality Insights service is not
a free service.
Use the Visual Insights to get insight into the themes present in a collection of images based on their visual appearance/content.
val service = new VisualInsights(new VCAPServicesConfig());
val images = new File("src/test/resources/images.zip");
val summary = service.getSummary(images);
Use the Visual Recognition service to recognize the following picture.
val service = new VisualRecognition(new VCAPServicesConfig());
val image = new File("src/test/resources/car.png");
val labelSet = new LabelSet();
labelSet.withLabelGroup("Auto Racing").withLabelGroup("Sports");
val recognizedImage = service.recognize(image, labelSet);
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.
To use VCAP_SERVICES values, use VCAPServicesConfig
as parameter to service constructor
val service = new PersonalityInsights(new VCAPServicesConfig());
To build and test the project you can use Gradle (version 2.x): or [SBT][sbt].
Gradle:
$ cd scala-sdk
$ gradle jar # build jar file (build/libs/watson-developer-cloud-2.1.0.jar)
$ gradle test # run tests
or SBT:
$ sbt package
SBT is the preferred way to build the project.
Find more open source projects on the IBM Github Page
This library is licensed under Apache 2.0. Full license text is available in LICENSE.