Class JoshuaNetworkTranslator
- java.lang.Object
- 
- org.apache.tika.language.translate.impl.AbstractTranslator
- 
- org.apache.tika.language.translate.impl.JoshuaNetworkTranslator
 
 
- 
- All Implemented Interfaces:
- Translator
 
 public class JoshuaNetworkTranslator extends AbstractTranslator 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 SummaryConstructors Constructor Description JoshuaNetworkTranslator()Default constructor which first checks for the presence of thetranslator.joshua.propertiesfile.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisAvailable()Stringtranslate(String text, String targetLanguage)Make an attempt to guess the source language viaorg.apache.tika.language.translate.AbstractTranslator#detectLanguage(String)before making the call totranslate(String, String, String)Stringtranslate(String text, String sourceLanguage, String targetLanguage)Initially then check if the source language has been provided.- 
Methods inherited from class org.apache.tika.language.translate.impl.AbstractTranslatordetectLanguage
 
- 
 
- 
- 
- 
Constructor Detail- 
JoshuaNetworkTranslatorpublic 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 Detail- 
translatepublic 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 org.apache.tika.langdetect.OptimaizeLangDetector. If we are still unable to guess the language then we return the source text.We 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:
- (java.lang.String, java.lang.String, java.lang.String)
 
 - 
translatepublic String translate(String text, String targetLanguage) throws TikaException, IOException Make an attempt to guess the source language viaorg.apache.tika.language.translate.AbstractTranslator#detectLanguage(String)before making the call totranslate(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:
- Translator.translate(java.lang.String, java.lang.String)
 
 - 
isAvailablepublic boolean isAvailable() - Returns:
- true if this Translator is probably able to translate right now.
- See Also:
- Translator.isAvailable()
 
 
- 
 
-