Class RTGTranslator
java.lang.Object
org.apache.tika.language.translate.impl.AbstractTranslator
org.apache.tika.language.translate.impl.RTGTranslator
- All Implemented Interfaces:
Translator
This translator is designed to work with a TCP-IP available RTG translation server, specifically the REST-based RTG server.
To get Docker image: https://hub.docker.com/repository/docker/tgowda/rtg-model
{code
# without GPU
docker run --rm -i -p 6060:6060 tgowda/rtg-model:500toEng-v1
# Or, with GPU device 0
docker run --rm -i -p 6060:6060 --gpus '"device=0"' tgowda/rtg-model:500toEng-v1
}
If you were to interact with the server via curl a request would look as follows
{code
curl --data "source=Comment allez-vous?" \
--data "source=Bonne journée" \
http://localhost:6060/translate
}
RTG requires input to be pre-formatted into sentences, one per line, so this translation implementation takes care of that.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanTranslate 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
-
Field Details
-
RTG_TRANSLATE_URL_BASE
- See Also:
-
RTG_PROPS
- See Also:
-
-
Constructor Details
-
RTGTranslator
public RTGTranslator()
-
-
Method Details
-
translate
public String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException Description copied from interface:TranslatorTranslate 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:TranslatorTranslate 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
-
translate
- Throws:
TikaExceptionIOException
-
isAvailable
public boolean isAvailable()- Returns:
- true if this Translator is probably able to translate right now.
-