Class JoshuaNetworkTranslator
- All Implemented Interfaces:
Translator
This translator is designed to work with a TCP-IP available Joshua translation server, specifically the REST-based Joshua server.
If you were to interact with the server via curl a request would look as follows
{code
curl http://localhost:5000/joshua/translate/english \
-i -H "Content-Type: application/json" \
-X POST -d '{"inputLanguage": "Spanish", "inputText": "vuelo"}' -v
}
Joshua requires input to be pre-formatted into sentences, one per line, so this translation implementation takes care of that.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor which first checks for the presence of thetranslator.joshua.propertiesfile. -
Method Summary
Modifier and TypeMethodDescriptionbooleanMake an attempt to guess the source language viabefore making the call toinvalid reference
org.apache.tika.language.translate.AbstractTranslator#detectLanguage(String)translate(String, String, String)Initially then check if the source language has been provided.Methods inherited from class AbstractTranslator
detectLanguage
-
Constructor Details
-
JoshuaNetworkTranslator
public JoshuaNetworkTranslator()Default constructor which first checks for the presence of thetranslator.joshua.propertiesfile. We check if the remote server is available on each translation process. This check is not a remote call, but instead a check for null value within of a local variable represetning the value forjoshua.server.url, which should be populated within thetranslator.joshua.propertiesfile.
-
-
Method Details
-
translate
public String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException Initially then check if the source language has been provided. If no source language (or a null value) has been provided then we make an attempt to guess the source using Tika's
. If we are still unable to guess the language then we return the source text.invalid reference
org.apache.tika.langdetect.OptimaizeLangDetectorWe then process the input text into a new string consisting of sentences, one per line e.g. insert \n between the presence of '.'
- 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- See Also:
-
translate
Make an attempt to guess the source language viabefore making the call toinvalid reference
org.apache.tika.language.translate.AbstractTranslator#detectLanguage(String)translate(String, String, String)- 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- See Also:
-
isAvailable
public boolean isAvailable()- Returns:
- true if this Translator is probably able to translate right now.
- See Also:
-