Class LanguageTranslator
public class LanguageTranslator
extends com.ibm.cloud.sdk.core.service.BaseService
- Version:
- v3
- See Also:
- Language Translator
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_SERVICE_NAME
static String
DEFAULT_SERVICE_URL
Fields inherited from class com.ibm.cloud.sdk.core.service.BaseService
PROPNAME_DISABLE_SSL, PROPNAME_ENABLE_GZIP, PROPNAME_URL
-
Constructor Summary
Constructors Constructor Description LanguageTranslator(String version)
Constructs an instance of the `LanguageTranslator` client.LanguageTranslator(String version, com.ibm.cloud.sdk.core.security.Authenticator authenticator)
Constructs an instance of the `LanguageTranslator` client.LanguageTranslator(String version, String serviceName)
Constructs an instance of the `LanguageTranslator` client.LanguageTranslator(String version, String serviceName, com.ibm.cloud.sdk.core.security.Authenticator authenticator)
Constructs an instance of the `LanguageTranslator` client. -
Method Summary
Modifier and Type Method Description com.ibm.cloud.sdk.core.http.ServiceCall<TranslationModel>
createModel(CreateModelOptions createModelOptions)
Create model.com.ibm.cloud.sdk.core.http.ServiceCall<Void>
deleteDocument(DeleteDocumentOptions deleteDocumentOptions)
Delete document.com.ibm.cloud.sdk.core.http.ServiceCall<DeleteModelResult>
deleteModel(DeleteModelOptions deleteModelOptions)
Delete model.com.ibm.cloud.sdk.core.http.ServiceCall<DocumentStatus>
getDocumentStatus(GetDocumentStatusOptions getDocumentStatusOptions)
Get document status.com.ibm.cloud.sdk.core.http.ServiceCall<TranslationModel>
getModel(GetModelOptions getModelOptions)
Get model details.com.ibm.cloud.sdk.core.http.ServiceCall<InputStream>
getTranslatedDocument(GetTranslatedDocumentOptions getTranslatedDocumentOptions)
Get translated document.String
getVersion()
Gets the version.com.ibm.cloud.sdk.core.http.ServiceCall<IdentifiedLanguages>
identify(IdentifyOptions identifyOptions)
Identify language.com.ibm.cloud.sdk.core.http.ServiceCall<DocumentList>
listDocuments()
List documents.com.ibm.cloud.sdk.core.http.ServiceCall<DocumentList>
listDocuments(ListDocumentsOptions listDocumentsOptions)
List documents.com.ibm.cloud.sdk.core.http.ServiceCall<IdentifiableLanguages>
listIdentifiableLanguages()
List identifiable languages.com.ibm.cloud.sdk.core.http.ServiceCall<IdentifiableLanguages>
listIdentifiableLanguages(ListIdentifiableLanguagesOptions listIdentifiableLanguagesOptions)
List identifiable languages.com.ibm.cloud.sdk.core.http.ServiceCall<Languages>
listLanguages()
List supported languages.com.ibm.cloud.sdk.core.http.ServiceCall<Languages>
listLanguages(ListLanguagesOptions listLanguagesOptions)
List supported languages.com.ibm.cloud.sdk.core.http.ServiceCall<TranslationModels>
listModels()
List models.com.ibm.cloud.sdk.core.http.ServiceCall<TranslationModels>
listModels(ListModelsOptions listModelsOptions)
List models.void
setVersion(String version)
Sets the version.com.ibm.cloud.sdk.core.http.ServiceCall<TranslationResult>
translate(TranslateOptions translateOptions)
Translate.com.ibm.cloud.sdk.core.http.ServiceCall<DocumentStatus>
translateDocument(TranslateDocumentOptions translateDocumentOptions)
Translate document.Methods inherited from class com.ibm.cloud.sdk.core.service.BaseService
configureClient, configureService, constructServiceUrl, constructServiceURL, enableGzipCompression, getAuthenticator, getClient, getEndPoint, getName, getServiceUrl, isJsonMimeType, isJsonPatchMimeType, setClient, setDefaultHeaders, setEndPoint, setServiceUrl, toString
-
Field Details
-
DEFAULT_SERVICE_NAME
- See Also:
- Constant Field Values
-
DEFAULT_SERVICE_URL
- See Also:
- Constant Field Values
-
-
Constructor Details
-
LanguageTranslator
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
- theAuthenticator
instance to be configured for this client
-
LanguageTranslator
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 instanceauthenticator
- theAuthenticator
instance to be configured for this client
-
-
Method Details
-
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
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
- theListLanguagesOptions
containing the options for the call- Returns:
- a
ServiceCall
with a result of typeLanguages
-
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 typeLanguages
-
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
- theTranslateOptions
containing the options for the call- Returns:
- a
ServiceCall
with a result of typeTranslationResult
-
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
- theListIdentifiableLanguagesOptions
containing the options for the call- Returns:
- a
ServiceCall
with a result of typeIdentifiableLanguages
-
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 typeIdentifiableLanguages
-
identify
public com.ibm.cloud.sdk.core.http.ServiceCall<IdentifiedLanguages> identify(IdentifyOptions identifyOptions)Identify language.Identifies the language of the input text.
- Parameters:
identifyOptions
- theIdentifyOptions
containing the options for the call- Returns:
- a
ServiceCall
with a result of typeIdentifiedLanguages
-
listModels
public com.ibm.cloud.sdk.core.http.ServiceCall<TranslationModels> listModels(ListModelsOptions listModelsOptions)List models.Lists available translation models.
- Parameters:
listModelsOptions
- theListModelsOptions
containing the options for the call- Returns:
- a
ServiceCall
with a result of typeTranslationModels
-
listModels
List models.Lists available translation models.
- Returns:
- a
ServiceCall
with a result of typeTranslationModels
-
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
- theCreateModelOptions
containing the options for the call- Returns:
- a
ServiceCall
with a result of typeTranslationModel
-
deleteModel
public com.ibm.cloud.sdk.core.http.ServiceCall<DeleteModelResult> deleteModel(DeleteModelOptions deleteModelOptions)Delete model.Deletes a custom translation model.
- Parameters:
deleteModelOptions
- theDeleteModelOptions
containing the options for the call- Returns:
- a
ServiceCall
with a result of typeDeleteModelResult
-
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
- theGetModelOptions
containing the options for the call- Returns:
- a
ServiceCall
with a result of typeTranslationModel
-
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
- theListDocumentsOptions
containing the options for the call- Returns:
- a
ServiceCall
with a result of typeDocumentList
-
listDocuments
List documents.Lists documents that have been submitted for translation.
- Returns:
- a
ServiceCall
with a result of typeDocumentList
-
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
- theTranslateDocumentOptions
containing the options for the call- Returns:
- a
ServiceCall
with a result of typeDocumentStatus
-
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
- theGetDocumentStatusOptions
containing the options for the call- Returns:
- a
ServiceCall
with a result of typeDocumentStatus
-
deleteDocument
public com.ibm.cloud.sdk.core.http.ServiceCall<Void> deleteDocument(DeleteDocumentOptions deleteDocumentOptions)Delete document.Deletes a document.
- Parameters:
deleteDocumentOptions
- theDeleteDocumentOptions
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
- theGetTranslatedDocumentOptions
containing the options for the call- Returns:
- a
ServiceCall
with a result of typeInputStream
-