-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
TextTranslationClient.java
1250 lines (1210 loc) · 67.6 KB
/
TextTranslationClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.
package com.azure.ai.translation.text;
import com.azure.ai.translation.text.implementation.TextTranslationClientImpl;
import com.azure.ai.translation.text.models.BreakSentenceItem;
import com.azure.ai.translation.text.models.DictionaryExampleItem;
import com.azure.ai.translation.text.models.DictionaryExampleTextItem;
import com.azure.ai.translation.text.models.DictionaryLookupItem;
import com.azure.ai.translation.text.models.GetSupportedLanguagesResult;
import com.azure.ai.translation.text.models.InputTextItem;
import com.azure.ai.translation.text.models.ProfanityAction;
import com.azure.ai.translation.text.models.ProfanityMarker;
import com.azure.ai.translation.text.models.TextType;
import com.azure.ai.translation.text.models.TranslatedTextItem;
import com.azure.ai.translation.text.models.TransliteratedText;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.exception.ClientAuthenticationException;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.exception.ResourceModifiedException;
import com.azure.core.exception.ResourceNotFoundException;
import com.azure.core.http.HttpHeaderName;
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.core.util.BinaryData;
import com.azure.core.util.serializer.TypeReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.azure.ai.translation.text.models.LanguageScope;
import com.azure.ai.translation.text.models.TranslateOptions;
/**
* Initializes a new instance of the synchronous TextTranslationClient type.
*/
@ServiceClient(builder = TextTranslationClientBuilder.class)
public final class TextTranslationClient {
@Generated
private final TextTranslationClientImpl serviceClient;
/**
* Initializes an instance of TextTranslationClient class.
*
* @param serviceClient the service client implementation.
*/
@Generated
TextTranslationClient(TextTranslationClientImpl serviceClient) {
this.serviceClient = serviceClient;
}
/**
* Translate Text.
* <p><strong>Query Parameters</strong></p>
* <table border="1">
* <caption>Query Parameters</caption>
* <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
* <tr><td>from</td><td>String</td><td>No</td><td>Specifies the language of the input text. Find which languages are
* available to translate from by
* looking up supported languages using the translation scope. If the from parameter isn't specified,
* automatic language detection is applied to determine the source language.
*
* You must use the from parameter rather than autodetection when using the dynamic dictionary feature.
* Note: the dynamic dictionary feature is case-sensitive.</td></tr>
* <tr><td>textType</td><td>String</td><td>No</td><td>Defines whether the text being translated is plain text or
* HTML text. Any HTML needs to be a well-formed,
* complete element. Possible values are: plain (default) or html. Allowed values: "Plain", "Html".</td></tr>
* <tr><td>category</td><td>String</td><td>No</td><td>A string specifying the category (domain) of the translation.
* This parameter is used to get translations
* from a customized system built with Custom Translator. Add the Category ID from your Custom Translator
* project details to this parameter to use your deployed customized system. Default value is: general.</td></tr>
* <tr><td>profanityAction</td><td>String</td><td>No</td><td>Specifies how profanities should be treated in
* translations.
* Possible values are: NoAction (default), Marked or Deleted. Allowed values: "NoAction", "Marked",
* "Deleted".</td></tr>
* <tr><td>profanityMarker</td><td>String</td><td>No</td><td>Specifies how profanities should be marked in
* translations.
* Possible values are: Asterisk (default) or Tag. . Allowed values: "Asterisk", "Tag".</td></tr>
* <tr><td>includeAlignment</td><td>Boolean</td><td>No</td><td>Specifies whether to include alignment projection
* from source text to translated text.
* Possible values are: true or false (default).</td></tr>
* <tr><td>includeSentenceLength</td><td>Boolean</td><td>No</td><td>Specifies whether to include sentence boundaries
* for the input text and the translated text.
* Possible values are: true or false (default).</td></tr>
* <tr><td>suggestedFrom</td><td>String</td><td>No</td><td>Specifies a fallback language if the language of the
* input text can't be identified.
* Language autodetection is applied when the from parameter is omitted. If detection fails,
* the suggestedFrom language will be assumed.</td></tr>
* <tr><td>fromScript</td><td>String</td><td>No</td><td>Specifies the script of the input text.</td></tr>
* <tr><td>toScript</td><td>String</td><td>No</td><td>Specifies the script of the translated text.</td></tr>
* <tr><td>allowFallback</td><td>Boolean</td><td>No</td><td>Specifies that the service is allowed to fall back to a
* general system when a custom system doesn't exist.
* Possible values are: true (default) or false.
*
* allowFallback=false specifies that the translation should only use systems trained for the category specified
* by the request. If a translation for language X to language Y requires chaining through a pivot language E,
* then all the systems in the chain (X → E and E → Y) will need to be custom and have the same category.
* If no system is found with the specific category, the request will return a 400 status code. allowFallback=true
* specifies that the service is allowed to fall back to a general system when a custom system doesn't
* exist.</td></tr>
* </table>
* You can add these to a request with {@link RequestOptions#addQueryParam}
* <p><strong>Header Parameters</strong></p>
* <table border="1">
* <caption>Header Parameters</caption>
* <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
* <tr><td>X-ClientTraceId</td><td>String</td><td>No</td><td>A client-generated GUID to uniquely identify the
* request.</td></tr>
* </table>
* You can add these to a request with {@link RequestOptions#addHeader}
* <p><strong>Request Body Schema</strong></p>
*
* <pre>{@code
* [
* (Required){
* text: String (Required)
* }
* ]
* }</pre>
*
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* [
* (Required){
* detectedLanguage (Optional): {
* language: String (Required)
* score: double (Required)
* }
* translations (Required): [
* (Required){
* to: String (Required)
* text: String (Required)
* transliteration (Optional): {
* text: String (Required)
* script: String (Required)
* }
* alignment (Optional): {
* proj: String (Required)
* }
* sentLen (Optional): {
* srcSentLen (Required): [
* int (Required)
* ]
* transSentLen (Required): [
* int (Required)
* ]
* }
* }
* ]
* sourceText (Optional): {
* text: String (Required)
* }
* }
* ]
* }</pre>
*
* @param targetLanguages Specifies the language of the output text. The target language must be one of the
* supported languages included
* in the translation scope. For example, use to=de to translate to German.
* It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string.
* For example, use to=de&to=it to translate to German and Italian.
* @param body Defines the content of the request.
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @return the response body along with {@link Response}.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<BinaryData> translateWithResponse(List<String> targetLanguages, BinaryData body,
RequestOptions requestOptions) {
return this.serviceClient.translateWithResponse(targetLanguages, body, requestOptions);
}
/**
* Transliterate Text.
* <p><strong>Header Parameters</strong></p>
* <table border="1">
* <caption>Header Parameters</caption>
* <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
* <tr><td>X-ClientTraceId</td><td>String</td><td>No</td><td>A client-generated GUID to uniquely identify the
* request.</td></tr>
* </table>
* You can add these to a request with {@link RequestOptions#addHeader}
* <p><strong>Request Body Schema</strong></p>
*
* <pre>{@code
* [
* (Required){
* text: String (Required)
* }
* ]
* }</pre>
*
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* [
* (Required){
* text: String (Required)
* script: String (Required)
* }
* ]
* }</pre>
*
* @param language Specifies the language of the text to convert from one script to another.
* Possible languages are listed in the transliteration scope obtained by querying the service
* for its supported languages.
* @param sourceLanguageScript Specifies the script used by the input text. Look up supported languages using the
* transliteration scope,
* to find input scripts available for the selected language.
* @param targetLanguageScript Specifies the output script. Look up supported languages using the transliteration
* scope, to find output
* scripts available for the selected combination of input language and input script.
* @param body Defines the content of the request.
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @return the response body along with {@link Response}.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<BinaryData> transliterateWithResponse(String language, String sourceLanguageScript,
String targetLanguageScript, BinaryData body, RequestOptions requestOptions) {
return this.serviceClient.transliterateWithResponse(language, sourceLanguageScript, targetLanguageScript, body,
requestOptions);
}
/**
* Find Sentence Boundaries.
* <p><strong>Query Parameters</strong></p>
* <table border="1">
* <caption>Query Parameters</caption>
* <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
* <tr><td>language</td><td>String</td><td>No</td><td>Language tag identifying the language of the input text.
* If a code isn't specified, automatic language detection will be applied.</td></tr>
* <tr><td>script</td><td>String</td><td>No</td><td>Script tag identifying the script used by the input text.
* If a script isn't specified, the default script of the language will be assumed.</td></tr>
* </table>
* You can add these to a request with {@link RequestOptions#addQueryParam}
* <p><strong>Header Parameters</strong></p>
* <table border="1">
* <caption>Header Parameters</caption>
* <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
* <tr><td>X-ClientTraceId</td><td>String</td><td>No</td><td>A client-generated GUID to uniquely identify the
* request.</td></tr>
* </table>
* You can add these to a request with {@link RequestOptions#addHeader}
* <p><strong>Request Body Schema</strong></p>
*
* <pre>{@code
* [
* (Required){
* text: String (Required)
* }
* ]
* }</pre>
*
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* [
* (Required){
* detectedLanguage (Optional): {
* language: String (Required)
* score: double (Required)
* }
* sentLen (Required): [
* int (Required)
* ]
* }
* ]
* }</pre>
*
* @param body Defines the content of the request.
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @return the response body along with {@link Response}.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<BinaryData> findSentenceBoundariesWithResponse(BinaryData body, RequestOptions requestOptions) {
return this.serviceClient.findSentenceBoundariesWithResponse(body, requestOptions);
}
/**
* Lookup Dictionary Entries.
* <p><strong>Header Parameters</strong></p>
* <table border="1">
* <caption>Header Parameters</caption>
* <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
* <tr><td>X-ClientTraceId</td><td>String</td><td>No</td><td>A client-generated GUID to uniquely identify the
* request.</td></tr>
* </table>
* You can add these to a request with {@link RequestOptions#addHeader}
* <p><strong>Request Body Schema</strong></p>
*
* <pre>{@code
* [
* (Required){
* text: String (Required)
* }
* ]
* }</pre>
*
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* [
* (Required){
* normalizedSource: String (Required)
* displaySource: String (Required)
* translations (Required): [
* (Required){
* normalizedTarget: String (Required)
* displayTarget: String (Required)
* posTag: String (Required)
* confidence: double (Required)
* prefixWord: String (Required)
* backTranslations (Required): [
* (Required){
* normalizedText: String (Required)
* displayText: String (Required)
* numExamples: int (Required)
* frequencyCount: int (Required)
* }
* ]
* }
* ]
* }
* ]
* }</pre>
*
* @param sourceLanguage Specifies the language of the input text.
* The source language must be one of the supported languages included in the dictionary scope.
* @param targetLanguage Specifies the language of the output text.
* The target language must be one of the supported languages included in the dictionary scope.
* @param body Defines the content of the request.
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @return the response body along with {@link Response}.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<BinaryData> lookupDictionaryEntriesWithResponse(String sourceLanguage, String targetLanguage,
BinaryData body, RequestOptions requestOptions) {
return this.serviceClient.lookupDictionaryEntriesWithResponse(sourceLanguage, targetLanguage, body,
requestOptions);
}
/**
* Lookup Dictionary Examples.
* <p><strong>Header Parameters</strong></p>
* <table border="1">
* <caption>Header Parameters</caption>
* <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
* <tr><td>X-ClientTraceId</td><td>String</td><td>No</td><td>A client-generated GUID to uniquely identify the
* request.</td></tr>
* </table>
* You can add these to a request with {@link RequestOptions#addHeader}
* <p><strong>Request Body Schema</strong></p>
*
* <pre>{@code
* [
* (Required){
* text: String (Required)
* translation: String (Required)
* }
* ]
* }</pre>
*
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* [
* (Required){
* normalizedSource: String (Required)
* normalizedTarget: String (Required)
* examples (Required): [
* (Required){
* sourcePrefix: String (Required)
* sourceTerm: String (Required)
* sourceSuffix: String (Required)
* targetPrefix: String (Required)
* targetTerm: String (Required)
* targetSuffix: String (Required)
* }
* ]
* }
* ]
* }</pre>
*
* @param sourceLanguage Specifies the language of the input text.
* The source language must be one of the supported languages included in the dictionary scope.
* @param targetLanguage Specifies the language of the output text.
* The target language must be one of the supported languages included in the dictionary scope.
* @param body Defines the content of the request.
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @return the response body along with {@link Response}.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<BinaryData> lookupDictionaryExamplesWithResponse(String sourceLanguage, String targetLanguage,
BinaryData body, RequestOptions requestOptions) {
return this.serviceClient.lookupDictionaryExamplesWithResponse(sourceLanguage, targetLanguage, body,
requestOptions);
}
/**
* Translate Text.
*
* @param targetLanguages Specifies the language of the output text. The target language must be one of the
* supported languages included
* in the translation scope. For example, use to=de to translate to German.
* It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string.
* For example, use to=de&to=it to translate to German and Italian.
* @param body Defines the content of the request.
* @param clientTraceId A client-generated GUID to uniquely identify the request.
* @param sourceLanguage Specifies the language of the input text. Find which languages are available to translate
* from by
* looking up supported languages using the translation scope. If the from parameter isn't specified,
* automatic language detection is applied to determine the source language.
*
* You must use the from parameter rather than autodetection when using the dynamic dictionary feature.
* Note: the dynamic dictionary feature is case-sensitive.
* @param textType Defines whether the text being translated is plain text or HTML text. Any HTML needs to be a
* well-formed,
* complete element. Possible values are: plain (default) or html.
* @param category A string specifying the category (domain) of the translation. This parameter is used to get
* translations
* from a customized system built with Custom Translator. Add the Category ID from your Custom Translator
* project details to this parameter to use your deployed customized system. Default value is: general.
* @param profanityAction Specifies how profanities should be treated in translations.
* Possible values are: NoAction (default), Marked or Deleted.
* @param profanityMarker Specifies how profanities should be marked in translations.
* Possible values are: Asterisk (default) or Tag.
* @param includeAlignment Specifies whether to include alignment projection from source text to translated text.
* Possible values are: true or false (default).
* @param includeSentenceLength Specifies whether to include sentence boundaries for the input text and the
* translated text.
* Possible values are: true or false (default).
* @param suggestedSourceLanguage Specifies a fallback language if the language of the input text can't be
* identified.
* Language autodetection is applied when the from parameter is omitted. If detection fails,
* the suggestedFrom language will be assumed.
* @param sourceLanguageScript Specifies the script of the input text.
* @param targetLanguageScript Specifies the script of the translated text.
* @param allowFallback Specifies that the service is allowed to fall back to a general system when a custom system
* doesn't exist.
* Possible values are: true (default) or false.
*
* allowFallback=false specifies that the translation should only use systems trained for the category specified
* by the request. If a translation for language X to language Y requires chaining through a pivot language E,
* then all the systems in the chain (X → E and E → Y) will need to be custom and have the same category.
* If no system is found with the specific category, the request will return a 400 status code. allowFallback=true
* specifies that the service is allowed to fall back to a general system when a custom system doesn't exist.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
private List<TranslatedTextItem> translate(List<String> targetLanguages, List<InputTextItem> body,
String clientTraceId, String sourceLanguage, TextType textType, String category,
ProfanityAction profanityAction, ProfanityMarker profanityMarker, Boolean includeAlignment,
Boolean includeSentenceLength, String suggestedSourceLanguage, String sourceLanguageScript,
String targetLanguageScript, Boolean allowFallback) {
// Generated convenience method for translateWithResponse
RequestOptions requestOptions = new RequestOptions();
if (clientTraceId != null) {
requestOptions.setHeader(HttpHeaderName.fromString("X-ClientTraceId"), clientTraceId);
}
if (sourceLanguage != null) {
requestOptions.addQueryParam("from", sourceLanguage, false);
}
if (textType != null) {
requestOptions.addQueryParam("textType", textType.toString(), false);
}
if (category != null) {
requestOptions.addQueryParam("category", category, false);
}
if (profanityAction != null) {
requestOptions.addQueryParam("profanityAction", profanityAction.toString(), false);
}
if (profanityMarker != null) {
requestOptions.addQueryParam("profanityMarker", profanityMarker.toString(), false);
}
if (includeAlignment != null) {
requestOptions.addQueryParam("includeAlignment", String.valueOf(includeAlignment), false);
}
if (includeSentenceLength != null) {
requestOptions.addQueryParam("includeSentenceLength", String.valueOf(includeSentenceLength), false);
}
if (suggestedSourceLanguage != null) {
requestOptions.addQueryParam("suggestedFrom", suggestedSourceLanguage, false);
}
if (sourceLanguageScript != null) {
requestOptions.addQueryParam("fromScript", sourceLanguageScript, false);
}
if (targetLanguageScript != null) {
requestOptions.addQueryParam("toScript", targetLanguageScript, false);
}
if (allowFallback != null) {
requestOptions.addQueryParam("allowFallback", String.valueOf(allowFallback), false);
}
return translateWithResponse(targetLanguages, BinaryData.fromObject(body), requestOptions).getValue()
.toObject(TYPE_REFERENCE_LIST_TRANSLATED_TEXT_ITEM);
}
/**
* Translate Text.
*
* @param targetLanguages Specifies the language of the output text. The target language must be one of the
* supported languages included
* in the translation scope. For example, use to=de to translate to German.
* It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string.
* For example, use to=de&to=it to translate to German and Italian.
* @param body Defines the content of the request.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
private List<TranslatedTextItem> translateInner(List<String> targetLanguages, List<InputTextItem> body) {
// Generated convenience method for translateWithResponse
RequestOptions requestOptions = new RequestOptions();
return translateWithResponse(targetLanguages, BinaryData.fromObject(body), requestOptions).getValue()
.toObject(TYPE_REFERENCE_LIST_TRANSLATED_TEXT_ITEM);
}
/**
* Translate Text.
* <p>
* This method is used when you have single target language and multiple texts to translate.
* </p>
*
* @param targetLanguage Specifies the language of the output text. The target language must be one of the
* supported languages included
* in the translation scope. For example, use to=de to translate to German.
* It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string.
* For example, use to=de&to=it to translate to German and Italian.
* @param texts Defines the content of the request.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public List<TranslatedTextItem> translate(String targetLanguage, List<String> texts) {
return translateInner(Arrays.asList(targetLanguage), convertTextToData(texts));
}
/**
* Translate Text.
* <p>
* This method is used when you have single target language and single text to translate.
* </p>
*
* @param targetLanguage Specifies the language of the output text. The target language must be one of the
* supported languages included
* in the translation scope. For example, use to=de to translate to German.
* It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string.
* For example, use to=de&to=it to translate to German and Italian.
* @param text Defines the content of the request.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public TranslatedTextItem translate(String targetLanguage, String text) {
return translate(targetLanguage, Arrays.asList(text)).get(0);
}
/**
* Translate Text.
* <p>
* This method is used when you have one input text and the optional parameters are needed such as specification
* of a source language, profanity handling etc.
* </p>
*
* @param text Text to translate.
* @param translateOptions Translate Options.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public TranslatedTextItem translate(String text, TranslateOptions translateOptions) {
return translate(Arrays.asList(text), translateOptions).get(0);
}
/**
* Translate Text.
* <p>
* This method is used when you have multiple texts and the optional parameters are needed such as specification
* of a source language, profanity handling etc..
* </p>
*
* @param texts List of text to translate.
* @param translateOptions Translate Options.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public List<TranslatedTextItem> translate(List<String> texts, TranslateOptions translateOptions) {
List<InputTextItem> content = new ArrayList<>();
for (String text : texts) {
content.add(new InputTextItem(text));
}
return translate(translateOptions.getTargetLanguages(), content, translateOptions.getClientTraceId(),
translateOptions.getSourceLanguage(), translateOptions.getTextType(), translateOptions.getCategory(),
translateOptions.getProfanityAction(), translateOptions.getProfanityMarker(),
translateOptions.isIncludeAlignment(), translateOptions.isIncludeSentenceLength(),
translateOptions.getSuggestedSourceLanguage(), translateOptions.getSourceLanguageScript(),
translateOptions.getTargetLanguageScript(), translateOptions.isAllowFallback());
}
/**
* Transliterate Text.
*
* @param language Specifies the language of the text to convert from one script to another.
* Possible languages are listed in the transliteration scope obtained by querying the service
* for its supported languages.
* @param sourceLanguageScript Specifies the script used by the input text. Look up supported languages using the
* transliteration scope,
* to find input scripts available for the selected language.
* @param targetLanguageScript Specifies the output script. Look up supported languages using the transliteration
* scope, to find output
* scripts available for the selected combination of input language and input script.
* @param body Defines the content of the request.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
private List<TransliteratedText> transliterateInner(String language, String sourceLanguageScript,
String targetLanguageScript, List<InputTextItem> body) {
// Generated convenience method for transliterateWithResponse
RequestOptions requestOptions = new RequestOptions();
return transliterateWithResponse(language, sourceLanguageScript, targetLanguageScript,
BinaryData.fromObject(body), requestOptions).getValue().toObject(TYPE_REFERENCE_LIST_TRANSLITERATED_TEXT);
}
/**
* Transliterate Text.
* <p>
* This method is used when you have multiple texts to transliterate and you want to provide client trace id.
* </p>
*
* @param language Specifies the language of the text to convert from one script to another.
* Possible languages are listed in the transliteration scope obtained by querying the service
* for its supported languages.
* @param sourceLanguageScript Specifies the script used by the input text. Look up supported languages using the
* transliteration scope,
* to find input scripts available for the selected language.
* @param targetLanguageScript Specifies the output script. Look up supported languages using the transliteration
* scope, to find output
* scripts available for the selected combination of input language and input script.
* @param body Defines the content of the request.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public List<TransliteratedText> transliterate(String language, String sourceLanguageScript,
String targetLanguageScript, List<String> body) {
return transliterateInner(language, sourceLanguageScript, targetLanguageScript, convertTextToData(body));
}
/**
* Transliterate Text.
* <p>
* This method is used when you have single text to transliterate and you want to provide client trace id.
* </p>
*
* @param language Specifies the language of the text to convert from one script to another.
* Possible languages are listed in the transliteration scope obtained by querying the service
* for its supported languages.
* @param sourceLanguageScript Specifies the script used by the input text. Look up supported languages using the
* transliteration scope,
* to find input scripts available for the selected language.
* @param targetLanguageScript Specifies the output script. Look up supported languages using the transliteration
* scope, to find output
* scripts available for the selected combination of input language and input script.
* @param text Defines the content of the request.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public TransliteratedText transliterate(String language, String sourceLanguageScript, String targetLanguageScript,
String text) {
return transliterate(language, sourceLanguageScript, targetLanguageScript, Arrays.asList(text)).get(0);
}
/**
* Find Sentence Boundaries.
*
* @param body Defines the content of the request.
* @param language Language tag identifying the language of the input text.
* If a code isn't specified, automatic language detection will be applied.
* @param script Script tag identifying the script used by the input text.
* If a script isn't specified, the default script of the language will be assumed.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
private List<BreakSentenceItem> findSentenceBoundariesInner(List<InputTextItem> body, String language,
String script) {
// Generated convenience method for findSentenceBoundariesWithResponse
RequestOptions requestOptions = new RequestOptions();
if (language != null) {
requestOptions.addQueryParam("language", language, false);
}
if (script != null) {
requestOptions.addQueryParam("script", script, false);
}
return findSentenceBoundariesWithResponse(BinaryData.fromObject(body), requestOptions).getValue()
.toObject(TYPE_REFERENCE_LIST_BREAK_SENTENCE_ITEM);
}
/**
* Find Sentence Boundaries.
* <p>
* This method is used when you have multiple texts for which you want to find sentence boundaries and you want to
* provide
* client trace id.
* </p>
*
* @param texts Defines the content of the request.
* @param language Language tag identifying the language of the input text.
* If a code isn't specified, automatic language detection will be applied.
* @param script Script tag identifying the script used by the input text.
* If a script isn't specified, the default script of the language will be assumed.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public List<BreakSentenceItem> findSentenceBoundaries(List<String> texts, String language, String script) {
return findSentenceBoundariesInner(convertTextToData(texts), language, script);
}
/**
* Find Sentence Boundaries.
* <p>
* This method is used when you have single text for which you want to find sentence boundaries and you want to
* provide
* client trace id.
* </p>
*
* @param text Defines the content of the request.
* @param language Language tag identifying the language of the input text.
* If a code isn't specified, automatic language detection will be applied.
* @param script Script tag identifying the script used by the input text.
* If a script isn't specified, the default script of the language will be assumed.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public BreakSentenceItem findSentenceBoundaries(String text, String language, String script) {
return findSentenceBoundaries(Arrays.asList(text), language, script).get(0);
}
/**
* Find Sentence Boundaries.
*
* @param body Defines the content of the request.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
private List<BreakSentenceItem> findSentenceBoundariesInner(List<InputTextItem> body) {
// Generated convenience method for findSentenceBoundariesWithResponse
RequestOptions requestOptions = new RequestOptions();
return findSentenceBoundariesWithResponse(BinaryData.fromObject(body), requestOptions).getValue()
.toObject(TYPE_REFERENCE_LIST_BREAK_SENTENCE_ITEM);
}
/**
* Find Sentence Boundaries.
* <p>
* This method is used when you have multiple texts for which you want to find sentence boundaries and you want
* the source language to be auto-detected by the service.
* </p>
*
* @param texts Defines the content of the request.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public List<BreakSentenceItem> findSentenceBoundaries(List<String> texts) {
return findSentenceBoundariesInner(convertTextToData(texts));
}
/**
* Find Sentence Boundaries.
* <p>
* This method is used when you have single text for which you want to find sentence boundaries and you want
* the source language to be auto-detected by the service.
* </p>
*
* @param text Defines the content of the request.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public BreakSentenceItem findSentenceBoundaries(String text) {
return findSentenceBoundaries(Arrays.asList(text)).get(0);
}
/**
* Lookup Dictionary Entries.
*
* @param sourceLanguage Specifies the language of the input text.
* The source language must be one of the supported languages included in the dictionary scope.
* @param targetLanguage Specifies the language of the output text.
* The target language must be one of the supported languages included in the dictionary scope.
* @param body Defines the content of the request.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
private List<DictionaryLookupItem> lookupDictionaryEntriesInner(String sourceLanguage, String targetLanguage,
List<InputTextItem> body) {
// Generated convenience method for lookupDictionaryEntriesWithResponse
RequestOptions requestOptions = new RequestOptions();
return lookupDictionaryEntriesWithResponse(sourceLanguage, targetLanguage, BinaryData.fromObject(body),
requestOptions).getValue().toObject(TYPE_REFERENCE_LIST_DICTIONARY_LOOKUP_ITEM);
}
/**
* Lookup Dictionary Entries.
* <p>
* This method is used when you want lookup multiple entries in the dictionary and you want to provide
* client trace id.
* </p>
*
* @param sourceLanguage Specifies the language of the input text.
* The source language must be one of the supported languages included in the dictionary scope.
* @param targetLanguage Specifies the language of the output text.
* The target language must be one of the supported languages included in the dictionary scope.
* @param texts Defines the content of the request.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public List<DictionaryLookupItem> lookupDictionaryEntries(String sourceLanguage, String targetLanguage,
List<String> texts) {
return lookupDictionaryEntriesInner(sourceLanguage, targetLanguage, convertTextToData(texts));
}
/**
* Lookup Dictionary Entries.
* <p>
* This method is used when you want lookup single entry in the dictionary and you want to provide
* client trace id.
* </p>
*
* @param sourceLanguage Specifies the language of the input text.
* The source language must be one of the supported languages included in the dictionary scope.
* @param targetLanguage Specifies the language of the output text.
* The target language must be one of the supported languages included in the dictionary scope.
* @param text Defines the content of the request.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public DictionaryLookupItem lookupDictionaryEntries(String sourceLanguage, String targetLanguage, String text) {
return lookupDictionaryEntries(sourceLanguage, targetLanguage, Arrays.asList(text)).get(0);
}
/**
* Lookup Dictionary Examples.
*
* @param sourceLanguage Specifies the language of the input text.
* The source language must be one of the supported languages included in the dictionary scope.
* @param targetLanguage Specifies the language of the output text.
* The target language must be one of the supported languages included in the dictionary scope.
* @param body Defines the content of the request.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public List<DictionaryExampleItem> lookupDictionaryExamples(String sourceLanguage, String targetLanguage,
List<DictionaryExampleTextItem> body) {
// Generated convenience method for lookupDictionaryExamplesWithResponse
RequestOptions requestOptions = new RequestOptions();
return lookupDictionaryExamplesWithResponse(sourceLanguage, targetLanguage, BinaryData.fromObject(body),
requestOptions).getValue().toObject(TYPE_REFERENCE_LIST_DICTIONARY_EXAMPLE_ITEM);
}
@Generated
private static final TypeReference<List<TransliteratedText>> TYPE_REFERENCE_LIST_TRANSLITERATED_TEXT
= new TypeReference<List<TransliteratedText>>() {
};
@Generated
private static final TypeReference<List<BreakSentenceItem>> TYPE_REFERENCE_LIST_BREAK_SENTENCE_ITEM
= new TypeReference<List<BreakSentenceItem>>() {
};