public abstract class AzureCognitiveServices extends Object implements ITranslator
Constructor and Description |
---|
AzureCognitiveServices() |
Modifier and Type | Method and Description |
---|---|
boolean |
canTranslate(String sourceLanguageCode,
String targetLanguageCode)
Checks if a translation is handled between two language codes.
|
void |
deconfigure()
Deconfigures the translator to "lose" the API key(s).
|
String |
detectLanguage(String text)
Detects the language of a text using the Azure Cognitive Services.
|
String |
getLanguageCode(String languageCode)
Gets the "real" language code, no matter the input case.
|
String |
getLanguageDescription(String languageCode)
Gets the language description for a language code, e.g.
|
String[] |
getLanguages()
Gets the supported languages by the Azure Cognitive Services.
|
String |
getName()
Returns the name of this translator.
|
String |
getReadyState()
Gets the ready state of this translator.
|
boolean |
isLanguageHandled(String languageCode)
Verifies if a Language Code is handled by this translator.
|
void |
setSubscriptionKey(String key)
Constructs the TokenAccess instance based on the subsciption key.
|
Translation |
translate(KString sourceText,
String sourceLanguageCode,
String targetLanguageCode)
Translates a text in plain text or HTML.
|
void |
updateSupportedLanguages()
Updates the translator with the supported languages by means of requesting the information
from the service.
|
public void setSubscriptionKey(String key) throws IllegalArgumentException
key
- The subscription key.IllegalArgumentException
- For invalid key.public void updateSupportedLanguages()
updateSupportedLanguages
in interface ITranslator
public String getLanguageCode(String languageCode)
getLanguageCode
in interface ITranslator
languageCode
- The language code.public void deconfigure()
deconfigure
in interface ITranslator
public String getReadyState()
getReadyState
in interface ITranslator
public String getName()
getName
in interface ITranslator
public boolean isLanguageHandled(String languageCode)
isLanguageHandled
in interface ITranslator
languageCode
- The language code.public String getLanguageDescription(String languageCode)
getLanguageDescription
in interface ITranslator
languageCode
- The language code.public boolean canTranslate(String sourceLanguageCode, String targetLanguageCode)
canTranslate
in interface ITranslator
sourceLanguageCode
- The source language code.targetLanguageCode
- The target language code.public Translation translate(KString sourceText, String sourceLanguageCode, String targetLanguageCode) throws TranslationException, RequestException
translate
in interface ITranslator
sourceText
- The source text to translate.sourceLanguageCode
- The source language code, null for automatic detection.targetLanguageCode
- The target language code.RequestException
- If the translation web service failed.TranslationException
- An exception for translation failure.public String[] getLanguages() throws TranslationException, RequestException
RequestException
- If the translation web service failed.TranslationException
- An exception for translation failure.public String detectLanguage(String text) throws TranslationException, RequestException
text
- Text to detect the language.RequestException
- If the translation web service failed.TranslationException
- An exception for translation failure.iizi® is a registered trademark of Mindus SARL. © Copyright Mindus SARL, 2020. All rights reserved.