Class MarianTranslator
- java.lang.Object
-
- org.apache.tika.language.translate.impl.AbstractTranslator
-
- org.apache.tika.language.translate.impl.MarianTranslator
-
- All Implemented Interfaces:
Translator
public class MarianTranslator extends AbstractTranslator
Translator that uses the Marian NMT decoder for translation.Users must install Marian NMT and configure model locations before using this Translator.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MarianTranslator.MarianServerClient
Internal Client for marian-server Web Socket Server.
-
Constructor Summary
Constructors Constructor Description MarianTranslator()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isAvailable()
boolean
isAvailable(String sourceLanguage, String targetLanguage)
Checks if the approproate Marian engine is available.String
translate(String text, String targetLanguage)
Default translate method which uses built Tika language identification.String
translate(String text, String sourceLanguage, String targetLanguage)
Translate method with specific source and target languages.-
Methods inherited from class org.apache.tika.language.translate.impl.AbstractTranslator
detectLanguage
-
-
-
-
Method Detail
-
translate
public String translate(String text, String targetLanguage) throws TikaException, IOException
Default translate method which uses built Tika language identification.- Parameters:
text
- The text to translate.targetLanguage
- The desired language to translate to (for example, "hi").- Returns:
- The translated text.
- Throws:
TikaException
- on any error performing translation.IOException
- on any I/O error performing translation.
-
translate
public String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException
Translate method with specific source and target languages.- Parameters:
text
- The text to translate.sourceLanguage
- The language to translate from (for example, "en").targetLanguage
- The desired language to translate to (for example, "hi").- Returns:
- The translated text.
- Throws:
TikaException
- on any error performing translation.IOException
- on any I/O error performing translation.
-
isAvailable
public boolean isAvailable()
- Returns:
- true if this Translator is probably able to translate right now.
-
isAvailable
public boolean isAvailable(String sourceLanguage, String targetLanguage)
Checks if the approproate Marian engine is available.- Parameters:
sourceLanguage
- The language to translate from (for example, "en").targetLanguage
- The desired language to translate to (for example, "hi").- Returns:
-
-