Class LanguageTranslator

java.lang.Object
com.ibm.cloud.sdk.core.service.BaseService
com.ibm.watson.language_translator.v3.LanguageTranslator

public class LanguageTranslator
extends com.ibm.cloud.sdk.core.service.BaseService
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.
Version:
v3
See Also:
Language Translator
  • Field Details

  • Constructor Details

    • LanguageTranslator

      public LanguageTranslator​(String version)
      Constructs an instance of the `LanguageTranslator` client. The default service name is used to configure the client instance.
      Parameters:
      version - Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is `2018-05-01`.
    • LanguageTranslator

      public LanguageTranslator​(String version, com.ibm.cloud.sdk.core.security.Authenticator authenticator)
      Constructs an instance of the `LanguageTranslator` client. The default service name and specified authenticator are used to configure the client instance.
      Parameters:
      version - Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is `2018-05-01`.
      authenticator - the Authenticator instance to be configured for this client
    • LanguageTranslator

      public LanguageTranslator​(String version, String serviceName)
      Constructs an instance of the `LanguageTranslator` client. The specified service name is used to configure the client instance.
      Parameters:
      version - Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is `2018-05-01`.
      serviceName - the service name to be used when configuring the client instance
    • LanguageTranslator

      public LanguageTranslator​(String version, String serviceName, com.ibm.cloud.sdk.core.security.Authenticator authenticator)
      Constructs an instance of the `LanguageTranslator` client. The specified service name and authenticator are used to configure the client instance.
      Parameters:
      version - Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is `2018-05-01`.
      serviceName - the service name to be used when configuring the client instance
      authenticator - the Authenticator instance to be configured for this client
  • Method Details

    • getVersion

      public String getVersion()
      Gets the version.

      Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format. The current version is `2018-05-01`.

      Returns:
      the version
    • setVersion

      public void setVersion​(String version)
      Sets the version.
      Parameters:
      version - the new version
    • listLanguages

      public com.ibm.cloud.sdk.core.http.ServiceCall<Languages> listLanguages​(ListLanguagesOptions listLanguagesOptions)
      List supported languages.

      Lists all supported languages for translation. The method returns an array of supported languages with information about each language. Languages are listed in alphabetical order by language code (for example, `af`, `ar`). In addition to basic information about each language, the response indicates whether the language is `supported_as_source` for translation and `supported_as_target` for translation. It also lists whether the language is `identifiable`.

      Parameters:
      listLanguagesOptions - the ListLanguagesOptions containing the options for the call
      Returns:
      a ServiceCall with a result of type Languages
    • listLanguages

      public com.ibm.cloud.sdk.core.http.ServiceCall<Languages> listLanguages()
      List supported languages.

      Lists all supported languages for translation. The method returns an array of supported languages with information about each language. Languages are listed in alphabetical order by language code (for example, `af`, `ar`). In addition to basic information about each language, the response indicates whether the language is `supported_as_source` for translation and `supported_as_target` for translation. It also lists whether the language is `identifiable`.

      Returns:
      a ServiceCall with a result of type Languages
    • translate

      public com.ibm.cloud.sdk.core.http.ServiceCall<TranslationResult> translate​(TranslateOptions translateOptions)
      Translate.

      Translates the input text from the source language to the target language. Specify a model ID that indicates the source and target languages, or specify the source and target languages individually. You can omit the source language to have the service attempt to detect the language from the input text. If you omit the source language, the request must contain sufficient input text for the service to identify the source language.

      You can translate a maximum of 50 KB (51,200 bytes) of text with a single request. All input text must be encoded in UTF-8 format.

      Parameters:
      translateOptions - the TranslateOptions containing the options for the call
      Returns:
      a ServiceCall with a result of type TranslationResult
    • listIdentifiableLanguages

      public com.ibm.cloud.sdk.core.http.ServiceCall<IdentifiableLanguages> listIdentifiableLanguages​(ListIdentifiableLanguagesOptions listIdentifiableLanguagesOptions)
      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:
      listIdentifiableLanguagesOptions - the ListIdentifiableLanguagesOptions containing the options for the call
      Returns:
      a ServiceCall with a result of type IdentifiableLanguages
    • listIdentifiableLanguages

      public com.ibm.cloud.sdk.core.http.ServiceCall<IdentifiableLanguages> listIdentifiableLanguages()
      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.

      Returns:
      a ServiceCall with a result of type IdentifiableLanguages
    • identify

      public com.ibm.cloud.sdk.core.http.ServiceCall<IdentifiedLanguages> identify​(IdentifyOptions identifyOptions)
      Identify language.

      Identifies the language of the input text.

      Parameters:
      identifyOptions - the IdentifyOptions containing the options for the call
      Returns:
      a ServiceCall with a result of type IdentifiedLanguages
    • listModels

      public com.ibm.cloud.sdk.core.http.ServiceCall<TranslationModels> listModels​(ListModelsOptions listModelsOptions)
      List models.

      Lists available translation models.

      Parameters:
      listModelsOptions - the ListModelsOptions containing the options for the call
      Returns:
      a ServiceCall with a result of type TranslationModels
    • listModels

      public com.ibm.cloud.sdk.core.http.ServiceCall<TranslationModels> listModels()
      List models.

      Lists available translation models.

      Returns:
      a ServiceCall with a result of type TranslationModels
    • createModel

      public com.ibm.cloud.sdk.core.http.ServiceCall<TranslationModel> createModel​(CreateModelOptions createModelOptions)
      Create model.

      Uploads training files to customize a translation model. You can customize a model with a forced glossary or with a parallel corpus: * Use a *forced glossary* to force certain terms and phrases to be translated in a specific way. You can upload only a single forced glossary file for a model. The size of a forced glossary file for a custom model is limited to 10 MB. * Use a *parallel corpus* when you want your custom model to learn from general translation patterns in parallel sentences in your samples. What your model learns from a parallel corpus can improve translation results for input text that the model has not been trained on. You can upload multiple parallel corpora files with a request. To successfully train with parallel corpora, the corpora files must contain a cumulative total of at least 5000 parallel sentences. The cumulative size of all uploaded corpus files for a custom model is limited to 250 MB.

      Depending on the type of customization and the size of the uploaded files, training time can range from minutes for a glossary to several hours for a large parallel corpus. To create a model that is customized with a parallel corpus and a forced glossary, customize the model with a parallel corpus first and then customize the resulting model with a forced glossary.

      You can create a maximum of 10 custom models per language pair. For more information about customizing a translation model, including the formatting and character restrictions for data files, see [Customizing your model](https://cloud.ibm.com/docs/language-translator?topic=language-translator-customizing).

      #### Supported file formats

      You can provide your training data for customization in the following document formats: * **TMX** (`.tmx`) - Translation Memory eXchange (TMX) is an XML specification for the exchange of translation memories. * **XLIFF** (`.xliff`) - XML Localization Interchange File Format (XLIFF) is an XML specification for the exchange of translation memories. * **CSV** (`.csv`) - Comma-separated values (CSV) file with two columns for aligned sentences and phrases. The first row must have two language codes. The first column is for the source language code, and the second column is for the target language code. * **TSV** (`.tsv` or `.tab`) - Tab-separated values (TSV) file with two columns for aligned sentences and phrases. The first row must have two language codes. The first column is for the source language code, and the second column is for the target language code. * **JSON** (`.json`) - Custom JSON format for specifying aligned sentences and phrases. * **Microsoft Excel** (`.xls` or `.xlsx`) - Excel file with the first two columns for aligned sentences and phrases. The first row contains the language code.

      You must encode all text data in UTF-8 format. For more information, see [Supported document formats for training data](https://cloud.ibm.com/docs/language-translator?topic=language-translator-customizing#supported-document-formats-for-training-data).

      #### Specifying file formats

      You can indicate the format of a file by including the file extension with the file name. Use the file extensions shown in **Supported file formats**.

      Alternatively, you can omit the file extension and specify one of the following `content-type` specifications for the file: * **TMX** - `application/x-tmx+xml` * **XLIFF** - `application/xliff+xml` * **CSV** - `text/csv` * **TSV** - `text/tab-separated-values` * **JSON** - `application/json` * **Microsoft Excel** - `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`

      For example, with `curl`, use the following `content-type` specification to indicate the format of a CSV file named **glossary**:

      `--form "forced_glossary=@glossary;type=text/csv"`.

      Parameters:
      createModelOptions - the CreateModelOptions containing the options for the call
      Returns:
      a ServiceCall with a result of type TranslationModel
    • deleteModel

      public com.ibm.cloud.sdk.core.http.ServiceCall<DeleteModelResult> deleteModel​(DeleteModelOptions deleteModelOptions)
      Delete model.

      Deletes a custom translation model.

      Parameters:
      deleteModelOptions - the DeleteModelOptions containing the options for the call
      Returns:
      a ServiceCall with a result of type DeleteModelResult
    • getModel

      public com.ibm.cloud.sdk.core.http.ServiceCall<TranslationModel> getModel​(GetModelOptions getModelOptions)
      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 has a status of `available`.

      Parameters:
      getModelOptions - the GetModelOptions containing the options for the call
      Returns:
      a ServiceCall with a result of type TranslationModel
    • listDocuments

      public com.ibm.cloud.sdk.core.http.ServiceCall<DocumentList> listDocuments​(ListDocumentsOptions listDocumentsOptions)
      List documents.

      Lists documents that have been submitted for translation.

      Parameters:
      listDocumentsOptions - the ListDocumentsOptions containing the options for the call
      Returns:
      a ServiceCall with a result of type DocumentList
    • listDocuments

      public com.ibm.cloud.sdk.core.http.ServiceCall<DocumentList> listDocuments()
      List documents.

      Lists documents that have been submitted for translation.

      Returns:
      a ServiceCall with a result of type DocumentList
    • translateDocument

      public com.ibm.cloud.sdk.core.http.ServiceCall<DocumentStatus> translateDocument​(TranslateDocumentOptions translateDocumentOptions)
      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. The maximum file size for document translation is * 20 MB for service instances on the Standard, Advanced, and Premium plans * 2 MB for service instances on the Lite plan.

      Parameters:
      translateDocumentOptions - the TranslateDocumentOptions containing the options for the call
      Returns:
      a ServiceCall with a result of type DocumentStatus
    • getDocumentStatus

      public com.ibm.cloud.sdk.core.http.ServiceCall<DocumentStatus> getDocumentStatus​(GetDocumentStatusOptions getDocumentStatusOptions)
      Get document status.

      Gets the translation status of a document.

      Parameters:
      getDocumentStatusOptions - the GetDocumentStatusOptions containing the options for the call
      Returns:
      a ServiceCall with a result of type DocumentStatus
    • deleteDocument

      public com.ibm.cloud.sdk.core.http.ServiceCall<Void> deleteDocument​(DeleteDocumentOptions deleteDocumentOptions)
      Delete document.

      Deletes a document.

      Parameters:
      deleteDocumentOptions - the DeleteDocumentOptions containing the options for the call
      Returns:
      a ServiceCall with a void result
    • getTranslatedDocument

      public com.ibm.cloud.sdk.core.http.ServiceCall<InputStream> getTranslatedDocument​(GetTranslatedDocumentOptions getTranslatedDocumentOptions)
      Get translated document.

      Gets the translated document associated with the given document ID.

      Parameters:
      getTranslatedDocumentOptions - the GetTranslatedDocumentOptions containing the options for the call
      Returns:
      a ServiceCall with a result of type InputStream