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 and Description |
---|
JoshuaNetworkTranslator()
Default constructor which first checks for the presence of
the
translator.joshua.properties file. |
Modifier and Type | Method and Description |
---|---|
boolean |
isAvailable() |
String |
translate(String text,
String targetLanguage)
Make an attempt to guess the source language via
AbstractTranslator.detectLanguage(String)
before making the call to
translate(String, String, String) |
String |
translate(String text,
String sourceLanguage,
String targetLanguage)
Initially then check if the source language has been provided.
|
detectLanguage
public JoshuaNetworkTranslator()
translator.joshua.properties
file.
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 for joshua.server.url
, which should be populated
within the translator.joshua.properties
file.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
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 '.'
text
- The text to translate.sourceLanguage
- The input text language (for example, "en").targetLanguage
- The desired language to translate to (for example, "fr").TikaException
- When there is an error translating.IOException
(java.lang.String, java.lang.String, java.lang.String)
public String translate(String text, String targetLanguage) throws TikaException, IOException
AbstractTranslator.detectLanguage(String)
before making the call to
translate(String, String, String)
text
- The text to translate.targetLanguage
- The desired language to translate to (for example, "hi").TikaException
- When there is an error translating.IOException
Translator.translate(java.lang.String, java.lang.String)
public boolean isAvailable()
Translator.isAvailable()
Copyright © 2007–1969 The Apache Software Foundation. All rights reserved.