Skip to content

Commit 7405900

Browse files
committed
Add ability to indicate no sentence-level analysis with tone() method
1 parent 015f42c commit 7405900

2 files changed

Lines changed: 43 additions & 19 deletions

File tree

‎tone-analyzer/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/model/ToneOptions.java‎

100644100755
Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public static class Builder {
3636
private Boolean includeSentences;
3737
private List<Tone> tones;
3838

39-
4039
/**
4140
* Instantiates a new builder.
4241
*/
@@ -56,18 +55,29 @@ public Builder(ToneOptions options) {
5655
/**
5756
* Sets the text as HTML.
5857
*
59-
* @param isHtml set the text as html
58+
* @param isHtml sets the text as html
6059
* @return the builder
6160
*/
6261
public Builder html(Boolean isHtml) {
6362
this.isHtml = isHtml;
6463
return this;
6564
}
6665

66+
/**
67+
* Indicates whether to return sentence-level tone analysis.
68+
*
69+
* @param sentences sets sentence-level analysis.
70+
* @return the builder
71+
*/
72+
public Builder includeSentences(Boolean sentences) {
73+
this.includeSentences = sentences;
74+
return this;
75+
}
76+
6777
/**
6878
* Adds the tone.
6979
*
70-
* @param tone the tone
80+
* @param tone the tone to add
7181
* @return the builder
7282
*/
7383
public Builder addTone(Tone tone) {
@@ -83,7 +93,7 @@ public Builder addTone(Tone tone) {
8393
/**
8494
* Builds the {@link ToneOptions} object.
8595
*
86-
* @return the gets the tone options
96+
* @return the tone options object
8797
*/
8898
public ToneOptions build() {
8999
return new ToneOptions(this);
@@ -97,40 +107,39 @@ private ToneOptions(Builder builder) {
97107
}
98108

99109
/**
100-
* Gets the html.
110+
* Gets the isHtml.
101111
*
102-
* @return the html
112+
* @return the isHtml attribute
103113
*/
104114
public Boolean html() {
105115
return isHtml;
106116
}
107117

108-
109118
/**
110-
* include sentences.
119+
* Get the includeSentences.
111120
*
112-
* @return the text
121+
* @return the includeSentences attribute
113122
*/
114123
public Boolean includeSentences() {
115124
return includeSentences;
116125
}
117126

118127
/**
119-
* New builder.
128+
* Gets the tones.
120129
*
121-
* @return the builder
130+
* @return the list of tones
122131
*/
123-
public Builder newBuilder() {
124-
return new Builder(this);
132+
public List<Tone> tones() {
133+
return tones;
125134
}
126135

127136
/**
128-
* Gets the tones.
137+
* New builder.
129138
*
130-
* @return the tone list
139+
* @return the builder
131140
*/
132-
public List<Tone> tones() {
133-
return tones;
141+
public Builder newBuilder() {
142+
return new Builder(this);
134143
}
135144

136145
}

‎tone-analyzer/src/test/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerIT.java‎

100644100755
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,32 @@ public void setUp() throws Exception {
7171
}
7272

7373
/**
74-
* Test get tone from text.
74+
* Test get tone from text with sentences.
7575
*/
7676
@Test
77-
public void testGetToneFromText() {
77+
public void testGetToneFromTextWithSentences() {
7878
ToneOptions options =
7979
new ToneOptions.Builder().addTone(Tone.EMOTION).addTone(Tone.LANGUAGE).addTone(Tone.SOCIAL).build();
8080

8181
ToneAnalysis tone = service.getTone(text, options).execute();
8282
assertToneAnalysis(tone);
8383
}
8484

85+
/**
86+
* Test get tone from text without sentences.
87+
*/
88+
@Test
89+
public void testGetToneFromTextWithoutSentences() {
90+
ToneOptions options =
91+
new ToneOptions.Builder().includeSentences(false).build();
92+
93+
ToneAnalysis tone = service.getTone(text, options).execute();
94+
Assert.assertNotNull(tone);
95+
Assert.assertNotNull(tone.getDocumentTone());
96+
Assert.assertEquals(3, tone.getDocumentTone().getTones().size());
97+
Assert.assertNull(tone.getSentencesTone());
98+
}
99+
85100
/**
86101
* Test get tone from html.
87102
*/

0 commit comments

Comments
 (0)