Class ExternalTranslator
- java.lang.Object
-
- org.apache.tika.language.translate.AbstractTranslator
-
- org.apache.tika.language.translate.ExternalTranslator
-
- All Implemented Interfaces:
Translator
- Direct Known Subclasses:
MosesTranslator
public abstract class ExternalTranslator extends AbstractTranslator
Abstract class used to interact with command line/external Translators.- Since:
- Tika 1.7
- See Also:
for an example of extending this class.
-
-
Constructor Summary
Constructors Constructor Description ExternalTranslator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
checkCommand(String checkCommandString, int... successCodes)
Checks to see if the command can be run.Reader
runAndGetOutput(String command, String[] env, File workingDirectory)
Run the given command and return the output written to standard out.String
translate(String text, String targetLanguage)
Default translate method which uses built Tika language identification.-
Methods inherited from class org.apache.tika.language.translate.AbstractTranslator
detectLanguage
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.tika.language.translate.Translator
isAvailable, translate
-
-
-
-
Method Detail
-
runAndGetOutput
public Reader runAndGetOutput(String command, String[] env, File workingDirectory) throws IOException, InterruptedException
Run the given command and return the output written to standard out.- Parameters:
command
- The complete command to run.env
- The environment to pass along to the Runtime.workingDirectory
- The directory from which to run the command.- Returns:
- The output of the command written to standard out.
- Throws:
IOException
InterruptedException
-
checkCommand
public boolean checkCommand(String checkCommandString, int... successCodes)
Checks to see if the command can be run. Typically used with something like "myapp --version" to check to see if "myapp" is installed and on the path.- Parameters:
checkCommandString
- The command to run and check the return code of.successCodes
- Return codes that signify success.
-
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:
Exception
TikaException
- When there is an error translating.IOException
-
-