ibm_watson.language_translator_v3 module¶
IBM Watson™ Language Translator translates text from one language to another. The service offers multiple IBM provided translation models that you can customize based on your unique terminology and language. Use Language Translator to take news from across the globe and present it in your language, communicate with your customers in their own language, and more.
-
class
LanguageTranslatorV3
(version, url='https://gateway.watsonplatform.net/language-translator/api', username=None, password=None, iam_apikey=None, iam_access_token=None, iam_url=None, iam_client_id=None, iam_client_secret=None, icp4d_access_token=None, icp4d_url=None, authentication_type=None)[source]¶ Bases:
ibm_cloud_sdk_core.base_service.BaseService
The Language Translator V3 service.
-
default_url
= 'https://gateway.watsonplatform.net/language-translator/api'¶
-
translate
(text, model_id=None, source=None, target=None, **kwargs)[source]¶ Translate.
Translates the input text from the source language to the target language.
in multiple translations in the response. :param str model_id: A globally unique string that identifies the underlying model that is used for translation. :param str source: Translation source language code. :param str target: Translation target language code. :param dict headers: A dict containing the request headers :return: A DetailedResponse containing the result, headers and HTTP status code. :rtype: DetailedResponse
-
list_identifiable_languages
(**kwargs)[source]¶ List identifiable languages.
Lists the languages that the service can identify. Returns the language code (for example, en for English or es for Spanish) and name of each language.
- Parameters
headers (dict) – A dict containing the request headers
- Returns
A DetailedResponse containing the result, headers and HTTP status code.
- Return type
DetailedResponse
-
list_models
(source=None, target=None, default_models=None, **kwargs)[source]¶ List models.
Lists available translation models.
- Parameters
will return all models (default and non-default) for each language pair. To return only default models, set this to true. To return only non-default models, set this to false. There is exactly one default model per language pair, the IBM provided base model. :param dict headers: A dict containing the request headers :return: A DetailedResponse containing the result, headers and HTTP status code. :rtype: DetailedResponse
-
create_model
(base_model_id, forced_glossary=None, parallel_corpus=None, name=None, **kwargs)[source]¶ Create model.
Uploads Translation Memory eXchange (TMX) files to customize a translation model. You can either customize a model with a forced glossary or with a corpus that contains parallel sentences. To create a model that is customized with a parallel corpus <b>and</b> a forced glossary, proceed in two steps: customize with a parallel corpus first and then customize the resulting model with a glossary. Depending on the type of customization and the size of the uploaded corpora, training can range from minutes for a glossary to several hours for a large parallel corpus. You can upload a single forced glossary file and this file must be less than <b>10 MB</b>. You can upload multiple parallel corpora tmx files. The cumulative file size of all uploaded files is limited to <b>250 MB</b>. To successfully train with a parallel corpus you must have at least <b>5,000 parallel sentences</b> in your corpus. You can have a <b>maximum of 10 custom models per language pair</b>.
- Parameters
base_model_id (str) – The model ID of the model to use as the base for
customization. To see available models, use the List models method. Usually all IBM provided models are customizable. In addition, all your models that have been created via parallel corpus customization, can be further customized with a forced glossary. :param file forced_glossary: A TMX file with your customizations. The customizations in the file completely overwrite the domain translaton data, including high frequency or high confidence phrase translations. You can upload only one glossary with a file size less than 10 MB per call. A forced glossary should contain single words or short phrases. :param file parallel_corpus: A TMX file with parallel sentences for source and target language. You can upload multiple parallel_corpus files in one request. All uploaded parallel_corpus files combined, your parallel corpus must contain at least 5,000 parallel sentences to train successfully. :param str name: An optional model name that you can use to identify the model. Valid characters are letters, numbers, dashes, underscores, spaces and apostrophes. The maximum length is 32 characters. :param dict headers: A dict containing the request headers :return: A DetailedResponse containing the result, headers and HTTP status code. :rtype: DetailedResponse
-
get_model
(model_id, **kwargs)[source]¶ Get model details.
Gets information about a translation model, including training status for custom models. Use this API call to poll the status of your customization request. A successfully completed training will have a status of available.
-
list_documents
(**kwargs)[source]¶ List documents.
Lists documents that have been submitted for translation.
- Parameters
headers (dict) – A dict containing the request headers
- Returns
A DetailedResponse containing the result, headers and HTTP status code.
- Return type
DetailedResponse
-
translate_document
(file, filename=None, file_content_type=None, model_id=None, source=None, target=None, document_id=None, **kwargs)[source]¶ Translate document.
Submit a document for translation. You can submit the document contents in the file parameter, or you can reference a previously submitted document by document ID.
- Parameters
file (file) – 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) Maximum file size: 20 MB. :param str filename: The filename for file. :param str file_content_type: The content type of file. :param str model_id: The model to use for translation. model_id or both source and target are required. :param str source: Language code that specifies the language of the source document. :param str target: Language code that specifies the target language for translation. :param str document_id: To use a previously submitted document as the source for a new translation, enter the document_id of the document. :param dict headers: A dict containing the request headers :return: A DetailedResponse containing the result, headers and HTTP status code. :rtype: DetailedResponse
-
get_document_status
(document_id, **kwargs)[source]¶ Get document status.
Gets the translation status of a document.
-
get_translated_document
(document_id, accept=None, **kwargs)[source]¶ Get translated document.
Gets the translated document associated with the given document ID.
- Parameters
document_id (str) – The document ID of the document that was submitted for
translation. :param str accept: The type of the response: application/powerpoint, application/mspowerpoint, application/x-rtf, application/json, application/xml, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-powerpoint, application/vnd.openxmlformats-officedocument.presentationml.presentation, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.oasis.opendocument.spreadsheet, application/vnd.oasis.opendocument.presentation, application/vnd.oasis.opendocument.text, application/pdf, application/rtf, text/html, text/json, text/plain, text/richtext, text/rtf, or text/xml. A character encoding can be specified by including a charset parameter. For example, ‘text/html;charset=utf-8’. :param dict headers: A dict containing the request headers :return: A DetailedResponse containing the result, headers and HTTP status code. :rtype: DetailedResponse
-
-
class
DeleteModelResult
(status)[source]¶ Bases:
object
DeleteModelResult.
- Attr str status
“OK” indicates that the model was successfully deleted.
-
class
DocumentList
(documents)[source]¶ Bases:
object
DocumentList.
- Attr list[DocumentStatus] documents
An array of all previously submitted documents.
-
class
DocumentStatus
(document_id, filename, status, model_id, source, target, created, base_model_id=None, completed=None, word_count=None, character_count=None)[source]¶ Bases:
object
Document information, including translation status.
- Attr str document_id
System generated ID identifying a document being translated
using one specific translation model. :attr str filename: filename from the submission (if it was missing in the multipart-form, ‘noname.<ext matching content type>’ is used. :attr str status: The status of the translation job associated with a submitted document. :attr str model_id: A globally unique string that identifies the underlying model that is used for translation. :attr str base_model_id: (optional) Model ID of the base model that was used to customize the model. If the model is not a custom model, this will be absent or an empty string. :attr str source: Translation source language code. :attr str target: Translation target language code. :attr datetime created: The time when the document was submitted. :attr datetime completed: (optional) The time when the translation completed. :attr int word_count: (optional) The number of words in the source document, present only if status=available. :attr int character_count: (optional) The number of characters in the source document, present only if status=available.
-
class
IdentifiableLanguage
(language, name)[source]¶ Bases:
object
IdentifiableLanguage.
- Attr str language
The language code for an identifiable language.
- Attr str name
The name of the identifiable language.
-
class
IdentifiableLanguages
(languages)[source]¶ Bases:
object
IdentifiableLanguages.
- Attr list[IdentifiableLanguage] languages
A list of all languages that the service
can identify.
-
class
IdentifiedLanguage
(language, confidence)[source]¶ Bases:
object
IdentifiedLanguage.
- Attr str language
The language code for an identified language.
- Attr float confidence
The confidence score for the identified language.
-
class
IdentifiedLanguages
(languages)[source]¶ Bases:
object
IdentifiedLanguages.
- Attr list[IdentifiedLanguage] languages
A ranking of identified languages with
confidence scores.
-
class
Translation
(translation_output)[source]¶ Bases:
object
Translation.
- Attr str translation_output
Translation output in UTF-8.
-
class
TranslationModel
(model_id, name=None, source=None, target=None, base_model_id=None, domain=None, customizable=None, default_model=None, owner=None, status=None)[source]¶ Bases:
object
Response payload for models.
- Attr str model_id
A globally unique string that identifies the underlying model that
is used for translation. :attr str name: (optional) Optional name that can be specified when the model is created. :attr str source: (optional) Translation source language code. :attr str target: (optional) Translation target language code. :attr str base_model_id: (optional) Model ID of the base model that was used to customize the model. If the model is not a custom model, this will be an empty string. :attr str domain: (optional) The domain of the translation model. :attr bool customizable: (optional) Whether this model can be used as a base for customization. Customized models are not further customizable, and some base models are not customizable. :attr bool default_model: (optional) Whether or not the model is a default model. A default model is the model for a given language pair that will be used when that language pair is specified in the source and target parameters. :attr str owner: (optional) Either an empty string, indicating the model is not a custom model, or the ID of the service instance that created the model. :attr str status: (optional) Availability of a model.
-
class
TranslationModels
(models)[source]¶ Bases:
object
The response type for listing existing translation models.
- Attr list[TranslationModel] models
An array of available models.
-
class
TranslationResult
(word_count, character_count, translations)[source]¶ Bases:
object
TranslationResult.
- Attr int word_count
Number of words in the input text.
- Attr int character_count
Number of characters in the input text.
- Attr list[Translation] translations
List of translation output in UTF-8,
corresponding to the input text entries.