public class CachedTranslator extends AbstractTranslator
Constructor and Description |
---|
CachedTranslator()
Create a new CachedTranslator (must set the
Translator with setTranslator(Translator) before use!) |
CachedTranslator(Translator translator)
Create a new CachedTranslator.
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(String text,
String targetLanguage)
Check whether this CachedTranslator's cache contains a translation of the text to the target language,
attempting to auto-detect the source language.
|
boolean |
contains(String text,
String sourceLanguage,
String targetLanguage)
Check whether this CachedTranslator's cache contains a translation of the text from the
source language to the target language.
|
int |
getNumTranslationPairs()
Get the number of different source/target translation pairs this CachedTranslator
currently has in its cache.
|
int |
getNumTranslationsFor(String sourceLanguage,
String targetLanguage)
Get the number of different translations from the source language to the target language
this CachedTranslator has in its cache.
|
Translator |
getTranslator() |
boolean |
isAvailable() |
void |
setTranslator(Translator translator) |
String |
translate(String text,
String targetLanguage)
Translate text to the given language
This method attempts to auto-detect the source language of the text.
|
String |
translate(String text,
String sourceLanguage,
String targetLanguage)
Translate text between given languages.
|
detectLanguage
public CachedTranslator()
Translator
with setTranslator(Translator)
before use!)public CachedTranslator(Translator translator)
translator
- The translator that should be used for the underlying translation service. The properties
for that service must be set properly!public Translator getTranslator()
public void setTranslator(Translator translator)
translator
- the translator to setpublic String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException
Translator
text
- The text to translate.sourceLanguage
- The input text language (for example, "en").targetLanguage
- The desired language to translate to (for example, "fr").TikaException
- When there is an error translating.IOException
public String translate(String text, String targetLanguage) throws TikaException, IOException
Translator
text
- The text to translate.targetLanguage
- The desired language to translate to (for example, "hi").TikaException
- When there is an error translating.IOException
public boolean isAvailable()
public int getNumTranslationPairs()
public int getNumTranslationsFor(String sourceLanguage, String targetLanguage)
sourceLanguage
- The source language of translation.targetLanguage
- The target language of translation.public boolean contains(String text, String sourceLanguage, String targetLanguage)
text
- What string to check for.sourceLanguage
- The source language of translation.targetLanguage
- The target language of translation.public boolean contains(String text, String targetLanguage)
text
- What string to check for.targetLanguage
- The target language of translation.Copyright © 2007–2017 The Apache Software Foundation. All rights reserved.