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: str, authenticator: ibm_cloud_sdk_core.authenticators.authenticator.Authenticator = None, service_name: str = 'language_translator')[source]¶ Bases:
ibm_cloud_sdk_core.base_service.BaseService
The Language Translator V3 service.
-
DEFAULT_SERVICE_URL
= 'https://gateway.watsonplatform.net/language-translator/api'¶
-
DEFAULT_SERVICE_NAME
= 'language_translator'¶
-
translate
(text: List[str], *, model_id: str = None, source: str = None, target: str = None, **kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[source]¶ Translate.
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.
- Parameters
text (List[str]) – Input text in UTF-8 encoding. Multiple entries will result in multiple translations in the response.
model_id (str) – (optional) 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.
source (str) – (optional) Language code that specifies the language of the source document.
target (str) – (optional) Language code that specifies the target language for translation. Required if model ID is not specified.
headers (dict) – A dict containing the request headers
- Returns
A DetailedResponse containing the result, headers and HTTP status code.
- Return type
DetailedResponse
-
list_identifiable_languages
(**kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[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
-
identify
(text: str, **kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[source]¶ Identify language.
Identifies the language of the input text.
-
list_models
(*, source: str = None, target: str = None, default: bool = None, **kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[source]¶ List models.
Lists available translation models.
- Parameters
source (str) – (optional) Specify a language code to filter results by source language.
target (str) – (optional) Specify a language code to filter results by target language.
default (bool) – (optional) If the default parameter isn’t specified, the service 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.
headers (dict) – A dict containing the request headers
- Returns
A DetailedResponse containing the result, headers and HTTP status code.
- Return type
DetailedResponse
-
create_model
(base_model_id: str, *, forced_glossary: BinaryIO = None, parallel_corpus: BinaryIO = None, name: str = None, **kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[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.
forced_glossary (TextIO) – (optional) 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.
parallel_corpus (TextIO) – (optional) 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.
name (str) – (optional) 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.
headers (dict) – A dict containing the request headers
- Returns
A DetailedResponse containing the result, headers and HTTP status code.
- Return type
DetailedResponse
-
delete_model
(model_id: str, **kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[source]¶ Delete model.
Deletes a custom translation model.
-
get_model
(model_id: str, **kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[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) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[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: BinaryIO, *, filename: str = None, file_content_type: str = None, model_id: str = None, source: str = None, target: str = None, document_id: str = None, **kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[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 (TextIO) – The contents of the source file to translate. [Supported file types](https://cloud.ibm.com/docs/language-translator?topic=language-translator-document-translator-tutorial#supported-file-formats) Maximum file size: 20 MB.
filename (str) – (optional) The filename for file.
file_content_type (str) – (optional) The content type of file.
model_id (str) – (optional) 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.
source (str) – (optional) Language code that specifies the language of the source document.
target (str) – (optional) Language code that specifies the target language for translation. Required if model ID is not specified.
document_id (str) – (optional) To use a previously submitted document as the source for a new translation, enter the document_id of the document.
headers (dict) – A dict containing the request headers
- Returns
A DetailedResponse containing the result, headers and HTTP status code.
- Return type
DetailedResponse
-
get_document_status
(document_id: str, **kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[source]¶ Get document status.
Gets the translation status of a document.
-
delete_document
(document_id: str, **kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[source]¶ Delete document.
Deletes a document.
-
get_translated_document
(document_id: str, *, accept: str = None, **kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[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.
accept (str) – (optional) 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’.
headers (dict) – A dict containing the request headers
- Returns
A DetailedResponse containing the result, headers and HTTP status code.
- Return type
DetailedResponse
-
-
class
TranslateDocumentEnums
[source]¶ Bases:
object
-
class
FileContentType
[source]¶ Bases:
enum.Enum
The content type of file.
-
APPLICATION_POWERPOINT
= 'application/powerpoint'¶
-
APPLICATION_MSPOWERPOINT
= 'application/mspowerpoint'¶
-
APPLICATION_X_RTF
= 'application/x-rtf'¶
-
APPLICATION_JSON
= 'application/json'¶
-
APPLICATION_XML
= 'application/xml'¶
-
APPLICATION_VND_MS_EXCEL
= 'application/vnd.ms-excel'¶
-
APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_SPREADSHEETML_SHEET
= 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'¶
-
APPLICATION_VND_MS_POWERPOINT
= 'application/vnd.ms-powerpoint'¶
-
APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_PRESENTATION
= 'application/vnd.openxmlformats-officedocument.presentationml.presentation'¶
-
APPLICATION_MSWORD
= 'application/msword'¶
-
APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_WORDPROCESSINGML_DOCUMENT
= 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'¶
-
APPLICATION_VND_OASIS_OPENDOCUMENT_SPREADSHEET
= 'application/vnd.oasis.opendocument.spreadsheet'¶
-
APPLICATION_VND_OASIS_OPENDOCUMENT_PRESENTATION
= 'application/vnd.oasis.opendocument.presentation'¶
-
APPLICATION_VND_OASIS_OPENDOCUMENT_TEXT
= 'application/vnd.oasis.opendocument.text'¶
-
APPLICATION_PDF
= 'application/pdf'¶
-
APPLICATION_RTF
= 'application/rtf'¶
-
TEXT_HTML
= 'text/html'¶
-
TEXT_JSON
= 'text/json'¶
-
TEXT_PLAIN
= 'text/plain'¶
-
TEXT_RICHTEXT
= 'text/richtext'¶
-
TEXT_RTF
= 'text/rtf'¶
-
TEXT_XML
= 'text/xml'¶
-
-
class
-
class
GetTranslatedDocumentEnums
[source]¶ Bases:
object
-
class
Accept
[source]¶ Bases:
enum.Enum
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’.
-
APPLICATION_POWERPOINT
= 'application/powerpoint'¶
-
APPLICATION_MSPOWERPOINT
= 'application/mspowerpoint'¶
-
APPLICATION_X_RTF
= 'application/x-rtf'¶
-
APPLICATION_JSON
= 'application/json'¶
-
APPLICATION_XML
= 'application/xml'¶
-
APPLICATION_VND_MS_EXCEL
= 'application/vnd.ms-excel'¶
-
APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_SPREADSHEETML_SHEET
= 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'¶
-
APPLICATION_VND_MS_POWERPOINT
= 'application/vnd.ms-powerpoint'¶
-
APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_PRESENTATION
= 'application/vnd.openxmlformats-officedocument.presentationml.presentation'¶
-
APPLICATION_MSWORD
= 'application/msword'¶
-
APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_WORDPROCESSINGML_DOCUMENT
= 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'¶
-
APPLICATION_VND_OASIS_OPENDOCUMENT_SPREADSHEET
= 'application/vnd.oasis.opendocument.spreadsheet'¶
-
APPLICATION_VND_OASIS_OPENDOCUMENT_PRESENTATION
= 'application/vnd.oasis.opendocument.presentation'¶
-
APPLICATION_VND_OASIS_OPENDOCUMENT_TEXT
= 'application/vnd.oasis.opendocument.text'¶
-
APPLICATION_PDF
= 'application/pdf'¶
-
APPLICATION_RTF
= 'application/rtf'¶
-
TEXT_HTML
= 'text/html'¶
-
TEXT_JSON
= 'text/json'¶
-
TEXT_PLAIN
= 'text/plain'¶
-
TEXT_RICHTEXT
= 'text/richtext'¶
-
TEXT_RTF
= 'text/rtf'¶
-
TEXT_XML
= 'text/xml'¶
-
-
class
-
class
DeleteModelResult
(status: str)[source]¶ Bases:
object
DeleteModelResult.
- Attr str status
“OK” indicates that the model was successfully deleted.
-
classmethod
from_dict
(_dict: Dict) → ibm_watson.language_translator_v3.DeleteModelResult[source]¶ Initialize a DeleteModelResult object from a json dictionary.
-
class
DocumentList
(documents: List[DocumentStatus])[source]¶ Bases:
object
DocumentList.
- Attr List[DocumentStatus] documents
An array of all previously submitted documents.
-
classmethod
from_dict
(_dict: Dict) → ibm_watson.language_translator_v3.DocumentList[source]¶ Initialize a DocumentList object from a json dictionary.
-
class
DocumentStatus
(document_id: str, filename: str, status: str, model_id: str, source: str, target: str, created: datetime.datetime, *, base_model_id: str = None, detected_language_confidence: float = None, completed: datetime.datetime = None, word_count: int = None, character_count: int = 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 float detected_language_confidence
(optional) 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.
- 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) An estimate of the number of words in the source document. Returned only if status is available.
- Attr int character_count
(optional) The number of characters in the source document, present only if status=available.
-
classmethod
from_dict
(_dict: Dict) → ibm_watson.language_translator_v3.DocumentStatus[source]¶ Initialize a DocumentStatus object from a json dictionary.
-
class
IdentifiableLanguage
(language: str, name: str)[source]¶ Bases:
object
IdentifiableLanguage.
- Attr str language
The language code for an identifiable language.
- Attr str name
The name of the identifiable language.
-
classmethod
from_dict
(_dict: Dict) → ibm_watson.language_translator_v3.IdentifiableLanguage[source]¶ Initialize a IdentifiableLanguage object from a json dictionary.
-
class
IdentifiableLanguages
(languages: List[IdentifiableLanguage])[source]¶ Bases:
object
IdentifiableLanguages.
- Attr List[IdentifiableLanguage] languages
A list of all languages that the service can identify.
-
classmethod
from_dict
(_dict: Dict) → ibm_watson.language_translator_v3.IdentifiableLanguages[source]¶ Initialize a IdentifiableLanguages object from a json dictionary.
-
class
IdentifiedLanguage
(language: str, confidence: float)[source]¶ Bases:
object
IdentifiedLanguage.
- Attr str language
The language code for an identified language.
- Attr float confidence
The confidence score for the identified language.
-
classmethod
from_dict
(_dict: Dict) → ibm_watson.language_translator_v3.IdentifiedLanguage[source]¶ Initialize a IdentifiedLanguage object from a json dictionary.
-
class
IdentifiedLanguages
(languages: List[IdentifiedLanguage])[source]¶ Bases:
object
IdentifiedLanguages.
- Attr List[IdentifiedLanguage] languages
A ranking of identified languages with confidence scores.
-
classmethod
from_dict
(_dict: Dict) → ibm_watson.language_translator_v3.IdentifiedLanguages[source]¶ Initialize a IdentifiedLanguages object from a json dictionary.
-
class
Translation
(translation: str)[source]¶ Bases:
object
Translation.
- Attr str translation
Translation output in UTF-8.
-
classmethod
from_dict
(_dict: Dict) → ibm_watson.language_translator_v3.Translation[source]¶ Initialize a Translation object from a json dictionary.
-
class
TranslationModel
(model_id: str, *, name: str = None, source: str = None, target: str = None, base_model_id: str = None, domain: str = None, customizable: bool = None, default_model: bool = None, owner: str = None, status: str = 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.
-
classmethod
from_dict
(_dict: Dict) → ibm_watson.language_translator_v3.TranslationModel[source]¶ Initialize a TranslationModel object from a json dictionary.
-
class
TranslationModels
(models: List[TranslationModel])[source]¶ Bases:
object
The response type for listing existing translation models.
- Attr List[TranslationModel] models
An array of available models.
-
classmethod
from_dict
(_dict: Dict) → ibm_watson.language_translator_v3.TranslationModels[source]¶ Initialize a TranslationModels object from a json dictionary.
-
class
TranslationResult
(word_count: int, character_count: int, translations: List[Translation], *, detected_language: str = None, detected_language_confidence: float = None)[source]¶ Bases:
object
TranslationResult.
- Attr int word_count
An estimate of the number of words in the input text.
- Attr int character_count
Number of characters in the input text.
- Attr str detected_language
(optional) The language code of the source text if the source language was automatically detected.
- Attr float detected_language_confidence
(optional) 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.
- Attr List[Translation] translations
List of translation output in UTF-8, corresponding to the input text entries.
-
classmethod
from_dict
(_dict: Dict) → ibm_watson.language_translator_v3.TranslationResult[source]¶ Initialize a TranslationResult object from a json dictionary.