introduction to using Watson Services with Java on...
Transcript of introduction to using Watson Services with Java on...
![Page 1: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/1.jpg)
introduction to usingWatson Services withJava on BluemixPatrick Mueller @pmuellr, muellerware.orgdeveloper advocate for IBM's Bluemix PaaS
http://pmuellr.github.io/slides/2015/02-java-intro-with-watson http://pmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf http://pmuellr.github.io/slides/ (all of Patrick's slides)
1 / 39
![Page 2: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/2.jpg)
agenda
Bluemix intro
deploy a sample app
code snippets
Watson services
Java + Watson on Bluemix
2 / 39
![Page 3: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/3.jpg)
what is Bluemix
Platform-as-a-Service aka PaaS aka web apphosting platform
you provide the app, Bluemix hosts the app
Java + Watson on Bluemix
3 / 39
![Page 4: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/4.jpg)
deployment process
you push your application code to Bluemix
Bluemix stages your app; finds runtimes, libraries yourapp uses
Bluemix builds a "droplet"; archive of app code,runtimes, libraries
Bluemix provisions VM to run the droplet, unpacksdroplet, starts it
Java + Watson on Bluemix
4 / 39
![Page 5: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/5.jpg)
references
Bluemix consoleBluemix documentationEclipse tools for Bluemix
Bluemix Answers
https://developer.ibm.com/answers/smartspace/bluemix/open to the publicthousands of questions already asked and answeredIBMers: do not ask questions containing sensitive IBMinternal information
Java + Watson on Bluemix
5 / 39
![Page 6: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/6.jpg)
articles / movies
Getting Started with IBM Bluemix and DevOps
Services using Java
Developing IBM Bluemix applications in Java with
Eclipse and DevOps Services
Work locally with IBM DevOps Services projects and
Git source control
Video: Develop and manage Java Apps with IBM
Bluemix and DevOps Services
Java + Watson on Bluemix
6 / 39
![Page 7: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/7.jpg)
sign up for Bluemix and DevOps
Services
for Bluemix, register here (click on SIGN UP):
https://bluemix.net
for DevOps Services, register here, after registering at
Bluemix (click on LOG IN):
https://hub.jazz.net/
use the same userid/password as for Bluemix
Java + Watson on Bluemix
7 / 39
![Page 8: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/8.jpg)
sign up for Bluemix and DevOps
Services (more)
IBMers: use your IBM email address when registering
if you have problems registering, send an email [email protected]
Java + Watson on Bluemix
8 / 39
![Page 9: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/9.jpg)
supported programming languages
just about anything
1st class support for Java (using Liberty) and node.js
community support for PHP, Ruby, Python, others
Java + Watson on Bluemix
9 / 39
![Page 10: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/10.jpg)
supported programming languages -node.js
http://node-stuff.mybluemix.net/how-to
lists pre-reqs to install
sample app with instructions to deploy yourself
Watson User Modeling sample for node.js availablehere
Java + Watson on Bluemix
10 / 39
![Page 11: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/11.jpg)
supported programming languages -Java
pre-reqs for Java development
install Eclipse (Luna)
install Bluemix tools for Eclipse
install WebSphere Software (in Eclipse Help menu)
install cf command-line tool (optional, but you will
probably want it)
Java + Watson on Bluemix
11 / 39
![Page 12: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/12.jpg)
supported development environments
command-line; using text editors or IDEs, and the cfcommand-line tool
Eclipse using cf command-line tool, or Bluemix plugin
for Eclipse
DevOps Services - http://hub.jazz.net; edit, build,
deploy all from the web
Java + Watson on Bluemix
12 / 39
![Page 13: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/13.jpg)
Watson User Modeling sample for Java
code / instructions, available here:
https://hub.jazz.net/project/pmuellr/um-java/overview
a live version of this application here:
http://watson-um-demo.mybluemix.net/
(show deployment of the app using DevOps Services)
Java + Watson on Bluemix
13 / 39
![Page 14: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/14.jpg)
Watson User Modeling sample for Java- using Eclipse
import um-java project using Eclipse git
deployment options
commit to git, let DevOps Services redeploy to
Bluemix
deploy directly using Eclipse for Bluemix tools
Java + Watson on Bluemix
14 / 39
![Page 15: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/15.jpg)
other goodies for Bluemix usingEclipse
incremental publish
remote debug
Java + Watson on Bluemix
15 / 39
![Page 16: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/16.jpg)
Java code examples
Java + Watson on Bluemix
16 / 39
![Page 17: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/17.jpg)
using Watson services from Java
bind service to app in Bluemix console
use VCAP_SERVICES environment variable to get URLand credentials for service
make REST calls to service
Java + Watson on Bluemix
17 / 39
![Page 18: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/18.jpg)
example VCAP_SERVICES{ "user_modeling": [ { "name": "watson-user-modeling", "label": "user_modeling", "plan": "user_modeling_free_plan", "credentials": { "url": "https://gateway.watsonplatform.net/systemu/service/", "username": "<secret username>", "password": "<secret password>" } } ]}
Java + Watson on Bluemix
18 / 39
![Page 19: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/19.jpg)
parsing VCAP_SERVICES in Java - libraries
com.ibm.websphere.appserver.api.json_1.0.2.jar
available for local usage in um-java sample, in um-java/lib directory
provided automatically when deploying to Bluemix
Java + Watson on Bluemix
19 / 39
![Page 20: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/20.jpg)
parsing VCAP_SERVICES in Java - codeimport com.ibm.json.java.JSONArray;
import com.ibm.json.java.JSONObject;
JSONObject getVcapServices() {
String vcap = System.getenv("VCAP_SERVICES");
if (vcap == null) return null;
JSONObject vcapObject = null;
try {
vcapObject = JSONObject.parse(vcap);
}
catch (IOException e) {
String message = "Error parsing VCAP_SERVICES: ";
logger.log(Level.SEVERE, message + e.getMessage(), e);
}
return vcapObject;
}
Java + Watson on Bluemix
20 / 39
![Page 21: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/21.jpg)
getting service credentials fromparsed VCAP_SERVICES in Java// label = "user_modeling";
private void processVCAP_Services(label) {
JSONObject sysEnv = getVcapServices();
if (sysEnv == null) return;
for (Object labelTest : sysEnv.keySet()) {
String labelString = (String) labelTest;
if (labelString.startsWith(label)) {
JSONArray services = (JSONArray) sysEnv.get(labelTest);
JSONObject service = (JSONObject) services.get(0);
JSONObject credentials;
credentials = (JSONObject) service.get("credentials");
baseURL = (String) credentials.get("url");
username = (String) credentials.get("username");
password = (String) credentials.get("password");
}
}
}
Java + Watson on Bluemix
21 / 39
![Page 22: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/22.jpg)
accessing a RESTy service in Java -libraries
use Apache HttpComponents for RESTy libraries
provided with Bluemix libraries for Eclipse
provided automatically when deploying to Bluemix
Java + Watson on Bluemix
22 / 39
![Page 23: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/23.jpg)
issuing REST request in JavaExecutor ex = Executor.newInstance().auth(username, password);URI profileURI = new URI(baseURL + "api/v2/profile").normalize();
Request profileRequest = Request.Post(profileURI) .addHeader("Accept", "application/json") .bodyString(content.toString(), ContentType.APPLICATION_JSON);
String profileString = ex.execute(profileRequest) .handleResponse(new ResponseHandler<String>() { @Override public String handleResponse(HttpResponse r) throws ClientProtocolException, IOException { int statusCode = r.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { req.setAttribute("error", handleError(r)); return null; } return EntityUtils.toString(r.getEntity()); }});
Java + Watson on Bluemix
23 / 39
![Page 24: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/24.jpg)
input and output of REST request
in previous example, content was the input, and
profileString was the output, baseURL, username,
password came from VCAP_SERVICES
input and output will often be JSON format
parse like VCAP_SERVICES example
JSON utilities can also be used to generate correctly
formatted JSON for input, from Java data structures
Java + Watson on Bluemix
24 / 39
![Page 25: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/25.jpg)
overview of Watsonservices
Java + Watson on Bluemix
25 / 39
![Page 26: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/26.jpg)
Watson - Concept Expansion
Maps euphemisms or colloquial terms to more commonlyunderstood phrases
input: starting point word, a few terms that areexamples of that word, and a data set to analyze
output: a ranked list of terms with contextuallysimilarity to the starting word
data sets: periodically updated random tweets, Medicaltranscript samples from MTSamples
Java + Watson on Bluemix
26 / 39
![Page 27: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/27.jpg)
Watson - Concept Insights
Explores information based on the concepts behind your
input
input: content and queries, in text and HTML
output: a list of content that is relevant to your queries
dataset: also uses English Wikipedia
Java + Watson on Bluemix
27 / 39
![Page 28: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/28.jpg)
Watson - Language Identification
Identifies the language in which text is written
supports: Arabic; Chinese (Simplified); Chinese (Traditional); Cyrillic; Danish;
Dutch; English; Farsi; Finnish; French; German; Greek; Hebrew; Hindi; Icelandic;
Italian; Japanese; Korean; Norwegian (Bokmal); Norwegian (Nynorsk); Portuguese;
Spanish; Swedish; Turkish; Urdu.
input: text
output: 5-letter ISO language code; eg, "en-US"
Java + Watson on Bluemix
28 / 39
![Page 29: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/29.jpg)
Watson - Machine Translation
Translate text from one language to another
supports: English, Brazilian Portuguese, Spanish,French and Arabic
input: text to be translated
output: translated text
Java + Watson on Bluemix
29 / 39
![Page 30: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/30.jpg)
Watson - Message Resonance
Communicate with people with a style and words thatsuits them
input: term to evaluate and community to measureagainst
output: score ranking of how well term will be receivedby community
communities: "cloud" twitter messages or "bigdata" twitter messages
Java + Watson on Bluemix
30 / 39
![Page 31: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/31.jpg)
Watson - Question and Answer
Direct responses to user inquiries fueled by primary
document sources
input: questions and which data set to query
output: multiple answers with confidence scores and
links to evidence
data sets: healthcare data (including Healthfinder
and CDC Health Topics) or travel data (including
Wikivoyage, TSA, and CDC Travel)
Java + Watson on Bluemix
31 / 39
![Page 32: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/32.jpg)
Watson - Relationship Extraction
Intelligently finds relationships between sentencecomponents (nouns, verbs, subjects, objects, etc.)
input: text news articles
output: entities from text and relationships in XMLdata structure
dataset: domain optimized for news articles
Java + Watson on Bluemix
32 / 39
![Page 33: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/33.jpg)
Watson - Speech to Text
Transcribes English speech to text with low latency
input: streamed or recorded audio
output: text transcriptions of the recognized words
dataset: intelligible english speech
Java + Watson on Bluemix
33 / 39
![Page 34: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/34.jpg)
Watson - Text to Speech
Synthesizes natural-sounding speech from English orSpanish text
input: English or Spanish text
output: synthesized audio based on the input text
dataset: English or Spanish text
Java + Watson on Bluemix
34 / 39
![Page 35: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/35.jpg)
Watson - Tradeoff Analytics
Helps users make better choices to best meet multipleconflicting goals
input: decision problem in a JSON document
output: problem and its resolution in a JSONdocument
dataset: self-contained in input decision problem
Java + Watson on Bluemix
35 / 39
![Page 36: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/36.jpg)
Watson - User Modeling
Improves understanding of people's preferences to helpengage users on their own terms
input: text from an individual
output: tree of social characteristcs in JSON andvisualizations using HTML and SVG
input should be at least 1000 words of text written byone individual
Java + Watson on Bluemix
36 / 39
![Page 37: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/37.jpg)
Watson - Visual Recognition
Analyzes the visual content of images and video frames tounderstand the content directly
input: JPEG images
output: a set of labels and likelihood scores
dataset: large number of classified pictures
Java + Watson on Bluemix
37 / 39
![Page 38: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/38.jpg)
Watson - more information
Watson Developer Cloud web site
one stop shopping for
getting started informationreference documentationapp gallerysample code
Java + Watson on Bluemix
38 / 39
![Page 39: introduction to using Watson Services with Java on Bluemixpmuellr.github.io/slides/2015/02-java-intro-with-watson/java-intro-with-watson.pdf · agenda Bluemix intro deploy a sample](https://reader030.fdocuments.in/reader030/viewer/2022040419/5e0319bfd9e2ea2f2041c298/html5/thumbnails/39.jpg)
fin
Java + Watson on Bluemix
39 / 39