-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
AITranslationTextModelFactory.cs
364 lines (331 loc) · 24.3 KB
/
AITranslationTextModelFactory.cs
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// <auto-generated/>
#nullable disable
using System.Collections.Generic;
using System.Linq;
namespace Azure.AI.Translation.Text
{
/// <summary> Model factory for models. </summary>
public static partial class AITranslationTextModelFactory
{
/// <summary> Initializes a new instance of <see cref="Text.GetSupportedLanguagesResult"/>. </summary>
/// <param name="translation"> Languages that support translate API. </param>
/// <param name="transliteration"> Languages that support transliteration API. </param>
/// <param name="dictionary"> Languages that support dictionary API. </param>
/// <returns> A new <see cref="Text.GetSupportedLanguagesResult"/> instance for mocking. </returns>
public static GetSupportedLanguagesResult GetSupportedLanguagesResult(IReadOnlyDictionary<string, TranslationLanguage> translation = null, IReadOnlyDictionary<string, TransliterationLanguage> transliteration = null, IReadOnlyDictionary<string, SourceDictionaryLanguage> dictionary = null)
{
translation ??= new Dictionary<string, TranslationLanguage>();
transliteration ??= new Dictionary<string, TransliterationLanguage>();
dictionary ??= new Dictionary<string, SourceDictionaryLanguage>();
return new GetSupportedLanguagesResult(translation, transliteration, dictionary, serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.TranslationLanguage"/>. </summary>
/// <param name="name"> Display name of the language in the locale requested via Accept-Language header. </param>
/// <param name="nativeName"> Display name of the language in the locale native for this language. </param>
/// <param name="directionality"> Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. </param>
/// <returns> A new <see cref="Text.TranslationLanguage"/> instance for mocking. </returns>
public static TranslationLanguage TranslationLanguage(string name = null, string nativeName = null, LanguageDirectionality directionality = default)
{
return new TranslationLanguage(name, nativeName, directionality, serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.TransliterationLanguage"/>. </summary>
/// <param name="name"> Display name of the language in the locale requested via Accept-Language header. </param>
/// <param name="nativeName"> Display name of the language in the locale native for this language. </param>
/// <param name="scripts"> List of scripts to convert from. </param>
/// <returns> A new <see cref="Text.TransliterationLanguage"/> instance for mocking. </returns>
public static TransliterationLanguage TransliterationLanguage(string name = null, string nativeName = null, IEnumerable<TransliterableScript> scripts = null)
{
scripts ??= new List<TransliterableScript>();
return new TransliterationLanguage(name, nativeName, scripts?.ToList(), serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.TransliterableScript"/>. </summary>
/// <param name="code"> Code identifying the script. </param>
/// <param name="name"> Display name of the script in the locale requested via Accept-Language header. </param>
/// <param name="nativeName"> Display name of the language in the locale native for the language. </param>
/// <param name="directionality"> Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. </param>
/// <param name="targetLanguageScripts"> List of scripts available to convert text to. </param>
/// <returns> A new <see cref="Text.TransliterableScript"/> instance for mocking. </returns>
public static TransliterableScript TransliterableScript(string code = null, string name = null, string nativeName = null, LanguageDirectionality directionality = default, IEnumerable<LanguageScript> targetLanguageScripts = null)
{
targetLanguageScripts ??= new List<LanguageScript>();
return new TransliterableScript(
code,
name,
nativeName,
directionality,
serializedAdditionalRawData: null,
targetLanguageScripts?.ToList());
}
/// <summary> Initializes a new instance of <see cref="Text.LanguageScript"/>. </summary>
/// <param name="code"> Code identifying the script. </param>
/// <param name="name"> Display name of the script in the locale requested via Accept-Language header. </param>
/// <param name="nativeName"> Display name of the language in the locale native for the language. </param>
/// <param name="directionality"> Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. </param>
/// <returns> A new <see cref="Text.LanguageScript"/> instance for mocking. </returns>
public static LanguageScript LanguageScript(string code = null, string name = null, string nativeName = null, LanguageDirectionality directionality = default)
{
return new LanguageScript(code, name, nativeName, directionality, serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.SourceDictionaryLanguage"/>. </summary>
/// <param name="name"> Display name of the language in the locale requested via Accept-Language header. </param>
/// <param name="nativeName"> Display name of the language in the locale native for this language. </param>
/// <param name="directionality"> Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. </param>
/// <param name="translations"> List of languages with alterative translations and examples for the query expressed in the source language. </param>
/// <returns> A new <see cref="Text.SourceDictionaryLanguage"/> instance for mocking. </returns>
public static SourceDictionaryLanguage SourceDictionaryLanguage(string name = null, string nativeName = null, LanguageDirectionality directionality = default, IEnumerable<TargetDictionaryLanguage> translations = null)
{
translations ??= new List<TargetDictionaryLanguage>();
return new SourceDictionaryLanguage(name, nativeName, directionality, translations?.ToList(), serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.TargetDictionaryLanguage"/>. </summary>
/// <param name="name"> Display name of the language in the locale requested via Accept-Language header. </param>
/// <param name="nativeName"> Display name of the language in the locale native for this language. </param>
/// <param name="directionality"> Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. </param>
/// <param name="code"> Language code identifying the target language. </param>
/// <returns> A new <see cref="Text.TargetDictionaryLanguage"/> instance for mocking. </returns>
public static TargetDictionaryLanguage TargetDictionaryLanguage(string name = null, string nativeName = null, LanguageDirectionality directionality = default, string code = null)
{
return new TargetDictionaryLanguage(name, nativeName, directionality, code, serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.TranslatedTextItem"/>. </summary>
/// <param name="detectedLanguage"> The detectedLanguage property is only present in the result object when language auto-detection is requested. </param>
/// <param name="translations">
/// An array of translation results. The size of the array matches the number of target
/// languages specified through the to query parameter.
/// </param>
/// <param name="sourceText">
/// Input text in the default script of the source language. sourceText property is present only when
/// the input is expressed in a script that's not the usual script for the language. For example,
/// if the input were Arabic written in Latin script, then sourceText.text would be the same Arabic text
/// converted into Arab script.
/// </param>
/// <returns> A new <see cref="Text.TranslatedTextItem"/> instance for mocking. </returns>
public static TranslatedTextItem TranslatedTextItem(DetectedLanguage detectedLanguage = null, IEnumerable<TranslationText> translations = null, SourceText sourceText = null)
{
translations ??= new List<TranslationText>();
return new TranslatedTextItem(detectedLanguage, translations?.ToList(), sourceText, serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.DetectedLanguage"/>. </summary>
/// <param name="language"> A string representing the code of the detected language. </param>
/// <param name="confidence">
/// A float value indicating the confidence in the result.
/// The score is between zero and one and a low score indicates a low confidence.
/// </param>
/// <returns> A new <see cref="Text.DetectedLanguage"/> instance for mocking. </returns>
public static DetectedLanguage DetectedLanguage(string language = null, float confidence = default)
{
return new DetectedLanguage(language, confidence, serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.TranslationText"/>. </summary>
/// <param name="targetLanguage"> A string representing the language code of the target language. </param>
/// <param name="text"> A string giving the translated text. </param>
/// <param name="transliteration"> An object giving the translated text in the script specified by the toScript parameter. </param>
/// <param name="alignment"> Alignment information. </param>
/// <param name="sentenceBoundaries"> Sentence boundaries in the input and output texts. </param>
/// <returns> A new <see cref="Text.TranslationText"/> instance for mocking. </returns>
public static TranslationText TranslationText(string targetLanguage = null, string text = null, TransliteratedText transliteration = null, TranslatedTextAlignment alignment = null, SentenceBoundaries sentenceBoundaries = null)
{
return new TranslationText(
targetLanguage,
text,
transliteration,
alignment,
sentenceBoundaries,
serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.TransliteratedText"/>. </summary>
/// <param name="text"> A string which is the result of converting the input string to the output script. </param>
/// <param name="script"> A string specifying the script used in the output. </param>
/// <returns> A new <see cref="Text.TransliteratedText"/> instance for mocking. </returns>
public static TransliteratedText TransliteratedText(string text = null, string script = null)
{
return new TransliteratedText(text, script, serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.TranslatedTextAlignment"/>. </summary>
/// <param name="projections">
/// Maps input text to translated text. The alignment information is only provided when the request
/// parameter includeAlignment is true. Alignment is returned as a string value of the following
/// format: [[SourceTextStartIndex]:[SourceTextEndIndex]–[TgtTextStartIndex]:[TgtTextEndIndex]].
/// The colon separates start and end index, the dash separates the languages, and space separates the words.
/// One word may align with zero, one, or multiple words in the other language, and the aligned words may
/// be non-contiguous. When no alignment information is available, the alignment element will be empty.
/// </param>
/// <returns> A new <see cref="Text.TranslatedTextAlignment"/> instance for mocking. </returns>
public static TranslatedTextAlignment TranslatedTextAlignment(string projections = null)
{
return new TranslatedTextAlignment(projections, serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.SentenceBoundaries"/>. </summary>
/// <param name="sourceSentencesLengths">
/// An integer array representing the lengths of the sentences in the input text.
/// The length of the array is the number of sentences, and the values are the length of each sentence.
/// </param>
/// <param name="translatedSentencesLengths">
/// An integer array representing the lengths of the sentences in the translated text.
/// The length of the array is the number of sentences, and the values are the length of each sentence.
/// </param>
/// <returns> A new <see cref="Text.SentenceBoundaries"/> instance for mocking. </returns>
public static SentenceBoundaries SentenceBoundaries(IEnumerable<int> sourceSentencesLengths = null, IEnumerable<int> translatedSentencesLengths = null)
{
sourceSentencesLengths ??= new List<int>();
translatedSentencesLengths ??= new List<int>();
return new SentenceBoundaries(sourceSentencesLengths?.ToList(), translatedSentencesLengths?.ToList(), serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.SourceText"/>. </summary>
/// <param name="text"> Input text in the default script of the source language. </param>
/// <returns> A new <see cref="Text.SourceText"/> instance for mocking. </returns>
public static SourceText SourceText(string text = null)
{
return new SourceText(text, serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.BreakSentenceItem"/>. </summary>
/// <param name="detectedLanguage"> The detectedLanguage property is only present in the result object when language auto-detection is requested. </param>
/// <param name="sentencesLengths">
/// An integer array representing the lengths of the sentences in the input text.
/// The length of the array is the number of sentences, and the values are the length of each sentence.
/// </param>
/// <returns> A new <see cref="Text.BreakSentenceItem"/> instance for mocking. </returns>
public static BreakSentenceItem BreakSentenceItem(DetectedLanguage detectedLanguage = null, IEnumerable<int> sentencesLengths = null)
{
sentencesLengths ??= new List<int>();
return new BreakSentenceItem(detectedLanguage, sentencesLengths?.ToList(), serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.DictionaryLookupItem"/>. </summary>
/// <param name="normalizedSource">
/// A string giving the normalized form of the source term.
/// For example, if the request is "JOHN", the normalized form will be "john".
/// The content of this field becomes the input to lookup examples.
/// </param>
/// <param name="displaySource">
/// A string giving the source term in a form best suited for end-user display.
/// For example, if the input is "JOHN", the display form will reflect the usual
/// spelling of the name: "John".
/// </param>
/// <param name="translations"> A list of translations for the source term. </param>
/// <returns> A new <see cref="Text.DictionaryLookupItem"/> instance for mocking. </returns>
public static DictionaryLookupItem DictionaryLookupItem(string normalizedSource = null, string displaySource = null, IEnumerable<DictionaryTranslation> translations = null)
{
translations ??= new List<DictionaryTranslation>();
return new DictionaryLookupItem(normalizedSource, displaySource, translations?.ToList(), serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.DictionaryTranslation"/>. </summary>
/// <param name="normalizedTarget">
/// A string giving the normalized form of this term in the target language.
/// This value should be used as input to lookup examples.
/// </param>
/// <param name="displayTarget">
/// A string giving the term in the target language and in a form best suited
/// for end-user display. Generally, this will only differ from the normalizedTarget
/// in terms of capitalization. For example, a proper noun like "Juan" will have
/// normalizedTarget = "juan" and displayTarget = "Juan".
/// </param>
/// <param name="posTag"> A string associating this term with a part-of-speech tag. </param>
/// <param name="confidence">
/// A value between 0.0 and 1.0 which represents the "confidence"
/// (or perhaps more accurately, "probability in the training data") of that translation pair.
/// The sum of confidence scores for one source word may or may not sum to 1.0.
/// </param>
/// <param name="prefixWord">
/// A string giving the word to display as a prefix of the translation. Currently,
/// this is the gendered determiner of nouns, in languages that have gendered determiners.
/// For example, the prefix of the Spanish word "mosca" is "la", since "mosca" is a feminine noun in Spanish.
/// This is only dependent on the translation, and not on the source.
/// If there is no prefix, it will be the empty string.
/// </param>
/// <param name="backTranslations">
/// A list of "back translations" of the target. For example, source words that the target can translate to.
/// The list is guaranteed to contain the source word that was requested (e.g., if the source word being
/// looked up is "fly", then it is guaranteed that "fly" will be in the backTranslations list).
/// However, it is not guaranteed to be in the first position, and often will not be.
/// </param>
/// <returns> A new <see cref="Text.DictionaryTranslation"/> instance for mocking. </returns>
public static DictionaryTranslation DictionaryTranslation(string normalizedTarget = null, string displayTarget = null, string posTag = null, float confidence = default, string prefixWord = null, IEnumerable<BackTranslation> backTranslations = null)
{
backTranslations ??= new List<BackTranslation>();
return new DictionaryTranslation(
normalizedTarget,
displayTarget,
posTag,
confidence,
prefixWord,
backTranslations?.ToList(),
serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.BackTranslation"/>. </summary>
/// <param name="normalizedText">
/// A string giving the normalized form of the source term that is a back-translation of the target.
/// This value should be used as input to lookup examples.
/// </param>
/// <param name="displayText">
/// A string giving the source term that is a back-translation of the target in a form best
/// suited for end-user display.
/// </param>
/// <param name="examplesCount">
/// An integer representing the number of examples that are available for this translation pair.
/// Actual examples must be retrieved with a separate call to lookup examples. The number is mostly
/// intended to facilitate display in a UX. For example, a user interface may add a hyperlink
/// to the back-translation if the number of examples is greater than zero and show the back-translation
/// as plain text if there are no examples. Note that the actual number of examples returned
/// by a call to lookup examples may be less than numExamples, because additional filtering may be
/// applied on the fly to remove "bad" examples.
/// </param>
/// <param name="frequencyCount">
/// An integer representing the frequency of this translation pair in the data. The main purpose of this
/// field is to provide a user interface with a means to sort back-translations so the most frequent terms are first.
/// </param>
/// <returns> A new <see cref="Text.BackTranslation"/> instance for mocking. </returns>
public static BackTranslation BackTranslation(string normalizedText = null, string displayText = null, int examplesCount = default, int frequencyCount = default)
{
return new BackTranslation(normalizedText, displayText, examplesCount, frequencyCount, serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.DictionaryExampleItem"/>. </summary>
/// <param name="normalizedSource">
/// A string giving the normalized form of the source term. Generally, this should be identical
/// to the value of the Text field at the matching list index in the body of the request.
/// </param>
/// <param name="normalizedTarget">
/// A string giving the normalized form of the target term. Generally, this should be identical
/// to the value of the Translation field at the matching list index in the body of the request.
/// </param>
/// <param name="examples"> A list of examples for the (source term, target term) pair. </param>
/// <returns> A new <see cref="Text.DictionaryExampleItem"/> instance for mocking. </returns>
public static DictionaryExampleItem DictionaryExampleItem(string normalizedSource = null, string normalizedTarget = null, IEnumerable<DictionaryExample> examples = null)
{
examples ??= new List<DictionaryExample>();
return new DictionaryExampleItem(normalizedSource, normalizedTarget, examples?.ToList(), serializedAdditionalRawData: null);
}
/// <summary> Initializes a new instance of <see cref="Text.DictionaryExample"/>. </summary>
/// <param name="sourcePrefix">
/// The string to concatenate before the value of sourceTerm to form a complete example.
/// Do not add a space character, since it is already there when it should be.
/// This value may be an empty string.
/// </param>
/// <param name="sourceTerm">
/// A string equal to the actual term looked up. The string is added with sourcePrefix
/// and sourceSuffix to form the complete example. Its value is separated so it can be
/// marked in a user interface, e.g., by bolding it.
/// </param>
/// <param name="sourceSuffix">
/// The string to concatenate after the value of sourceTerm to form a complete example.
/// Do not add a space character, since it is already there when it should be.
/// This value may be an empty string.
/// </param>
/// <param name="targetPrefix"> A string similar to sourcePrefix but for the target. </param>
/// <param name="targetTerm"> A string similar to sourceTerm but for the target. </param>
/// <param name="targetSuffix"> A string similar to sourceSuffix but for the target. </param>
/// <returns> A new <see cref="Text.DictionaryExample"/> instance for mocking. </returns>
public static DictionaryExample DictionaryExample(string sourcePrefix = null, string sourceTerm = null, string sourceSuffix = null, string targetPrefix = null, string targetTerm = null, string targetSuffix = null)
{
return new DictionaryExample(
sourcePrefix,
sourceTerm,
sourceSuffix,
targetPrefix,
targetTerm,
targetSuffix,
serializedAdditionalRawData: null);
}
}
}