Skip to content

Commit

Permalink
feat(LanguageTranslator): add support for language detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mamoonraja committed Apr 21, 2020
1 parent cd3a592 commit ccca1da
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
27 changes: 17 additions & 10 deletions Scripts/Services/LanguageTranslator/V3/LanguageTranslatorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,19 @@ public LanguageTranslatorService(string versionDate, Authenticator authenticator
/// <summary>
/// Translate.
///
/// Translates the input text from the source language to the target language.
/// Translates the input text from the source language to the target language. A target language or translation
/// model ID is required. The service attempts to detect the language of the source text if it is not specified.
/// </summary>
/// <param name="callback">The callback function that is invoked when the operation completes.</param>
/// <param name="text">Input text in UTF-8 encoding. Multiple entries will result in multiple translations in
/// the response.</param>
/// <param name="modelId">A globally unique string that identifies the underlying model that is used for
/// translation. (optional)</param>
/// <param name="source">Translation source language code. (optional)</param>
/// <param name="target">Translation target language code. (optional)</param>
/// <param name="modelId">The model to use for translation. For example, `en-de` selects the IBM provided base
/// model for English to German translation. A model ID overrides the source and target parameters and is
/// required if you use a custom model. If no model ID is specified, you must specify a target language.
/// (optional)</param>
/// <param name="source">Language code that specifies the language of the source document. (optional)</param>
/// <param name="target">Language code that specifies the target language for translation. Required if model ID
/// is not specified. (optional)</param>
/// <returns><see cref="TranslationResult" />TranslationResult</returns>
public bool Translate(Callback<TranslationResult> callback, List<string> text, string modelId = null, string source = null, string target = null)
{
Expand Down Expand Up @@ -716,15 +720,18 @@ private void OnListDocumentsResponse(RESTConnector.Request req, RESTConnector.Re
/// <param name="file">The contents of the source file to translate.
///
/// [Supported file
/// types](https://cloud.ibm.com/docs/services/language-translator?topic=language-translator-document-translator-tutorial#supported-file-formats)
/// types](https://cloud.ibm.com/docs/language-translator?topic=language-translator-document-translator-tutorial#supported-file-formats)
///
/// Maximum file size: **20 MB**.</param>
/// <param name="filename">The filename for file.</param>
/// <param name="fileContentType">The content type of file. (optional)</param>
/// <param name="modelId">The model to use for translation. `model_id` or both `source` and `target` are
/// required. (optional)</param>
/// <param name="modelId">The model to use for translation. For example, `en-de` selects the IBM provided base
/// model for English to German translation. A model ID overrides the source and target parameters and is
/// required if you use a custom model. If no model ID is specified, you must specify a target language.
/// (optional)</param>
/// <param name="source">Language code that specifies the language of the source document. (optional)</param>
/// <param name="target">Language code that specifies the target language for translation. (optional)</param>
/// <param name="target">Language code that specifies the target language for translation. Required if model ID
/// is not specified. (optional)</param>
/// <param name="documentId">To use a previously submitted document as the source for a new translation, enter
/// the `document_id` of the document. (optional)</param>
/// <returns><see cref="DocumentStatus" />DocumentStatus</returns>
Expand Down Expand Up @@ -1015,4 +1022,4 @@ private void OnGetTranslatedDocumentResponse(RESTConnector.Request req, RESTConn
((RequestObject<byte[]>)req).Callback(response, resp.Error);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public class StatusValue
[JsonProperty("source", NullValueHandling = NullValueHandling.Ignore)]
public string Source { get; set; }
/// <summary>
/// A score between 0 and 1 indicating the confidence of source language detection. A higher value indicates
/// greater confidence. This is returned only when the service automatically detects the source language.
/// </summary>
[JsonProperty("detected_language_confidence", NullValueHandling = NullValueHandling.Ignore)]
public double? DetectedLanguageConfidence { get; set; }
/// <summary>
/// Translation target language code.
/// </summary>
[JsonProperty("target", NullValueHandling = NullValueHandling.Ignore)]
Expand Down
11 changes: 11 additions & 0 deletions Scripts/Services/LanguageTranslator/V3/Model/TranslationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ public class TranslationResult
[JsonProperty("character_count", NullValueHandling = NullValueHandling.Ignore)]
public long? CharacterCount { get; set; }
/// <summary>
/// The language code of the source text if the source language was automatically detected.
/// </summary>
[JsonProperty("detected_language", NullValueHandling = NullValueHandling.Ignore)]
public string DetectedLanguage { get; set; }
/// <summary>
/// A score between 0 and 1 indicating the confidence of source language detection. A higher value indicates
/// greater confidence. This is returned only when the service automatically detects the source language.
/// </summary>
[JsonProperty("detected_language_confidence", NullValueHandling = NullValueHandling.Ignore)]
public double? DetectedLanguageConfidence { get; set; }
/// <summary>
/// List of translation output in UTF-8, corresponding to the input text entries.
/// </summary>
[JsonProperty("translations", NullValueHandling = NullValueHandling.Ignore)]
Expand Down

0 comments on commit ccca1da

Please sign in to comment.