watson_developer_cloud.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)[source]¶ Bases:
watson_developer_cloud.watson_service.WatsonService
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.
Parameters: text (list[str]) – Input text in UTF-8 encoding. Multiple entries will result in multiple translations in the response. :param str model_id: Model ID of the translation model to use. If this is specified, the source and target parameters will be ignored. The method requires either a model ID or both the source and target parameters. :param str source: Language code of the source text language. Use with target as an alternative way to select a translation model. When source and target are set, and a model ID is not set, the system chooses a default model for the language pair (usually the model based on the news domain). :param str target: Language code of the translation target language. Use with source as an alternative way to select a translation model. :param dict headers: A dict containing the request headers :return: A DetailedResponse containing the result, headers and HTTP status code. :rtype: DetailedResponse
-
identify
(text, **kwargs)[source]¶ Identify language.
Identifies the language of the input text.
Parameters: Returns: A DetailedResponse containing the result, headers and HTTP status code.
Return type:
-
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
-
create_model
(base_model_id, name=None, forced_glossary=None, parallel_corpus=None, forced_glossary_filename=None, parallel_corpus_filename=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>maxium 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 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 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 forced_glossary_filename: The filename for forced_glossary. :param str parallel_corpus_filename: The filename for parallel_corpus. :param dict headers: A dict containing the request headers :return: A DetailedResponse containing the result, headers and HTTP status code. :rtype: DetailedResponse
-
delete_model
(model_id, **kwargs)[source]¶ Delete model.
Deletes a custom translation model.
Parameters: Returns: A DetailedResponse containing the result, headers and HTTP status code.
Return type:
-
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.
Parameters: Returns: A DetailedResponse containing the result, headers and HTTP status code.
Return type:
-
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
-
-
class
DeleteModelResult
(status)[source]¶ Bases:
object
DeleteModelResult.
Attr str status: “OK” indicates that the model was successfully deleted.
-
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.