Skip to content

Commit 0c676db

Browse files
Merge branch 'pr/241'
2 parents e1ab4b8 + 916c42e commit 0c676db

File tree

4 files changed

+68
-24
lines changed

4 files changed

+68
-24
lines changed

src/main/java/com/ibm/watson/developer_cloud/language_translation/v2/LanguageTranslation.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
22
* Copyright 2015 IBM Corp. All Rights Reserved.
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
55
* in compliance with the License. You may obtain a copy of the License at
6-
*
6+
*
77
* http://www.apache.org/licenses/LICENSE-2.0
8-
*
8+
*
99
* Unless required by applicable law or agreed to in writing, software distributed under the License
1010
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
1111
* or implied. See the License for the specific language governing permissions and limitations under
@@ -24,6 +24,7 @@
2424
import com.ibm.watson.developer_cloud.language_translation.v2.model.CreateModelOptions;
2525
import com.ibm.watson.developer_cloud.language_translation.v2.model.IdentifiableLanguage;
2626
import com.ibm.watson.developer_cloud.language_translation.v2.model.IdentifiedLanguage;
27+
import com.ibm.watson.developer_cloud.language_translation.v2.model.Language;
2728
import com.ibm.watson.developer_cloud.language_translation.v2.model.LanguageList;
2829
import com.ibm.watson.developer_cloud.language_translation.v2.model.TranslationModel;
2930
import com.ibm.watson.developer_cloud.language_translation.v2.model.TranslationModelList;
@@ -37,7 +38,7 @@
3738
/**
3839
* The IBM Watson Language Translation service translate text from one language to another and
3940
* identifies the language in which text is written.
40-
*
41+
*
4142
* @version v2
4243
* @see <a href=
4344
* "http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/language-translation.html">
@@ -92,7 +93,7 @@ public LanguageTranslation() {
9293

9394
/**
9495
* Creates a translation models.
95-
*
96+
*
9697
* @param options the create model options
9798
* @return the translation model
9899
*/
@@ -125,7 +126,7 @@ public TranslationModel createModel(CreateModelOptions options) {
125126

126127
/**
127128
* Deletes a translation models.
128-
*
129+
*
129130
* @param modelId the model identifier
130131
*/
131132
public void deleteModel(String modelId) {
@@ -138,7 +139,7 @@ public void deleteModel(String modelId) {
138139

139140
/**
140141
* Retrieves the list of identifiable languages.
141-
*
142+
*
142143
* @return the identifiable languages
143144
* @see TranslationModel
144145
*/
@@ -150,7 +151,7 @@ public List<IdentifiableLanguage> getIdentifiableLanguages() {
150151

151152
/**
152153
* Retrieves a translation models.
153-
*
154+
*
154155
* @param modelId the model identifier
155156
* @return the translation models
156157
* @see TranslationModel
@@ -165,7 +166,7 @@ public TranslationModel getModel(String modelId) {
165166

166167
/**
167168
* Retrieves the list of translation models.
168-
*
169+
*
169170
* @return the translation models
170171
* @see TranslationModel
171172
*/
@@ -175,7 +176,7 @@ public List<TranslationModel> getModels() {
175176

176177
/**
177178
* Retrieves the list of models.
178-
*
179+
*
179180
* @param showDefault show default models
180181
* @param source the source
181182
* @param target the target
@@ -202,7 +203,7 @@ public List<TranslationModel> getModels(final Boolean showDefault, final String
202203

203204
/**
204205
* Identify language in which text is written.
205-
*
206+
*
206207
* @param text the text to identify
207208
* @return the identified language
208209
*/
@@ -219,7 +220,7 @@ public List<IdentifiedLanguage> identify(final String text) {
219220

220221
/**
221222
* Translate text using a model.
222-
*
223+
*
223224
* @param text The submitted paragraphs to translate
224225
* @param modelId the model id
225226
* @return The {@link TranslationResult}
@@ -233,32 +234,32 @@ public TranslationResult translate(final String text, final String modelId) {
233234
* Translate text using source and target languages.<br>
234235
* <br>
235236
* Here is an example of how to translate "hello" from English to Spanish:
236-
*
237-
*
237+
*
238+
*
238239
* <pre>
239240
* LanguageTranslation service = new LanguageTranslation();
240241
* service.setUsernameAndPassword(&quot;USERNAME&quot;, &quot;PASSWORD&quot;);
241-
*
242+
*
242243
* TranslationResult translationResult = service.translate(&quot;hello&quot;, &quot;en&quot;, &quot;es&quot;);
243-
*
244+
*
244245
* System.out.println(translationResult);
245246
* </pre>
246-
*
247+
*
247248
* @param text The submitted paragraphs to translate
248249
* @param source The source language
249250
* @param target The target language
250251
* @return The {@link TranslationResult}
251252
*/
252-
public TranslationResult translate(final String text, final String source, final String target) {
253-
Validate.isTrue(source != null && !source.isEmpty(), "source cannot be null or empty");
254-
Validate.isTrue(target != null && !target.isEmpty(), "target cannot be null or empty");
255-
return translateRequest(text, null, source, target);
253+
public TranslationResult translate(final String text, final Language source, final Language target) {
254+
Validate.isTrue(source != null, "source cannot be null");
255+
Validate.isTrue(target != null, "target cannot be null");
256+
return translateRequest(text, null, source.toString(), target.toString());
256257
}
257258

258259
/**
259260
* Translate paragraphs of text using a model and or source and target. model_id or source and
260261
* target needs to be specified. If both are specified, then only model_id will be used
261-
*
262+
*
262263
* @param text the text
263264
* @param modelId the model id
264265
* @param source the source
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.ibm.watson.developer_cloud.language_translation.v2.model;
2+
3+
public enum Language {
4+
5+
ARABIC {
6+
@Override
7+
public String toString() {
8+
return "ar";
9+
}
10+
}, ENGLISH {
11+
@Override
12+
public String toString() {
13+
return "en";
14+
}
15+
}, SPANISH {
16+
@Override
17+
public String toString() {
18+
return "es";
19+
}
20+
}, FRENCH {
21+
@Override
22+
public String toString() {
23+
return "fr";
24+
}
25+
}, ITALIAN {
26+
@Override
27+
public String toString() {
28+
return "it";
29+
}
30+
}, PORTUGUESE {
31+
@Override
32+
public String toString() {
33+
return "pt";
34+
}
35+
};
36+
37+
@Override
38+
public String toString() {
39+
return "";
40+
}
41+
}

src/test/java/com/ibm/watson/developer_cloud/language_translation/v2/LanguageTranslationIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.ibm.watson.developer_cloud.language_translation.v2.model.IdentifiableLanguage;
3030
import com.ibm.watson.developer_cloud.language_translation.v2.model.IdentifiedLanguage;
3131
import com.ibm.watson.developer_cloud.language_translation.v2.model.TranslationModel;
32+
import com.ibm.watson.developer_cloud.language_translation.v2.model.Language;
3233
import com.ibm.watson.developer_cloud.language_translation.v2.model.TranslationResult;
3334

3435
/**
@@ -129,7 +130,7 @@ public void testIdentify() {
129130
public void testTranslate() {
130131
final String result = "El equipo es increíble IBM Watson";
131132
testTranslationResult(text, result, service.translate(text, ENGLISH_TO_SPANISH));
132-
testTranslationResult(text, result, service.translate(text, ENGLISH, SPANISH));
133+
testTranslationResult(text, result, service.translate(text, Language.ENGLISH, Language.SPANISH));
133134
}
134135

135136
private void testTranslationResult(String text, String result, TranslationResult translationResult) {

src/test/java/com/ibm/watson/developer_cloud/language_translation/v2/LanguageTranslationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.ibm.watson.developer_cloud.language_translation.v2.model.CreateModelOptions;
4040
import com.ibm.watson.developer_cloud.language_translation.v2.model.IdentifiableLanguage;
4141
import com.ibm.watson.developer_cloud.language_translation.v2.model.IdentifiedLanguage;
42+
import com.ibm.watson.developer_cloud.language_translation.v2.model.Language;
4243
import com.ibm.watson.developer_cloud.language_translation.v2.model.LanguageList;
4344
import com.ibm.watson.developer_cloud.language_translation.v2.model.Translation;
4445
import com.ibm.watson.developer_cloud.language_translation.v2.model.TranslationModel;
@@ -255,7 +256,7 @@ public void testTranslateNotSupported() {
255256
*/
256257
@Test(expected = IllegalArgumentException.class)
257258
public void testTranslateWithNull() {
258-
service.translate(null, "", "");
259+
service.translate(null, null, null);
259260

260261
}
261262

0 commit comments

Comments
 (0)