Class CachedTranslator
java.lang.Object
org.apache.tika.language.translate.impl.AbstractTranslator
org.apache.tika.language.translate.impl.CachedTranslator
- All Implemented Interfaces:
Translator
CachedTranslator. Saves a map of previous translations in order to prevent repetitive translation requests.
-
Constructor Summary
ConstructorDescriptionCreate a new CachedTranslator (must set theTranslator
withsetTranslator(Translator)
before use!)CachedTranslator
(Translator translator) Create a new CachedTranslator. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Check whether this CachedTranslator's cache contains a translation of the text to the target language, attempting to auto-detect the source language.boolean
Check whether this CachedTranslator's cache contains a translation of the text from the source language to the target language.int
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.boolean
void
setTranslator
(Translator translator) Translate text to the given language This method attempts to auto-detect the source language of the text.Translate text between given languages.Methods inherited from class org.apache.tika.language.translate.impl.AbstractTranslator
detectLanguage
-
Constructor Details
-
CachedTranslator
public CachedTranslator()Create a new CachedTranslator (must set theTranslator
withsetTranslator(Translator)
before use!) -
CachedTranslator
Create a new CachedTranslator.- Parameters:
translator
- The translator that should be used for the underlying translation service. The properties for that service must be set properly!
-
-
Method Details
-
getTranslator
- Returns:
- the translator
-
setTranslator
- Parameters:
translator
- the translator to set
-
translate
public String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException Description copied from interface:Translator
Translate text between given languages.- Parameters:
text
- The text to translate.sourceLanguage
- The input text language (for example, "en").targetLanguage
- The desired language to translate to (for example, "fr").- Returns:
- The translation result. If translation is unavailable, returns the same text back.
- Throws:
TikaException
- When there is an error translating.IOException
-
translate
Description copied from interface:Translator
Translate text to the given language This method attempts to auto-detect the source language of the text.- Parameters:
text
- The text to translate.targetLanguage
- The desired language to translate to (for example, "hi").- Returns:
- The translation result. If translation is unavailable, returns the same text back.
- Throws:
TikaException
- When there is an error translating.IOException
-
isAvailable
public boolean isAvailable()- Returns:
- true if this Translator is probably able to translate right now.
-
getNumTranslationPairs
public int getNumTranslationPairs()Get the number of different source/target translation pairs this CachedTranslator currently has in its cache.- Returns:
- Number of translation source/target pairs in this CachedTranslator's cache.
- Since:
- Tika 1.6
-
getNumTranslationsFor
Get the number of different translations from the source language to the target language this CachedTranslator has in its cache.- Parameters:
sourceLanguage
- The source language of translation.targetLanguage
- The target language of translation.- Returns:
- The number of translations between source and target.
- Since:
- Tika 1.6
-
contains
Check whether this CachedTranslator's cache contains a translation of the text from the source language to the target language.- Parameters:
text
- What string to check for.sourceLanguage
- The source language of translation.targetLanguage
- The target language of translation.- Returns:
- true if the cache contains a translation of the text, false otherwise.
-
contains
Check whether this CachedTranslator's cache contains a translation of the text to the target language, attempting to auto-detect the source language.- Parameters:
text
- What string to check for.targetLanguage
- The target language of translation.- Returns:
- true if the cache contains a translation of the text, false otherwise.
-