From 266a771949cfedb9af875ccc707a64d4d93e859c Mon Sep 17 00:00:00 2001 From: Eddie Zaneski Date: Wed, 10 Feb 2016 11:05:20 -0500 Subject: [PATCH 01/14] [Alchemy Vision] Fix example in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bda666c3ad3..7a0074a6b1d 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ service.setApiKey(""); File image = new File("src/test/resources/alchemy/obama.jpg"); Boolean forceShowAll = false; Boolean knowledgeGraph = false; -ImageKeywords keywords = service.getImageKeywords(, forceShowAll, knowledgeGraph); +ImageKeywords keywords = service.getImageKeywords(image, forceShowAll, knowledgeGraph); System.out.println(keywords); ``` From de7e64e8905ec240463028a8ed3b409538c2a5ac Mon Sep 17 00:00:00 2001 From: Hernan Badenes Date: Wed, 10 Feb 2016 16:42:56 -0300 Subject: [PATCH 02/14] first version for v3 wrapper --- .../tone_analyzer/v3/ToneAnalyzer.java | 81 +++++++++ .../tone_analyzer/v3/model/ElementTone.java | 32 ++++ .../v3/model/SentenceAnalysis.java | 65 +++++++ .../tone_analyzer/v3/model/ToneAnalysis.java | 42 +++++ .../tone_analyzer/v3/model/ToneCategory.java | 56 ++++++ .../tone_analyzer/v3/model/ToneScore.java | 55 ++++++ .../tone_analyzer/v3/package-info.java | 15 ++ .../tone_analyzer/v3/ToneAnalyzerIT.java | 67 ++++++++ .../tone_analyzer/v3/ToneAnalyzerTest.java | 161 ++++++++++++++++++ 9 files changed, 574 insertions(+) create mode 100644 src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzer.java create mode 100644 src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ElementTone.java create mode 100644 src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/SentenceAnalysis.java create mode 100644 src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneAnalysis.java create mode 100644 src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneCategory.java create mode 100644 src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneScore.java create mode 100644 src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/package-info.java create mode 100644 src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerIT.java create mode 100644 src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerTest.java diff --git a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzer.java b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzer.java new file mode 100644 index 00000000000..628ac7c05dd --- /dev/null +++ b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzer.java @@ -0,0 +1,81 @@ +/** + * Copyright 2015 IBM Corp. All Rights Reserved. + * + * 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. + */ +package com.ibm.watson.developer_cloud.tone_analyzer.v3; + +import java.lang.reflect.Type; +import java.util.List; + +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; +import com.ibm.watson.developer_cloud.http.HttpMediaType; +import com.ibm.watson.developer_cloud.http.RequestBuilder; +import com.ibm.watson.developer_cloud.service.WatsonService; +import com.ibm.watson.developer_cloud.tone_analyzer.v1.model.Scorecard; +import com.ibm.watson.developer_cloud.tone_analyzer.v1.model.SynonymOptions; +import com.ibm.watson.developer_cloud.tone_analyzer.v1.model.SynonymResult; +import com.ibm.watson.developer_cloud.tone_analyzer.v1.model.Tone; +import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneAnalysis; +import com.ibm.watson.developer_cloud.util.GsonSingleton; +import com.ibm.watson.developer_cloud.util.ResponseUtil; +import com.squareup.okhttp.Request; +import com.squareup.okhttp.Response; + +/** + * The IBM Watson The Tone Analyzer service uses linguistic analysis to detect emotional tones, + * social propensities, and writing styles in written communication. Then it offers suggestions to + * help the writer improve their intended language tones. + * + * @version v1 + * @see + * Tone Analyzer + */ +public class ToneAnalyzer extends WatsonService { + + private static final String PATH_TONE = "/v3/tone"; + private static final String TEXT = "text"; + private static final String URL = + "https://gateway.watsonplatform.net/tone-analyzer-beta/api"; + + /** + * Instantiates a new Tone Analyzer service. + */ + public ToneAnalyzer() { + super("tone_analyzer"); + setEndPoint(URL); + } + + + /** + * Analyzes the "tone" of a piece of text. The message is analyzed from several tones (social + * tone, emotional tone, writing tone), and for each of them various traits are derived (such as + * conscientiousness, agreeableness, openness). + * + * @param text The text to analyze + * @return the {@link Tone} with the response + * + */ + public ToneAnalysis getTone(final String text) { + + if (text == null || text.isEmpty()) + throw new IllegalArgumentException("text cannot be null or empty"); + + final JsonObject contentJson = new JsonObject(); + contentJson.addProperty(TEXT, text); + + final Request request = RequestBuilder.post(PATH_TONE).withBodyJson(contentJson).build(); + return executeRequest(request, ToneAnalysis.class); + } + +} diff --git a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ElementTone.java b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ElementTone.java new file mode 100644 index 00000000000..42abcc15950 --- /dev/null +++ b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ElementTone.java @@ -0,0 +1,32 @@ +package com.ibm.watson.developer_cloud.tone_analyzer.v3.model; + +import java.util.ArrayList; +import java.util.List; + +import com.ibm.watson.developer_cloud.service.model.GenericModel; + +/** + * This object represents the results of Tone analysis on an element; which may be a document or a sentence. + * Its structure is a 2-level tree, with tone categories in the top level and the individual tones (and their + * scores) in leaves. + * + * @author Hernan Badenes + * + */ +public class ElementTone extends GenericModel { + + List tones = new ArrayList(); + + public List getTones() { + return tones; + } + + public void setTones(List tones) { + this.tones = tones; + } + + public void addTone(ToneCategory tone) { + this.tones.add(tone); + } + +} diff --git a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/SentenceAnalysis.java b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/SentenceAnalysis.java new file mode 100644 index 00000000000..8dba64ef01f --- /dev/null +++ b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/SentenceAnalysis.java @@ -0,0 +1,65 @@ +package com.ibm.watson.developer_cloud.tone_analyzer.v3.model; + +import java.util.ArrayList; +import java.util.List; + +import com.ibm.watson.developer_cloud.service.model.GenericModel; + +/** + * This element contains the result of analyzing an individual sentence. It contains a list of ToneCategory + * objects which is the actual result, and also some metadata about the sentence: The original text (if it needs + * to be tracked back), and the position of the sentence in the original text (as index of first and last + * character). + * + * @author Hernan Badenes + * + */ +public class SentenceAnalysis extends GenericModel { + + long sentence_id; + + int charFrom; + + int charTo; + + String text; + + List tones = new ArrayList(); + + public SentenceAnalysis() { + } + + public SentenceAnalysis(long sentence_id, int charFrom, int charTo, String text) { + super(); + this.sentence_id = sentence_id; + this.charFrom = charFrom; + this.charTo = charTo; + this.text = text; + } + + public long getSentence_id() { + return sentence_id; + } + + public int getCharFrom() { + return charFrom; + } + + public int getCharTo() { + return charTo; + } + + public String getText() { + return text; + } + + public void setTones(List tones) { + this.tones = tones; + } + + public void addTone(ToneCategory tone) { + this.tones.add(tone); + } + + +} \ No newline at end of file diff --git a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneAnalysis.java b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneAnalysis.java new file mode 100644 index 00000000000..e39a655d0fd --- /dev/null +++ b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneAnalysis.java @@ -0,0 +1,42 @@ +package com.ibm.watson.developer_cloud.tone_analyzer.v3.model; + +import java.util.List; + +import com.ibm.watson.developer_cloud.service.model.GenericModel; + +/** + * + * Main object containing the result of running Tone Analyzer on a document. It contains both + * the sentence-level and document-level results. + * + * @author Hernan Badenes + * + */ +public class ToneAnalysis extends GenericModel { + + ElementTone documentTone; + + List sentencesTone; + + public ElementTone getDocumentTone() { + return documentTone; + } + + public void setDocumentTone(ElementTone documentTone) { + this.documentTone = documentTone; + } + + public List getSentencesTone() { + return sentencesTone; + } + + public void setSentencesTone(List sentencesTone) { + this.sentencesTone = sentencesTone; + } + + public void addSentencesTone(SentenceAnalysis analysis) { + this.sentencesTone.add(analysis); + } + + +} diff --git a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneCategory.java b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneCategory.java new file mode 100644 index 00000000000..7893d448e0c --- /dev/null +++ b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneCategory.java @@ -0,0 +1,56 @@ +package com.ibm.watson.developer_cloud.tone_analyzer.v3.model; + +import java.util.ArrayList; +import java.util.List; + +import com.ibm.watson.developer_cloud.service.model.GenericModel; + +/** + * This object represents a top levle tone (or Tone Category) from the list of Writing Tone, Emotion Tone or Social Tone. + * It holds a list of scores for individual Tones. + * + * @author Hernan Badenes + * + */ +public class ToneCategory extends GenericModel { + + // The ID of this category. It can referred to from several places in the API input/output. + String id; + + // A human-readable, localized name for this category. + String name; + + // The list of tone scores in this category + List tones = new ArrayList(); + + public ToneCategory() { + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getTones() { + return tones; + } + + public void setTones(List tones) { + this.tones = tones; + } + + public void addTone(ToneScore score) { + this.tones.add(score); + } +} diff --git a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneScore.java b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneScore.java new file mode 100644 index 00000000000..79939ed2862 --- /dev/null +++ b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneScore.java @@ -0,0 +1,55 @@ +package com.ibm.watson.developer_cloud.tone_analyzer.v3.model; + +import com.ibm.watson.developer_cloud.service.model.GenericModel; + +/* + * Object representing scoring of a single Tone (of any category) on our responses. It contains the Tone ID, a score, and optionally + * a list of evidences. + * + * @author Hernan Badenes + */ +public class ToneScore extends GenericModel { + + String tone_id; + + String tone_name; + + Double score; + + public ToneScore() { + + } + + public ToneScore(String toneId, String toneName, Double score) { + super(); + this.tone_id = toneId; + this.tone_name = toneName; + this.score = score; + } + + public String getToneId() { + return tone_id; + } + + public String getToneName() { + return tone_name; + } + + public Double getScore() { + return score; + } + + public void setToneId(String toneId) { + this.tone_id = toneId; + } + + public void setToneName(String toneName) { + this.tone_name = toneName; + } + + public void setScore(Double score) { + this.score = score; + } + + +} diff --git a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/package-info.java b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/package-info.java new file mode 100644 index 00000000000..8f90dc1dfad --- /dev/null +++ b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/package-info.java @@ -0,0 +1,15 @@ +/** + * Copyright 2015 IBM Corp. All Rights Reserved. + * + * 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. + */ +package com.ibm.watson.developer_cloud.tone_analyzer.v3; + diff --git a/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerIT.java b/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerIT.java new file mode 100644 index 00000000000..c22faab260b --- /dev/null +++ b/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerIT.java @@ -0,0 +1,67 @@ +/** + * Copyright 2015 IBM Corp. All Rights Reserved. + * + * 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. + */ +package com.ibm.watson.developer_cloud.tone_analyzer.v3; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.ibm.watson.developer_cloud.WatsonServiceTest; +import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneAnalysis; + +/** + * The Class ToneAnalyzerTest. + */ +public class ToneAnalyzerIT extends WatsonServiceTest { + + /** The service. */ + private ToneAnalyzer service; + + /* + * (non-Javadoc) + * + * @see com.ibm.watson.developer_cloud.WatsonServiceTest#setUp() + */ + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + service = new ToneAnalyzer(); + service.setUsernameAndPassword(getValidProperty("tone_analyzer.username"), + getValidProperty("tone_analyzer.password")); + service.setEndPoint(getValidProperty("tone_analyzer.url")); + service.setDefaultHeaders(getDefaultHeaders()); + + } + + @Test + public void testGetTone() { + final String text = + "I know the times are difficult! Our sales have been " + + "disappointing for the past three quarters for our data analytics " + + "product suite. We have a competitive data analytics product " + + "suite in the industry. But we need to do our job selling it! "; + + + // Call the service and get the tone + final ToneAnalysis tone = service.getTone(text); + Assert.assertNotNull(tone); + Assert.assertNotNull(tone.getDocumentTone()); + Assert.assertEquals(3, tone.getDocumentTone().getTones().size()); + Assert.assertNotNull(tone.getSentencesTone()); + Assert.assertEquals(1, tone.getSentencesTone().size()); + Assert.assertNotNull(tone.getSentencesTone().get(0).getText()); + } + +} diff --git a/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerTest.java b/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerTest.java new file mode 100644 index 00000000000..3bea81b8606 --- /dev/null +++ b/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerTest.java @@ -0,0 +1,161 @@ +/** + * Copyright 2015 IBM Corp. All Rights Reserved. + * + * 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. + */ +package com.ibm.watson.developer_cloud.tone_analyzer.v3; + +import static org.mockserver.model.HttpRequest.request; +import static org.mockserver.model.HttpResponse.response; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockserver.model.Header; + +import com.google.gson.JsonObject; +import com.ibm.watson.developer_cloud.WatsonServiceUnitTest; +import com.ibm.watson.developer_cloud.http.HttpMediaType; +import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ElementTone; +import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.SentenceAnalysis; +import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneAnalysis; +import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneCategory; +import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneScore; +import com.ibm.watson.developer_cloud.util.GsonSingleton; + +import io.netty.handler.codec.http.HttpHeaders; + +/** + * The Class ToneAnalyzerTest. + */ +@SuppressWarnings("serial") +public class ToneAnalyzerTest extends WatsonServiceUnitTest { + + private final static String TONE_PATH = "/v3/tone"; + + /** The service. */ + private ToneAnalyzer service; + + /* + * (non-Javadoc) + * + * @see com.ibm.watson.developer_cloud.WatsonServiceTest#setUp() + */ + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + service = new ToneAnalyzer(); + service.setApiKey(""); + service.setEndPoint(MOCK_SERVER_URL); + + } + + /** + * Test get tone. + */ + @Test + public void testGetTone() { + final String text = + "I know the times are difficult! Our sales have been " + + "disappointing for the past three quarters for our data analytics " + + "product suite. We have a competitive data analytics product " + + "suite in the industry. But we need to do our job selling it! "; + + final ToneAnalysis response = new ToneAnalysis(); + + final ElementTone docTone = new ElementTone(); + docTone.addTone(buildEmotionTone()); + docTone.addTone(buildWritingTone()); + docTone.addTone(buildSocialTone()); + + List sentences = new ArrayList(); + response.setSentencesTone(sentences); + + final SentenceAnalysis sentence = new SentenceAnalysis(0, 0, text.length(), text); + sentence.addTone(buildEmotionTone()); + sentence.addTone(buildWritingTone()); + sentence.addTone(buildSocialTone()); + + final JsonObject contentJson = new JsonObject(); + contentJson.addProperty("text", text); + + mockServer + .when(request().withMethod(POST).withPath(TONE_PATH).withBody(contentJson.toString())) + .respond( + response().withHeaders( + new Header(HttpHeaders.Names.CONTENT_TYPE, HttpMediaType.APPLICATION_JSON)) + .withBody(GsonSingleton.getGson().toJson(response))); + + // Call the service and get the tone + final ToneAnalysis tone = service.getTone(text); + Assert.assertNotNull(tone); + Assert.assertNotNull(tone.getDocumentTone()); + Assert.assertEquals(3, tone.getDocumentTone().getTones().size()); + Assert.assertNotNull(tone.getSentencesTone()); + Assert.assertEquals(1, tone.getSentencesTone().size()); + Assert.assertNotNull(tone.getSentencesTone().get(0).getText()); + Assert.assertEquals(tone, response); + + } + + private ToneCategory buildEmotionTone() { + final ToneCategory ret = new ToneCategory(); + ret.setId("emotion_tone"); + ret.setName("Emotion Tone"); + List tones = new ArrayList(); + tones.add(new ToneScore("anger", "Anger", 0.1)); + tones.add(new ToneScore("disgust", "Disgust", 0.2)); + tones.add(new ToneScore("fear", "Fear", 0.3)); + tones.add(new ToneScore("joy", "Joy", 0.4)); + tones.add(new ToneScore("sadness", "Sadness", 0.0)); + ret.setTones(tones); + return null; + } + + private ToneCategory buildWritingTone() { + final ToneCategory ret = new ToneCategory(); + ret.setId("writing_tone"); + ret.setName("Writing Tone"); + List tones = new ArrayList(); + tones.add(new ToneScore("analytical", "Analytical", 0.2)); + tones.add(new ToneScore("confident", "Confident", 0.3)); + tones.add(new ToneScore("tentative", "Tentative", 0.4)); + ret.setTones(tones); + return null; + } + + private ToneCategory buildSocialTone() { + final ToneCategory ret = new ToneCategory(); + ret.setId("social_tone"); + ret.setName("Social Tone"); + List tones = new ArrayList(); + tones.add(new ToneScore("openness_big5", "Openness", 0.1)); + tones.add(new ToneScore("conscientiousness_big5", "Conscientiousness", 0.2)); + tones.add(new ToneScore("extraversion_big5", "Extraversion", 0.3)); + tones.add(new ToneScore("agreeableness_big5", "Agreeableness", 0.4)); + tones.add(new ToneScore("neuroticism_big5", "Emotional Range", 0.5)); + ret.setTones(tones); + return null; + } + +/** + * Test tone with null. + */ + @Test(expected = IllegalArgumentException.class) + public void testGetToneWithNull() { + service.getTone(null); + } + +} From 38a8e02fd713068979646d2c9beb6d856254db7c Mon Sep 17 00:00:00 2001 From: German Attanasio Ruiz Date: Wed, 10 Feb 2016 23:20:01 -0500 Subject: [PATCH 03/14] [tone-analyzer] Add support for v3 --- .../tone_analyzer/v3/ToneAnalyzer.java | 40 +- .../tone_analyzer/v3/model/ElementTone.java | 35 +- .../v3/model/SentenceAnalysis.java | 65 --- .../tone_analyzer/v3/model/SentenceTone.java | 111 +++++ .../tone_analyzer/v3/model/ToneAnalysis.java | 87 +++- .../tone_analyzer/v3/model/ToneCategory.java | 130 +++-- .../tone_analyzer/v3/model/ToneScore.java | 134 ++++-- .../tone_analyzer/v3/ToneAnalyzerIT.java | 8 +- .../tone_analyzer/v3/ToneAnalyzerTest.java | 122 ++--- src/test/resources/tone_analyzer/message.txt | 1 + src/test/resources/tone_analyzer/tone.json | 455 ++++++++++++++++++ 11 files changed, 888 insertions(+), 300 deletions(-) delete mode 100644 src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/SentenceAnalysis.java create mode 100644 src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/SentenceTone.java create mode 100644 src/test/resources/tone_analyzer/message.txt create mode 100644 src/test/resources/tone_analyzer/tone.json diff --git a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzer.java b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzer.java index 628ac7c05dd..a30edfb6ad0 100644 --- a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzer.java +++ b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzer.java @@ -13,23 +13,12 @@ */ package com.ibm.watson.developer_cloud.tone_analyzer.v3; -import java.lang.reflect.Type; -import java.util.List; - import com.google.gson.JsonObject; -import com.google.gson.reflect.TypeToken; -import com.ibm.watson.developer_cloud.http.HttpMediaType; import com.ibm.watson.developer_cloud.http.RequestBuilder; import com.ibm.watson.developer_cloud.service.WatsonService; -import com.ibm.watson.developer_cloud.tone_analyzer.v1.model.Scorecard; -import com.ibm.watson.developer_cloud.tone_analyzer.v1.model.SynonymOptions; -import com.ibm.watson.developer_cloud.tone_analyzer.v1.model.SynonymResult; import com.ibm.watson.developer_cloud.tone_analyzer.v1.model.Tone; import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneAnalysis; -import com.ibm.watson.developer_cloud.util.GsonSingleton; -import com.ibm.watson.developer_cloud.util.ResponseUtil; import com.squareup.okhttp.Request; -import com.squareup.okhttp.Response; /** * The IBM Watson The Tone Analyzer service uses linguistic analysis to detect emotional tones, @@ -37,26 +26,36 @@ * help the writer improve their intended language tones. * * @version v1 - * @see - * Tone Analyzer + * @see Tone + * Analyzer */ public class ToneAnalyzer extends WatsonService { + private static final String VERSION_DATE = "version"; private static final String PATH_TONE = "/v3/tone"; private static final String TEXT = "text"; - private static final String URL = - "https://gateway.watsonplatform.net/tone-analyzer-beta/api"; + private static final String URL = "https://gateway.watsonplatform.net/tone-analyzer-beta/api"; + private String versionDate; + + /** The version date */ + public static final String VERSION_DATE_2016_02_11 = "2016-02-11"; + /** - * Instantiates a new Tone Analyzer service. + * Instantiates a new tone analyzer. + * + * @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value + * will keep your API calls from failing when the service introduces breaking changes. */ - public ToneAnalyzer() { + public ToneAnalyzer(String versionDate) { super("tone_analyzer"); setEndPoint(URL); + this.versionDate = versionDate; } + /** * Analyzes the "tone" of a piece of text. The message is analyzed from several tones (social * tone, emotional tone, writing tone), and for each of them various traits are derived (such as @@ -74,7 +73,10 @@ public ToneAnalysis getTone(final String text) { final JsonObject contentJson = new JsonObject(); contentJson.addProperty(TEXT, text); - final Request request = RequestBuilder.post(PATH_TONE).withBodyJson(contentJson).build(); + final Request request = RequestBuilder.post(PATH_TONE) + .withQuery(VERSION_DATE, versionDate) + .withBodyJson(contentJson) + .build(); return executeRequest(request, ToneAnalysis.class); } diff --git a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ElementTone.java b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ElementTone.java index 42abcc15950..e427276f406 100644 --- a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ElementTone.java +++ b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ElementTone.java @@ -1,8 +1,21 @@ +/** + * Copyright 2015 IBM Corp. All Rights Reserved. + * + * 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. + */ package com.ibm.watson.developer_cloud.tone_analyzer.v3.model; -import java.util.ArrayList; import java.util.List; +import com.google.gson.annotations.SerializedName; import com.ibm.watson.developer_cloud.service.model.GenericModel; /** @@ -10,21 +23,35 @@ * Its structure is a 2-level tree, with tone categories in the top level and the individual tones (and their * scores) in leaves. * - * @author Hernan Badenes - * */ public class ElementTone extends GenericModel { - List tones = new ArrayList(); + @SerializedName("tone_categories") + private List tones; + /** + * Gets the tones. + * + * @return the tones + */ public List getTones() { return tones; } + /** + * Sets the tones. + * + * @param tones the new tones + */ public void setTones(List tones) { this.tones = tones; } + /** + * Adds the tone. + * + * @param tone the tone + */ public void addTone(ToneCategory tone) { this.tones.add(tone); } diff --git a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/SentenceAnalysis.java b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/SentenceAnalysis.java deleted file mode 100644 index 8dba64ef01f..00000000000 --- a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/SentenceAnalysis.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.ibm.watson.developer_cloud.tone_analyzer.v3.model; - -import java.util.ArrayList; -import java.util.List; - -import com.ibm.watson.developer_cloud.service.model.GenericModel; - -/** - * This element contains the result of analyzing an individual sentence. It contains a list of ToneCategory - * objects which is the actual result, and also some metadata about the sentence: The original text (if it needs - * to be tracked back), and the position of the sentence in the original text (as index of first and last - * character). - * - * @author Hernan Badenes - * - */ -public class SentenceAnalysis extends GenericModel { - - long sentence_id; - - int charFrom; - - int charTo; - - String text; - - List tones = new ArrayList(); - - public SentenceAnalysis() { - } - - public SentenceAnalysis(long sentence_id, int charFrom, int charTo, String text) { - super(); - this.sentence_id = sentence_id; - this.charFrom = charFrom; - this.charTo = charTo; - this.text = text; - } - - public long getSentence_id() { - return sentence_id; - } - - public int getCharFrom() { - return charFrom; - } - - public int getCharTo() { - return charTo; - } - - public String getText() { - return text; - } - - public void setTones(List tones) { - this.tones = tones; - } - - public void addTone(ToneCategory tone) { - this.tones.add(tone); - } - - -} \ No newline at end of file diff --git a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/SentenceTone.java b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/SentenceTone.java new file mode 100644 index 00000000000..85df0800212 --- /dev/null +++ b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/SentenceTone.java @@ -0,0 +1,111 @@ +/** + * Copyright 2015 IBM Corp. All Rights Reserved. + * + * 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. + */ +package com.ibm.watson.developer_cloud.tone_analyzer.v3.model; + +import com.google.gson.annotations.SerializedName; + +/** + * This element contains the result of analyzing an individual sentence. It contains a list of + * ToneCategory objects which is the actual result, and also some metadata about the sentence: The + * original text (if it needs to be tracked back), and the position of the sentence in the original + * text (as index of first and last character). + * + */ +public class SentenceTone extends ElementTone { + + @SerializedName("sentence_id") + private Integer id; + + @SerializedName("input_from") + private Integer inputFrom; + + @SerializedName("input_to") + private Integer inputTo; + + @SerializedName("text") + private String text; + + /** + * Gets the id. + * + * @return the id + */ + public Integer getId() { + return id; + } + + /** + * Sets the id. + * + * @param id the new id + */ + public void setId(Integer id) { + this.id = id; + } + + /** + * Gets the input from. + * + * @return the input from + */ + public Integer getInputFrom() { + return inputFrom; + } + + /** + * Sets the input from. + * + * @param inputFrom the new input from + */ + public void setInputFrom(Integer inputFrom) { + this.inputFrom = inputFrom; + } + + /** + * Gets the input to. + * + * @return the input to + */ + public Integer getInputTo() { + return inputTo; + } + + /** + * Sets the input to. + * + * @param inputTo the new input to + */ + public void setInputTo(Integer inputTo) { + this.inputTo = inputTo; + } + + /** + * Gets the text. + * + * @return the text + */ + public String getText() { + return text; + } + + /** + * Sets the text. + * + * @param text the new text + */ + public void setText(String text) { + this.text = text; + } + +} diff --git a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneAnalysis.java b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneAnalysis.java index e39a655d0fd..f632660aefd 100644 --- a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneAnalysis.java +++ b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneAnalysis.java @@ -1,42 +1,81 @@ +/** + * Copyright 2015 IBM Corp. All Rights Reserved. + * + * 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. + */ package com.ibm.watson.developer_cloud.tone_analyzer.v3.model; import java.util.List; +import com.google.gson.annotations.SerializedName; import com.ibm.watson.developer_cloud.service.model.GenericModel; /** * - * Main object containing the result of running Tone Analyzer on a document. It contains both - * the sentence-level and document-level results. + * Main object containing the result of running Tone Analyzer on a document. It contains both the + * sentence-level and document-level results. * - * @author Hernan Badenes - * */ public class ToneAnalysis extends GenericModel { - ElementTone documentTone; + @SerializedName("document_tone") + private ElementTone documentTone; + + @SerializedName("sentences_tone") + private List sentencesTone; + + /** + * Gets the document tone. + * + * @return the document tone + */ + public ElementTone getDocumentTone() { + return documentTone; + } + + /** + * Sets the document tone. + * + * @param documentTone the new document tone + */ + public void setDocumentTone(ElementTone documentTone) { + this.documentTone = documentTone; + } - List sentencesTone; + /** + * Gets the sentences tone. + * + * @return the sentences tone + */ + public List getSentencesTone() { + return sentencesTone; + } - public ElementTone getDocumentTone() { - return documentTone; - } + /** + * Sets the sentences tone. + * + * @param sentencesTone the new sentences tone + */ + public void setSentencesTone(List sentencesTone) { + this.sentencesTone = sentencesTone; + } - public void setDocumentTone(ElementTone documentTone) { - this.documentTone = documentTone; - } + /** + * Adds the sentences tone. + * + * @param analysis the analysis + */ + public void addSentencesTone(SentenceTone analysis) { + this.sentencesTone.add(analysis); + } - public List getSentencesTone() { - return sentencesTone; - } - public void setSentencesTone(List sentencesTone) { - this.sentencesTone = sentencesTone; - } - - public void addSentencesTone(SentenceAnalysis analysis) { - this.sentencesTone.add(analysis); - } - - } diff --git a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneCategory.java b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneCategory.java index 7893d448e0c..695ced3af5a 100644 --- a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneCategory.java +++ b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneCategory.java @@ -1,56 +1,96 @@ +/** + * Copyright 2015 IBM Corp. All Rights Reserved. + * + * 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. + */ package com.ibm.watson.developer_cloud.tone_analyzer.v3.model; -import java.util.ArrayList; import java.util.List; +import com.google.gson.annotations.SerializedName; import com.ibm.watson.developer_cloud.service.model.GenericModel; /** - * This object represents a top levle tone (or Tone Category) from the list of Writing Tone, Emotion Tone or Social Tone. - * It holds a list of scores for individual Tones. + * Top level tone (or Tone Category) from the list of Writing Tone, Emotion Tone or Social Tone. It + * holds a list of scores for individual Tones. * - * @author Hernan Badenes - * */ public class ToneCategory extends GenericModel { - - // The ID of this category. It can referred to from several places in the API input/output. - String id; - - // A human-readable, localized name for this category. - String name; - - // The list of tone scores in this category - List tones = new ArrayList(); - - public ToneCategory() { - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getTones() { - return tones; - } - - public void setTones(List tones) { - this.tones = tones; - } - - public void addTone(ToneScore score) { - this.tones.add(score); - } + + @SerializedName("category_id") + private String id; + @SerializedName("category_name") + private String name; + private List tones; + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + return id; + } + + /** + * Sets the id. + * + * @param id the new id + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Sets the name. + * + * @param name the new name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Gets the tones. + * + * @return the tones + */ + public List getTones() { + return tones; + } + + /** + * Sets the tones. + * + * @param tones the new tones + */ + public void setTones(List tones) { + this.tones = tones; + } + + /** + * Adds the tone. + * + * @param score the score + */ + public void addTone(ToneScore score) { + this.tones.add(score); + } } diff --git a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneScore.java b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneScore.java index 79939ed2862..0d7570226a5 100644 --- a/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneScore.java +++ b/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneScore.java @@ -1,55 +1,95 @@ +/** + * Copyright 2015 IBM Corp. All Rights Reserved. + * + * 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. + */ package com.ibm.watson.developer_cloud.tone_analyzer.v3.model; +import com.google.gson.annotations.SerializedName; import com.ibm.watson.developer_cloud.service.model.GenericModel; -/* - * Object representing scoring of a single Tone (of any category) on our responses. It contains the Tone ID, a score, and optionally - * a list of evidences. - * - * @author Hernan Badenes +/** + * Object representing scoring of a single Tone (of any category) on our responses. It contains the + * Tone ID, a score, and optionally a list of evidences. */ public class ToneScore extends GenericModel { - String tone_id; - - String tone_name; - - Double score; - - public ToneScore() { - - } - - public ToneScore(String toneId, String toneName, Double score) { - super(); - this.tone_id = toneId; - this.tone_name = toneName; - this.score = score; - } - - public String getToneId() { - return tone_id; - } - - public String getToneName() { - return tone_name; - } - - public Double getScore() { - return score; - } - - public void setToneId(String toneId) { - this.tone_id = toneId; - } - - public void setToneName(String toneName) { - this.tone_name = toneName; - } - - public void setScore(Double score) { - this.score = score; - } - - + @SerializedName("tone_id") + private String id; + + @SerializedName("tone_name") + private String name; + + /** The score. */ + private Double score; + + /** + * Instantiates a new tone score. + */ + public ToneScore() { + + } + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + return id; + } + + /** + * Sets the id. + * + * @param id the new id + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Sets the name. + * + * @param name the new name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Gets the score. + * + * @return the score + */ + public Double getScore() { + return score; + } + + /** + * Sets the score. + * + * @param score the new score + */ + public void setScore(Double score) { + this.score = score; + } + } diff --git a/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerIT.java b/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerIT.java index c22faab260b..75148e67c43 100644 --- a/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerIT.java +++ b/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerIT.java @@ -21,7 +21,7 @@ import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneAnalysis; /** - * The Class ToneAnalyzerTest. + * Tone Analyzer Integration tests */ public class ToneAnalyzerIT extends WatsonServiceTest { @@ -37,7 +37,7 @@ public class ToneAnalyzerIT extends WatsonServiceTest { @Before public void setUp() throws Exception { super.setUp(); - service = new ToneAnalyzer(); + service = new ToneAnalyzer(ToneAnalyzer.VERSION_DATE_2016_02_11); service.setUsernameAndPassword(getValidProperty("tone_analyzer.username"), getValidProperty("tone_analyzer.password")); service.setEndPoint(getValidProperty("tone_analyzer.url")); @@ -60,8 +60,8 @@ public void testGetTone() { Assert.assertNotNull(tone.getDocumentTone()); Assert.assertEquals(3, tone.getDocumentTone().getTones().size()); Assert.assertNotNull(tone.getSentencesTone()); - Assert.assertEquals(1, tone.getSentencesTone().size()); - Assert.assertNotNull(tone.getSentencesTone().get(0).getText()); + Assert.assertEquals(4, tone.getSentencesTone().size()); + Assert.assertEquals("I know the times are difficult!", tone.getSentencesTone().get(0).getText()); } } diff --git a/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerTest.java b/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerTest.java index 3bea81b8606..2bfaa086e2b 100644 --- a/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerTest.java +++ b/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerTest.java @@ -16,32 +16,26 @@ import static org.mockserver.model.HttpRequest.request; import static org.mockserver.model.HttpResponse.response; -import java.util.ArrayList; -import java.util.List; +import java.io.FileNotFoundException; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mockserver.model.Header; import com.google.gson.JsonObject; import com.ibm.watson.developer_cloud.WatsonServiceUnitTest; +import com.ibm.watson.developer_cloud.http.HttpHeaders; import com.ibm.watson.developer_cloud.http.HttpMediaType; -import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ElementTone; -import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.SentenceAnalysis; import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneAnalysis; -import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneCategory; -import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneScore; -import com.ibm.watson.developer_cloud.util.GsonSingleton; - -import io.netty.handler.codec.http.HttpHeaders; /** - * The Class ToneAnalyzerTest. + * Tone Analyzer unit test */ -@SuppressWarnings("serial") public class ToneAnalyzerTest extends WatsonServiceUnitTest { - + + private static final String VERSION_DATE = "version"; + private static final String TEXT = "text"; + private static final String FIXTURE = "src/test/resources/tone_analyzer/tone.json"; private final static String TONE_PATH = "/v3/tone"; /** The service. */ @@ -56,7 +50,7 @@ public class ToneAnalyzerTest extends WatsonServiceUnitTest { @Before public void setUp() throws Exception { super.setUp(); - service = new ToneAnalyzer(); + service = new ToneAnalyzer(ToneAnalyzer.VERSION_DATE_2016_02_11); service.setApiKey(""); service.setEndPoint(MOCK_SERVER_URL); @@ -64,93 +58,37 @@ public void setUp() throws Exception { /** * Test get tone. + * + * @throws FileNotFoundException */ @Test - public void testGetTone() { - final String text = - "I know the times are difficult! Our sales have been " - + "disappointing for the past three quarters for our data analytics " - + "product suite. We have a competitive data analytics product " - + "suite in the industry. But we need to do our job selling it! "; - - final ToneAnalysis response = new ToneAnalysis(); + public void testGetTone() throws FileNotFoundException { + final String text = "I know the times are difficult! Our sales have been " + + "disappointing for the past three quarters for our data analytics " + + "product suite. We have a competitive data analytics product " + + "suite in the industry. But we need to do our job selling it! "; - final ElementTone docTone = new ElementTone(); - docTone.addTone(buildEmotionTone()); - docTone.addTone(buildWritingTone()); - docTone.addTone(buildSocialTone()); - - List sentences = new ArrayList(); - response.setSentencesTone(sentences); + ToneAnalysis response = + loadFixture(FIXTURE, ToneAnalysis.class); - final SentenceAnalysis sentence = new SentenceAnalysis(0, 0, text.length(), text); - sentence.addTone(buildEmotionTone()); - sentence.addTone(buildWritingTone()); - sentence.addTone(buildSocialTone()); - final JsonObject contentJson = new JsonObject(); - contentJson.addProperty("text", text); + contentJson.addProperty(TEXT, text); mockServer - .when(request().withMethod(POST).withPath(TONE_PATH).withBody(contentJson.toString())) - .respond( - response().withHeaders( - new Header(HttpHeaders.Names.CONTENT_TYPE, HttpMediaType.APPLICATION_JSON)) - .withBody(GsonSingleton.getGson().toJson(response))); - - // Call the service and get the tone - final ToneAnalysis tone = service.getTone(text); - Assert.assertNotNull(tone); - Assert.assertNotNull(tone.getDocumentTone()); - Assert.assertEquals(3, tone.getDocumentTone().getTones().size()); - Assert.assertNotNull(tone.getSentencesTone()); - Assert.assertEquals(1, tone.getSentencesTone().size()); - Assert.assertNotNull(tone.getSentencesTone().get(0).getText()); - Assert.assertEquals(tone, response); - - } - - private ToneCategory buildEmotionTone() { - final ToneCategory ret = new ToneCategory(); - ret.setId("emotion_tone"); - ret.setName("Emotion Tone"); - List tones = new ArrayList(); - tones.add(new ToneScore("anger", "Anger", 0.1)); - tones.add(new ToneScore("disgust", "Disgust", 0.2)); - tones.add(new ToneScore("fear", "Fear", 0.3)); - tones.add(new ToneScore("joy", "Joy", 0.4)); - tones.add(new ToneScore("sadness", "Sadness", 0.0)); - ret.setTones(tones); - return null; - } - - private ToneCategory buildWritingTone() { - final ToneCategory ret = new ToneCategory(); - ret.setId("writing_tone"); - ret.setName("Writing Tone"); - List tones = new ArrayList(); - tones.add(new ToneScore("analytical", "Analytical", 0.2)); - tones.add(new ToneScore("confident", "Confident", 0.3)); - tones.add(new ToneScore("tentative", "Tentative", 0.4)); - ret.setTones(tones); - return null; + .when(request() + .withMethod(POST) + .withPath(TONE_PATH) + .withQueryStringParameter(VERSION_DATE, ToneAnalyzer.VERSION_DATE_2016_02_11) + .withBody(contentJson.toString())) + .respond(response() + .withHeader(HttpHeaders.CONTENT_TYPE, HttpMediaType.APPLICATION_JSON) + .withBody(response.toString())); + + // Call the service and compare the result + Assert.assertEquals(response, service.getTone(text)); } - private ToneCategory buildSocialTone() { - final ToneCategory ret = new ToneCategory(); - ret.setId("social_tone"); - ret.setName("Social Tone"); - List tones = new ArrayList(); - tones.add(new ToneScore("openness_big5", "Openness", 0.1)); - tones.add(new ToneScore("conscientiousness_big5", "Conscientiousness", 0.2)); - tones.add(new ToneScore("extraversion_big5", "Extraversion", 0.3)); - tones.add(new ToneScore("agreeableness_big5", "Agreeableness", 0.4)); - tones.add(new ToneScore("neuroticism_big5", "Emotional Range", 0.5)); - ret.setTones(tones); - return null; - } - -/** + /** * Test tone with null. */ @Test(expected = IllegalArgumentException.class) diff --git a/src/test/resources/tone_analyzer/message.txt b/src/test/resources/tone_analyzer/message.txt new file mode 100644 index 00000000000..7a8fa798f85 --- /dev/null +++ b/src/test/resources/tone_analyzer/message.txt @@ -0,0 +1 @@ +I know the times are difficult! Our sales have been disappointing for the past three quarters for our data analytics product suite. We have a competitive data analytics product suite in the industry. But we need to do our job selling it! \ No newline at end of file diff --git a/src/test/resources/tone_analyzer/tone.json b/src/test/resources/tone_analyzer/tone.json new file mode 100644 index 00000000000..73cbaa0e297 --- /dev/null +++ b/src/test/resources/tone_analyzer/tone.json @@ -0,0 +1,455 @@ +{ + "document_tone": { + "tone_categories": [ + { + "tones": [ + { + "score": 0.105802, + "tone_id": "anger", + "tone_name": "Anger" + }, + { + "score": 0.280862, + "tone_id": "disgust", + "tone_name": "Disgust" + }, + { + "score": 0.299966, + "tone_id": "fear", + "tone_name": "Fear" + }, + { + "score": 0.222444, + "tone_id": "joy", + "tone_name": "Joy" + }, + { + "score": 0.090926, + "tone_id": "sadness", + "tone_name": "Sadness" + } + ], + "category_id": "emotion_tone", + "category_name": "Emotion Tone" + }, + { + "tones": [ + { + "score": 0.951, + "tone_id": "analytical", + "tone_name": "Analytical" + }, + { + "score": 0.999, + "tone_id": "confident", + "tone_name": "Confident" + }, + { + "score": 0.999, + "tone_id": "tentative", + "tone_name": "Tentative" + } + ], + "category_id": "writing_tone", + "category_name": "Writing Tone" + }, + { + "tones": [ + { + "score": 0.037, + "tone_id": "openness_big5", + "tone_name": "Openness" + }, + { + "score": 0.172, + "tone_id": "conscientiousness_big5", + "tone_name": "Conscientiousness" + }, + { + "score": 0.263, + "tone_id": "extraversion_big5", + "tone_name": "Extraversion" + }, + { + "score": 0.831, + "tone_id": "agreeableness_big5", + "tone_name": "Agreeableness" + }, + { + "score": 0.967, + "tone_id": "neuroticism_big5", + "tone_name": "Emotional Range" + } + ], + "category_id": "social_tone", + "category_name": "Social Tone" + } + ] + }, + "sentences_tone": [ + { + "sentence_id": 0, + "text": "I know the times are difficult!", + "input_from": 0, + "input_to": 31, + "tone_categories": [ + { + "tones": [ + { + "score": 0.276294, + "tone_id": "anger", + "tone_name": "Anger" + }, + { + "score": 0.280268, + "tone_id": "disgust", + "tone_name": "Disgust" + }, + { + "score": 0.236519, + "tone_id": "fear", + "tone_name": "Fear" + }, + { + "score": 0.15242, + "tone_id": "joy", + "tone_name": "Joy" + }, + { + "score": 0.054499, + "tone_id": "sadness", + "tone_name": "Sadness" + } + ], + "category_id": "emotion_tone", + "category_name": "Emotion Tone" + }, + { + "tones": [ + { + "score": 0.892, + "tone_id": "analytical", + "tone_name": "Analytical" + }, + { + "score": 0.999, + "tone_id": "confident", + "tone_name": "Confident" + }, + { + "score": 0.999, + "tone_id": "tentative", + "tone_name": "Tentative" + } + ], + "category_id": "writing_tone", + "category_name": "Writing Tone" + }, + { + "tones": [ + { + "score": 0.07, + "tone_id": "openness_big5", + "tone_name": "Openness" + }, + { + "score": 0.291, + "tone_id": "conscientiousness_big5", + "tone_name": "Conscientiousness" + }, + { + "score": 0.37, + "tone_id": "extraversion_big5", + "tone_name": "Extraversion" + }, + { + "score": 0.165, + "tone_id": "agreeableness_big5", + "tone_name": "Agreeableness" + }, + { + "score": 0.959, + "tone_id": "neuroticism_big5", + "tone_name": "Emotional Range" + } + ], + "category_id": "social_tone", + "category_name": "Social Tone" + } + ] + }, + { + "sentence_id": 1, + "text": "Our sales have been disappointing for the past three quarters for our data analytics product suite.", + "input_from": 32, + "input_to": 131, + "tone_categories": [ + { + "tones": [ + { + "score": 0.144036, + "tone_id": "anger", + "tone_name": "Anger" + }, + { + "score": 0.235218, + "tone_id": "disgust", + "tone_name": "Disgust" + }, + { + "score": 0.18726, + "tone_id": "fear", + "tone_name": "Fear" + }, + { + "score": 0.141991, + "tone_id": "joy", + "tone_name": "Joy" + }, + { + "score": 0.291495, + "tone_id": "sadness", + "tone_name": "Sadness" + } + ], + "category_id": "emotion_tone", + "category_name": "Emotion Tone" + }, + { + "tones": [ + { + "score": 0.379, + "tone_id": "analytical", + "tone_name": "Analytical" + }, + { + "score": 0.999, + "tone_id": "confident", + "tone_name": "Confident" + }, + { + "score": 0.999, + "tone_id": "tentative", + "tone_name": "Tentative" + } + ], + "category_id": "writing_tone", + "category_name": "Writing Tone" + }, + { + "tones": [ + { + "score": 0.174, + "tone_id": "openness_big5", + "tone_name": "Openness" + }, + { + "score": 0.367, + "tone_id": "conscientiousness_big5", + "tone_name": "Conscientiousness" + }, + { + "score": 0.41, + "tone_id": "extraversion_big5", + "tone_name": "Extraversion" + }, + { + "score": 0.753, + "tone_id": "agreeableness_big5", + "tone_name": "Agreeableness" + }, + { + "score": 0.803, + "tone_id": "neuroticism_big5", + "tone_name": "Emotional Range" + } + ], + "category_id": "social_tone", + "category_name": "Social Tone" + } + ] + }, + { + "sentence_id": 2, + "text": "We have a competitive data analytics product suite in the industry.", + "input_from": 132, + "input_to": 199, + "tone_categories": [ + { + "tones": [ + { + "score": 0.209645, + "tone_id": "anger", + "tone_name": "Anger" + }, + { + "score": 0.193127, + "tone_id": "disgust", + "tone_name": "Disgust" + }, + { + "score": 0.22004, + "tone_id": "fear", + "tone_name": "Fear" + }, + { + "score": 0.206854, + "tone_id": "joy", + "tone_name": "Joy" + }, + { + "score": 0.170334, + "tone_id": "sadness", + "tone_name": "Sadness" + } + ], + "category_id": "emotion_tone", + "category_name": "Emotion Tone" + }, + { + "tones": [ + { + "score": 0.608, + "tone_id": "analytical", + "tone_name": "Analytical" + }, + { + "score": 0.999, + "tone_id": "confident", + "tone_name": "Confident" + }, + { + "score": 0.999, + "tone_id": "tentative", + "tone_name": "Tentative" + } + ], + "category_id": "writing_tone", + "category_name": "Writing Tone" + }, + { + "tones": [ + { + "score": 0.627, + "tone_id": "openness_big5", + "tone_name": "Openness" + }, + { + "score": 0.928, + "tone_id": "conscientiousness_big5", + "tone_name": "Conscientiousness" + }, + { + "score": 0.035, + "tone_id": "extraversion_big5", + "tone_name": "Extraversion" + }, + { + "score": 0.526, + "tone_id": "agreeableness_big5", + "tone_name": "Agreeableness" + }, + { + "score": 0.548, + "tone_id": "neuroticism_big5", + "tone_name": "Emotional Range" + } + ], + "category_id": "social_tone", + "category_name": "Social Tone" + } + ] + }, + { + "sentence_id": 3, + "text": "But we need to do our job selling it!", + "input_from": 200, + "input_to": 237, + "tone_categories": [ + { + "tones": [ + { + "score": 0.056075, + "tone_id": "anger", + "tone_name": "Anger" + }, + { + "score": 0.226992, + "tone_id": "disgust", + "tone_name": "Disgust" + }, + { + "score": 0.252165, + "tone_id": "fear", + "tone_name": "Fear" + }, + { + "score": 0.315444, + "tone_id": "joy", + "tone_name": "Joy" + }, + { + "score": 0.149324, + "tone_id": "sadness", + "tone_name": "Sadness" + } + ], + "category_id": "emotion_tone", + "category_name": "Emotion Tone" + }, + { + "tones": [ + { + "score": 0.722, + "tone_id": "analytical", + "tone_name": "Analytical" + }, + { + "score": 0.999, + "tone_id": "confident", + "tone_name": "Confident" + }, + { + "score": 0.999, + "tone_id": "tentative", + "tone_name": "Tentative" + } + ], + "category_id": "writing_tone", + "category_name": "Writing Tone" + }, + { + "tones": [ + { + "score": 0.02, + "tone_id": "openness_big5", + "tone_name": "Openness" + }, + { + "score": 0.024, + "tone_id": "conscientiousness_big5", + "tone_name": "Conscientiousness" + }, + { + "score": 0.828, + "tone_id": "extraversion_big5", + "tone_name": "Extraversion" + }, + { + "score": 0.946, + "tone_id": "agreeableness_big5", + "tone_name": "Agreeableness" + }, + { + "score": 0.969, + "tone_id": "neuroticism_big5", + "tone_name": "Emotional Range" + } + ], + "category_id": "social_tone", + "category_name": "Social Tone" + } + ] + } + ] +} \ No newline at end of file From d480ea214608abad0b55690c702a28305c8e8111 Mon Sep 17 00:00:00 2001 From: German Attanasio Ruiz Date: Wed, 10 Feb 2016 23:20:17 -0500 Subject: [PATCH 04/14] [code formatting] --- .../com/ibm/watson/developer_cloud/util/ResponseUtil.java | 4 ++-- .../com/ibm/watson/developer_cloud/WatsonServiceTest.java | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ibm/watson/developer_cloud/util/ResponseUtil.java b/src/main/java/com/ibm/watson/developer_cloud/util/ResponseUtil.java index 2f509e5b477..2973a48308f 100644 --- a/src/main/java/com/ibm/watson/developer_cloud/util/ResponseUtil.java +++ b/src/main/java/com/ibm/watson/developer_cloud/util/ResponseUtil.java @@ -109,7 +109,7 @@ public static T getObject(Response response, Class t try { response.body().close(); } catch (IOException e) { - log.log(Level.SEVERE,"Error closing the HTTP Response", e); + log.log(Level.SEVERE, "Error closing the HTTP Response", e); } } } @@ -120,7 +120,7 @@ public static T getObject(Response response, Class t * * @param response an HTTP response * @return the content body as String - * */ + */ public static String getString(Response response) { try { return response.body().string(); diff --git a/src/test/java/com/ibm/watson/developer_cloud/WatsonServiceTest.java b/src/test/java/com/ibm/watson/developer_cloud/WatsonServiceTest.java index 7d20687dee4..df4bac5819a 100755 --- a/src/test/java/com/ibm/watson/developer_cloud/WatsonServiceTest.java +++ b/src/test/java/com/ibm/watson/developer_cloud/WatsonServiceTest.java @@ -52,11 +52,12 @@ public WatsonServiceTest() { setupLogging(); } - protected Map getDefaultHeaders() { - Map headers = new HashMap(); + protected Map getDefaultHeaders() { + Map headers = new HashMap(); headers.put(HttpHeaders.X_WATSON_LEARNING_OPT_OUT, String.valueOf(true)); return headers; } + /** * The Class EmptyPropertyException. */ From af5c7c60275ebaae603d9c10df5e0582d1969b8b Mon Sep 17 00:00:00 2001 From: German Attanasio Ruiz Date: Thu, 11 Feb 2016 16:13:12 -0500 Subject: [PATCH 05/14] merge unit test and integration test results --- .utility/travis.sh | 4 +- pom.xml | 103 ++++++++++++++++++++------------------------- 2 files changed, 49 insertions(+), 58 deletions(-) diff --git a/.utility/travis.sh b/.utility/travis.sh index 00c94ca73f6..511925a5bd5 100755 --- a/.utility/travis.sh +++ b/.utility/travis.sh @@ -2,8 +2,10 @@ if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then echo '$TRAVIS_PULL_REQUEST is false, running all tests' - mvn clean cobertura:cobertura-integration-test coveralls:report + mvn clean integration-test else echo '$TRAVIS_PULL_REQUEST is not false ($TRAVIS_PULL_REQUEST), running unit tests' mvn clean test fi +# merge the unit test and integration test reports +mvn jacoco:merge \ No newline at end of file diff --git a/pom.xml b/pom.xml index f2f705c884e..460358b2318 100644 --- a/pom.xml +++ b/pom.xml @@ -128,23 +128,6 @@ deploy - - - org.codehaus.mojo - cobertura-maven-plugin - 2.7 - - xml - - - com/ibm/watson/developer_cloud/*/v*/model/**/*.class - - - com/ibm/watson/developer_cloud/*/**/*Example.class - - - - org.eluder.coveralls coveralls-maven-plugin @@ -178,47 +161,53 @@ org.jacoco jacoco-maven-plugin 0.7.5.201505241946 - - - com/ibm/watson/developer_cloud/*/v*/model/**/*.class - com/ibm/watson/developer_cloud/**/*Example.* - - - - - - prepare-agent - - - - report - test - - report - - - + + + + ${project.build.directory} + + *.exec + + + + + com/ibm/watson/developer_cloud/*/v*/model/**/*.class + com/ibm/watson/developer_cloud/**/*Example.* + + + + + prepare-unit-test-agent + + prepare-agent + + + + generate-unit-test-report + + report + + + + prepare-integration-test-agent + + prepare-agent-integration + + + + generate-integration-test-report + + report-integration + + + + merge + + merge + + + - From 093ee3f30a5a9bcaad3c69843d5d2b284f6ca3a9 Mon Sep 17 00:00:00 2001 From: German Attanasio Ruiz Date: Thu, 11 Feb 2016 16:59:00 -0500 Subject: [PATCH 06/14] switch back to cobertura --- .utility/travis.sh | 6 ++--- pom.xml | 67 ++++++++++++---------------------------------- 2 files changed, 19 insertions(+), 54 deletions(-) diff --git a/.utility/travis.sh b/.utility/travis.sh index 511925a5bd5..5ec8a6f0f35 100755 --- a/.utility/travis.sh +++ b/.utility/travis.sh @@ -2,10 +2,8 @@ if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then echo '$TRAVIS_PULL_REQUEST is false, running all tests' - mvn clean integration-test + mvn clean cobertura:cobertura-integration-test else echo '$TRAVIS_PULL_REQUEST is not false ($TRAVIS_PULL_REQUEST), running unit tests' mvn clean test -fi -# merge the unit test and integration test reports -mvn jacoco:merge \ No newline at end of file +fi \ No newline at end of file diff --git a/pom.xml b/pom.xml index 460358b2318..55e55df4db9 100644 --- a/pom.xml +++ b/pom.xml @@ -157,56 +157,23 @@ - - org.jacoco - jacoco-maven-plugin - 0.7.5.201505241946 - - - - ${project.build.directory} - - *.exec - - - - - com/ibm/watson/developer_cloud/*/v*/model/**/*.class - com/ibm/watson/developer_cloud/**/*Example.* - - - - - prepare-unit-test-agent - - prepare-agent - - - - generate-unit-test-report - - report - - - - prepare-integration-test-agent - - prepare-agent-integration - - - - generate-integration-test-report - - report-integration - - - - merge - - merge - - - + + org.codehaus.mojo + cobertura-maven-plugin + 2.7 + + xml + html + true + + + com/ibm/watson/developer_cloud/*/v*/model/**/*.class + + + com/ibm/watson/developer_cloud/*/**/*Example.class + + + From 9b7d287f440100a450905acadcccb6b36e19b389 Mon Sep 17 00:00:00 2001 From: German Attanasio Ruiz Date: Thu, 11 Feb 2016 17:06:43 -0500 Subject: [PATCH 07/14] switch back to use cobertura.xml --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index 55e55df4db9..e7ed4896467 100644 --- a/pom.xml +++ b/pom.xml @@ -163,7 +163,6 @@ 2.7 xml - html true From eeebb1ec6b79d8aa3d3c26f74540db4c84554a8b Mon Sep 17 00:00:00 2001 From: German Attanasio Ruiz Date: Thu, 11 Feb 2016 17:20:06 -0500 Subject: [PATCH 08/14] Fixes #190 --- .../concept_insights/v2/ConceptInsights.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/ibm/watson/developer_cloud/concept_insights/v2/ConceptInsights.java b/src/main/java/com/ibm/watson/developer_cloud/concept_insights/v2/ConceptInsights.java index 2175014db5d..65b843d889f 100644 --- a/src/main/java/com/ibm/watson/developer_cloud/concept_insights/v2/ConceptInsights.java +++ b/src/main/java/com/ibm/watson/developer_cloud/concept_insights/v2/ConceptInsights.java @@ -213,7 +213,7 @@ public ConceptInsights() { * @return {@link Annotations} */ public Annotations annotateText(final Graph graph, final String text) { - final String graphId = IDHelper.getGraphId(graph, getAccountId()); + final String graphId = IDHelper.getGraphId(graph, getFirstAccountId()); Validate.notEmpty(text, "text cannot be empty"); final Request request = @@ -243,7 +243,7 @@ public Annotations annotateText(final Graph graph, final String text) { */ public QueryConcepts conceptualSearch(Corpus corpus, Map parameters) { Validate.notNull(parameters.get(IDS), "ids cannot be null"); - final String corpusId = IDHelper.getCorpusId(corpus, getAccountId()); + final String corpusId = IDHelper.getCorpusId(corpus, getFirstAccountId()); final Map queryParams = new HashMap(); final String[] queryParameters = new String[] {CURSOR, LIMIT}; @@ -283,7 +283,7 @@ public QueryConcepts conceptualSearch(Corpus corpus, Map paramet * @param corpus Corpus the corpus object. */ public void createCorpus(final Corpus corpus) { - final String corpusId = IDHelper.getCorpusId(corpus, getAccountId()); + final String corpusId = IDHelper.getCorpusId(corpus, getFirstAccountId()); final Request request = RequestBuilder .put(API_VERSION + corpusId) @@ -314,7 +314,7 @@ public void createDocument(final Document document) { * @param corpus Corpus the corpus object. */ public void deleteCorpus(final Corpus corpus) { - final String corpusId = IDHelper.getCorpusId(corpus, getAccountId()); + final String corpusId = IDHelper.getCorpusId(corpus, getFirstAccountId()); final Request request = RequestBuilder.delete(API_VERSION + corpusId).build(); executeWithoutResponse(request); } @@ -352,11 +352,11 @@ private T executeRequest(final String resourcePath, } /** - * Gets the account id. + * Returns the first account id. * * @return the account id */ - private String getAccountId() { + public String getFirstAccountId() { if (accountId == null) { final Accounts accounts = getAccountsInfo(); if (accounts != null && accounts.getAccounts() != null && !accounts.getAccounts().isEmpty()) { @@ -426,7 +426,7 @@ public Concepts getConceptRelatedConcepts(final Concept concept, * @return the Corpus */ public Corpus getCorpus(final Corpus corpus) { - final String corpusId = IDHelper.getCorpusId(corpus, getAccountId()); + final String corpusId = IDHelper.getCorpusId(corpus, getFirstAccountId()); return executeRequest(API_VERSION + corpusId, null, Corpus.class); } @@ -437,7 +437,7 @@ public Corpus getCorpus(final Corpus corpus) { * @return {@link CorpusProcessingState} The processing state of a given corpus. */ public CorpusProcessingState getCorpusProcessingState(final Corpus corpus) { - final String corpusId = IDHelper.getCorpusId(corpus, getAccountId()); + final String corpusId = IDHelper.getCorpusId(corpus, getFirstAccountId()); return executeRequest(API_VERSION + corpusId + PROCESSING_STATE_PATH, null, CorpusProcessingState.class); } @@ -457,7 +457,7 @@ public CorpusProcessingState getCorpusProcessingState(final Corpus corpus) { * @return {@link Concepts} */ public Concepts getCorpusRelatedConcepts(final Corpus corpus, final Map parameters) { - final String corpusId = IDHelper.getCorpusId(corpus, getAccountId()); + final String corpusId = IDHelper.getCorpusId(corpus, getFirstAccountId()); final Map queryParameters = new HashMap(); final String[] params = new String[] {LEVEL, LIMIT}; @@ -483,7 +483,7 @@ public Concepts getCorpusRelatedConcepts(final Corpus corpus, final Map concepts) { - final String corpusId = IDHelper.getCorpusId(corpus, getAccountId()); + final String corpusId = IDHelper.getCorpusId(corpus, getFirstAccountId()); Validate.notEmpty(concepts, "concepts cannot be empty"); final Map queryParameters = new HashMap(); @@ -505,7 +505,7 @@ public Scores getCorpusRelationScores(final Corpus corpus, final List c * @return the {@link CorpusStats} */ public CorpusStats getCorpusStats(final Corpus corpus) { - final String corpusId = IDHelper.getCorpusId(corpus, getAccountId()); + final String corpusId = IDHelper.getCorpusId(corpus, getFirstAccountId()); return executeRequest(API_VERSION + corpusId + STATS_PATH, null, CorpusStats.class); } @@ -618,7 +618,7 @@ public Scores getDocumentRelationScores(final Document document, final List concepts, final Map parameters) { - final String graphId = IDHelper.getGraphId(graph, getAccountId()); + final String graphId = IDHelper.getGraphId(graph, getFirstAccountId()); Validate.notEmpty(concepts, "concepts cannot be empty"); final Map queryParameters = new HashMap(); @@ -721,7 +721,7 @@ public Corpora listCorpora(final String accountId) { * @return {@link Documents} */ public Documents listDocuments(final Corpus corpus, final Map parameters) { - final String corpusId = IDHelper.getCorpusId(corpus, getAccountId()); + final String corpusId = IDHelper.getCorpusId(corpus, getFirstAccountId()); final Map queryParameters = new HashMap(); final String[] queryParams = new String[] {CURSOR, LIMIT}; @@ -766,7 +766,7 @@ public Graphs listGraphs() { * @return {@link Matches} */ public Matches searchCorpusByLabel(final Corpus corpus, final Map parameters) { - final String corpusId = IDHelper.getCorpusId(corpus, getAccountId()); + final String corpusId = IDHelper.getCorpusId(corpus, getFirstAccountId()); Validate.notEmpty((String) parameters.get(QUERY), "query cannot be empty"); final Map queryParameters = new HashMap(); @@ -809,7 +809,7 @@ public Matches searchCorpusByLabel(final Corpus corpus, final Map parameters) { - final String graphId = IDHelper.getGraphId(graph, getAccountId()); + final String graphId = IDHelper.getGraphId(graph, getFirstAccountId()); Validate.notEmpty((String) parameters.get(QUERY), "query cannot be empty"); final Map queryParameters = new HashMap(); @@ -833,7 +833,7 @@ public Matches searchGraphsConceptByLabel(final Graph graph, final Map Date: Thu, 11 Feb 2016 17:23:28 -0500 Subject: [PATCH 09/14] Update coverage badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a0074a6b1d..a3b5ca0c408 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Watson Developer Cloud Java SDK [![Build Status](https://travis-ci.org/watson-developer-cloud/java-sdk.svg?branch=master)](https://travis-ci.org/watson-developer-cloud/java-sdk) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.ibm.watson.developer_cloud/java-sdk/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.ibm.watson.developer_cloud/java-sdk) -[![Coverage Status](https://coveralls.io/repos/watson-developer-cloud/java-sdk/badge.svg)](https://coveralls.io/github/watson-developer-cloud/java-sdk) +[![codecov.io](https://codecov.io/github/watson-developer-cloud/java-sdk/coverage.svg?branch=master)](https://codecov.io/github/watson-developer-cloud/java-sdk?branch=master) Java client library to use the [Watson Developer Cloud][wdc] services, a collection of REST APIs and SDKs that use cognitive computing to solve complex problems. From 7dd7dd78255454f095e0dbab5772fae09b09c0cc Mon Sep 17 00:00:00 2001 From: German Attanasio Ruiz Date: Thu, 11 Feb 2016 17:29:35 -0500 Subject: [PATCH 10/14] exclude model classes --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index e7ed4896467..043485b7842 100644 --- a/pom.xml +++ b/pom.xml @@ -165,11 +165,11 @@ xml true + + *.model* + - com/ibm/watson/developer_cloud/*/v*/model/**/*.class - - - com/ibm/watson/developer_cloud/*/**/*Example.class + **/*/model/* From 98a62740929dce0944d4349053152bca607e401d Mon Sep 17 00:00:00 2001 From: German Attanasio Ruiz Date: Thu, 11 Feb 2016 17:34:26 -0500 Subject: [PATCH 11/14] [tone-analyzer] v3 updated --- README.md | 12 +++--- .../tone_analyzer/v3/ToneAnalyzerExample.java | 42 +++++++++++++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 examples/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerExample.java diff --git a/README.md b/README.md index a3b5ca0c408..3e9c7591c75 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,6 @@ APIs and SDKs that use cognitive computing to solve complex problems. * [Usage](#usage) * [Getting the Service Credentials](#getting-the-service-credentials) * [Questions](#questions) - * [Examples](#examples) * [IBM Watson Services](#ibm-watson-services) * [Alchemy Language](#alchemy-language) * [Alchemy Vision](#alchemy-vision) @@ -23,9 +22,7 @@ APIs and SDKs that use cognitive computing to solve complex problems. * [Concept Insights](#concept-insights) * [Dialog](#dialog) * [Document Conversion](#document-conversion) - * [Language Identification](#language-identification) * [Language Translation](#language-translation) - * [Machine Translation](#machine-translation) * [Natural Language Classifier](#natural-language-classifier) * [Personality Insights](#personality-insights) * [Relationship Extraction](#relationship-extraction) @@ -38,9 +35,7 @@ APIs and SDKs that use cognitive computing to solve complex problems. * [Visual Recognition](#visual-recognition) * [Android](#android) * [Running in Bluemix](#running-in-bluemix) - * [Build + Test](#build--test) * [Eclipse and Intellij](#working-with-eclipse-and-intellij-idea) - * [Open Source @ IBM](#open-source--ibm) * [License](#license) * [Contributing](#contributing) @@ -365,9 +360,10 @@ System.out.println(voices); Use the [Tone Analyzer][tone_analyzer] service to get the tone of your email. ```java -ToneAnalyzer service = new ToneAnalyzer(); +ToneAnalyzer service = new ToneAnalyzer(ToneAnalyzer.VERSION_DATE_2016_02_11); service.setUsernameAndPassword("", ""); + String text = "I know the times are difficult! Our sales have been " + "disappointing for the past three quarters for our data analytics " + "product suite. We have a competitive data analytics product " @@ -377,6 +373,10 @@ String text = "I know the times are difficult! Our sales have been " // Call the service and get the tone Tone tone = service.getTone(text, Scorecard.EMAIL); System.out.println(tone); + + +ToneAnalysis tone = service.getTone(text); +System.out.println(tone); ``` diff --git a/examples/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerExample.java b/examples/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerExample.java new file mode 100644 index 00000000000..0ad13a5e617 --- /dev/null +++ b/examples/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerExample.java @@ -0,0 +1,42 @@ +/** + * Copyright 2015 IBM Corp. All Rights Reserved. + * + * 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. + */ +package com.ibm.watson.developer_cloud.tone_analyzer.v3; + +import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneAnalysis; + +public class ToneAnalyzerExample { + + + public static void main(String[] args) { + ToneAnalyzer service = new ToneAnalyzer(ToneAnalyzer.VERSION_DATE_2016_02_11); + service.setUsernameAndPassword("", ""); + + String text = + "I know the times are difficult! Our sales have been " + + "disappointing for the past three quarters for our data analytics " + + "product suite. We have a competitive data analytics product " + + "suite in the industry. But we need to do our job selling it! " + + "We need to acknowledge and fix our sales challenges. " + + "We can’t blame the economy for our lack of execution! " + + "We are missing critical sales opportunities. " + + "Our product is in no way inferior to the competitor products. " + + "Our clients are hungry for analytical tools to improve their " + + "business outcomes. Economy has nothing to do with it."; + + // Call the service and get the tone + ToneAnalysis tone = service.getTone(text); + System.out.println(tone); + + } +} From ae51e4680027d55a5d7e6f530669eb3b7f72362e Mon Sep 17 00:00:00 2001 From: German Attanasio Ruiz Date: Thu, 11 Feb 2016 17:36:12 -0500 Subject: [PATCH 12/14] 2.8.0 --- README.md | 8 ++++---- examples/retrieve-and-rank-solrj/pom.xml | 2 +- .../ibm/watson/developer_cloud/service/WatsonService.java | 2 +- .../developer_cloud/service/GenericServiceTest.java | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3e9c7591c75..cc549e5f1cb 100644 --- a/README.md +++ b/README.md @@ -48,13 +48,13 @@ APIs and SDKs that use cognitive computing to solve complex problems. com.ibm.watson.developer_cloud java-sdk - 2.7.1 + 2.8.0 ``` ##### Gradle ```gradle -'com.ibm.watson.developer_cloud:java-sdk:2.7.1' +'com.ibm.watson.developer_cloud:java-sdk:2.8.0' ``` Now, you are ready to see some [examples](https://github.com/watson-developer-cloud/java-sdk/tree/master/examples/java/com/ibm/watson/developer_cloud). @@ -481,7 +481,7 @@ Gradle: ```sh $ cd java-sdk - $ gradle jar # build jar file (build/libs/watson-developer-cloud-2.7.1.jar) + $ gradle jar # build jar file (build/libs/watson-developer-cloud-2.8.0.jar) $ gradle test # run tests ``` @@ -551,4 +551,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md). [apache_maven]: http://maven.apache.org/ [releases]: https://github.com/watson-developer-cloud/java-sdk/releases -[jar]: https://github.com/watson-developer-cloud/java-sdk/releases/download/java-sdk-2.7.1/java-sdk-2.7.1-jar-with-dependencies.jar +[jar]: https://github.com/watson-developer-cloud/java-sdk/releases/download/java-sdk-2.8.0/java-sdk-2.8.0-jar-with-dependencies.jar diff --git a/examples/retrieve-and-rank-solrj/pom.xml b/examples/retrieve-and-rank-solrj/pom.xml index be6efbcccfa..11d348e8d4f 100644 --- a/examples/retrieve-and-rank-solrj/pom.xml +++ b/examples/retrieve-and-rank-solrj/pom.xml @@ -27,7 +27,7 @@ com.ibm.watson.developer_cloud java-sdk - 2.7.1 + 2.8.0 diff --git a/src/main/java/com/ibm/watson/developer_cloud/service/WatsonService.java b/src/main/java/com/ibm/watson/developer_cloud/service/WatsonService.java index 99ce1540b65..f7ef7c878e4 100644 --- a/src/main/java/com/ibm/watson/developer_cloud/service/WatsonService.java +++ b/src/main/java/com/ibm/watson/developer_cloud/service/WatsonService.java @@ -286,7 +286,7 @@ public String getName() { * @return the user agent */ private final String getUserAgent() { - return "watson-developer-cloud-java-sdk-2.7.1"; + return "watson-developer-cloud-java-sdk-2.8.0"; } /** diff --git a/src/test/java/com/ibm/watson/developer_cloud/service/GenericServiceTest.java b/src/test/java/com/ibm/watson/developer_cloud/service/GenericServiceTest.java index b8963ec65b1..fd06a32c154 100644 --- a/src/test/java/com/ibm/watson/developer_cloud/service/GenericServiceTest.java +++ b/src/test/java/com/ibm/watson/developer_cloud/service/GenericServiceTest.java @@ -179,7 +179,7 @@ public void testUserAgentIsSet() { mockAPICall(); service.getProfile(sampleText); mockServer.verify(new HttpRequest().withMethod("POST").withHeader( - new Header(HttpHeaders.USER_AGENT, "watson-developer-cloud-java-sdk-2.7.1"))); + new Header(HttpHeaders.USER_AGENT, "watson-developer-cloud-java-sdk-2.8.0"))); } @Test From 1eeffcd26e9ec79b69b763243803979565f8e31b Mon Sep 17 00:00:00 2001 From: German Attanasio Ruiz Date: Thu, 11 Feb 2016 17:38:37 -0500 Subject: [PATCH 13/14] [maven-release-plugin] prepare release java-sdk-2.8.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 043485b7842..d1ce4d418ee 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.ibm.watson.developer_cloud - 2.7.2-SNAPSHOT + 2.8.0 jar java-sdk Watson Developer Cloud Java SDK @@ -75,7 +75,7 @@ SSH scm:git:git@github.com:watson-developer-cloud/java-sdk.git https://github.com/watson-developer-cloud/java-sdk - HEAD + java-sdk-2.8.0 From 6679ff95c1fb039b6b9ba454ba5cb42be22caacf Mon Sep 17 00:00:00 2001 From: German Attanasio Ruiz Date: Thu, 11 Feb 2016 17:38:39 -0500 Subject: [PATCH 14/14] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d1ce4d418ee..856a512f39a 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.ibm.watson.developer_cloud - 2.8.0 + 2.8.1-SNAPSHOT jar java-sdk Watson Developer Cloud Java SDK @@ -75,7 +75,7 @@ SSH scm:git:git@github.com:watson-developer-cloud/java-sdk.git https://github.com/watson-developer-cloud/java-sdk - java-sdk-2.8.0 + HEAD