introduction to using Watson Services with Java on Bluemix Patrick - - PowerPoint PPT Presentation

introduction to using watson services with java on bluemix
SMART_READER_LITE
LIVE PREVIEW

introduction to using Watson Services with Java on Bluemix Patrick - - PowerPoint PPT Presentation

introduction to using Watson Services with Java on Bluemix Patrick Mueller @pmuellr , muellerware.org developer advocate for IBM's Bluemix PaaS http://pmuellr.github.io/slides/2015/02-java-intro-with-watson


slide-1
SLIDE 1

introduction to using Watson Services with Java on Bluemix

Patrick Mueller @pmuellr, muellerware.org developer 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

slide-2
SLIDE 2

agenda

Bluemix intro deploy a sample app code snippets Watson services

Java + Watson on Bluemix

2 / 39

slide-3
SLIDE 3

what is Bluemix

Platform-as-a-Service aka PaaS aka web app hosting platform you provide the app, Bluemix hosts the app

Java + Watson on Bluemix

3 / 39

slide-4
SLIDE 4

deployment process

you push your application code to Bluemix Bluemix stages your app; finds runtimes, libraries your app uses Bluemix builds a "droplet"; archive of app code, runtimes, libraries Bluemix provisions VM to run the droplet, unpacks droplet, starts it

Java + Watson on Bluemix

4 / 39

slide-5
SLIDE 5

references

Bluemix console Bluemix documentation Eclipse tools for Bluemix Bluemix Answers

https://developer.ibm.com/answers/smartspace/bluemix/

  • pen to the public

thousands of questions already asked and answered IBMers: do not ask questions containing sensitive IBM internal information

Java + Watson on Bluemix

5 / 39

slide-6
SLIDE 6

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

slide-7
SLIDE 7

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

slide-8
SLIDE 8

sign up for Bluemix and DevOps Services (more)

IBMers: use your IBM email address when registering if you have problems registering, send an email to id@bluemix.net

Java + Watson on Bluemix

8 / 39

slide-9
SLIDE 9

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

slide-10
SLIDE 10

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 available here

Java + Watson on Bluemix

10 / 39

slide-11
SLIDE 11

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

slide-12
SLIDE 12

supported development environments

command-line; using text editors or IDEs, and the cf command-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

slide-13
SLIDE 13

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

slide-14
SLIDE 14

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

slide-15
SLIDE 15
  • ther goodies for Bluemix using

Eclipse

incremental publish remote debug

Java + Watson on Bluemix

15 / 39

slide-16
SLIDE 16

Java code examples

Java + Watson on Bluemix

16 / 39

slide-17
SLIDE 17

using Watson services from Java

bind service to app in Bluemix console use VCAP_SERVICES environment variable to get URL and credentials for service make REST calls to service

Java + Watson on Bluemix

17 / 39

slide-18
SLIDE 18

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

slide-19
SLIDE 19

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

slide-20
SLIDE 20

parsing VCAP_SERVICES in Java - code

import 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

slide-21
SLIDE 21

getting service credentials from parsed 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

slide-22
SLIDE 22

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

slide-23
SLIDE 23

issuing REST request in Java

Executor 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

slide-24
SLIDE 24

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

slide-25
SLIDE 25
  • verview of Watson

services

Java + Watson on Bluemix

25 / 39

slide-26
SLIDE 26

Watson - Concept Expansion

Maps euphemisms or colloquial terms to more commonly understood phrases input: starting point word, a few terms that are examples of that word, and a data set to analyze

  • utput: a ranked list of terms with contextually

similarity to the starting word data sets: periodically updated random tweets, Medical transcript samples from MTSamples

Java + Watson on Bluemix

26 / 39

slide-27
SLIDE 27

Watson - Concept Insights

Explores information based on the concepts behind your input input: content and queries, in text and HTML

  • utput: a list of content that is relevant to your queries

dataset: also uses English Wikipedia

Java + Watson on Bluemix

27 / 39

slide-28
SLIDE 28

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

  • utput: 5-letter ISO language code; eg, "en-US"

Java + Watson on Bluemix

28 / 39

slide-29
SLIDE 29

Watson - Machine Translation

Translate text from one language to another supports: English, Brazilian Portuguese, Spanish, French and Arabic input: text to be translated

  • utput: translated text

Java + Watson on Bluemix

29 / 39

slide-30
SLIDE 30

Watson - Message Resonance

Communicate with people with a style and words that suits them input: term to evaluate and community to measure against

  • utput: score ranking of how well term will be received

by community communities: "cloud" twitter messages or "big data" twitter messages

Java + Watson on Bluemix

30 / 39

slide-31
SLIDE 31

Watson - Question and Answer

Direct responses to user inquiries fueled by primary document sources input: questions and which data set to query

  • utput: 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

slide-32
SLIDE 32

Watson - Relationship Extraction

Intelligently finds relationships between sentence components (nouns, verbs, subjects, objects, etc.) input: text news articles

  • utput: entities from text and relationships in XML

data structure dataset: domain optimized for news articles

Java + Watson on Bluemix

32 / 39

slide-33
SLIDE 33

Watson - Speech to Text

Transcribes English speech to text with low latency input: streamed or recorded audio

  • utput: text transcriptions of the recognized words

dataset: intelligible english speech

Java + Watson on Bluemix

33 / 39

slide-34
SLIDE 34

Watson - Text to Speech

Synthesizes natural-sounding speech from English or Spanish text input: English or Spanish text

  • utput: synthesized audio based on the input text

dataset: English or Spanish text

Java + Watson on Bluemix

34 / 39

slide-35
SLIDE 35

Watson - Tradeoff Analytics

Helps users make better choices to best meet multiple conflicting goals input: decision problem in a JSON document

  • utput: problem and its resolution in a JSON

document dataset: self-contained in input decision problem

Java + Watson on Bluemix

35 / 39

slide-36
SLIDE 36

Watson - User Modeling

Improves understanding of people's preferences to help engage users on their own terms input: text from an individual

  • utput: tree of social characteristcs in JSON and

visualizations using HTML and SVG input should be at least 1000 words of text written by

  • ne individual

Java + Watson on Bluemix

36 / 39

slide-37
SLIDE 37

Watson - Visual Recognition

Analyzes the visual content of images and video frames to understand the content directly input: JPEG images

  • utput: a set of labels and likelihood scores

dataset: large number of classified pictures

Java + Watson on Bluemix

37 / 39

slide-38
SLIDE 38

Watson - more information

Watson Developer Cloud web site

  • ne stop shopping for

getting started information reference documentation app gallery sample code

Java + Watson on Bluemix

38 / 39

slide-39
SLIDE 39

fin

Java + Watson on Bluemix

39 / 39