A Java wrapper for the IBM Watson DQA service.
The latest release is jwatson 1.0.
Use sbt clean compile assembly
to build the project. The fat jar
file can be found in the /target
folder.
public static void main(String[] args) throws IOException {
// Create a Watson instance with your URL and credentials
JWatson watson = new JWatson("username", "password", "https://url/instance/xxxxx/deepqa/");
// Query Watson to retrieve answers for a specific question
// WatsonAnswer answer = watson.askQuestion("Who is Angela Merkel?");
// ... or use the QuestionBuilder to construct complex questions for Watson
WatsonQuestion question = new WatsonQuestion.QuestionBuilder("Who is Angela Merkel?")
.setNumberOfAnswers(3) // Provide three possible answers
.formatAnswer() // Instruct Watson to deliver answers in HTML
.create();
WatsonAnswer answer = watson.askQuestion(question);
System.out.println(answer);
}
- Make sure that the URL contains a trailing slash at the end.
- Ping and Feedback endpoints are not implemented yet.
- To use JWatson with the Bluemix QA service instead of an university (private-) instance, you need make slightly modifications in the JSON structure.
Copyright 2016 Technische Universität Darmstadt.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.