Class ExternalTranslator
java.lang.Object
org.apache.tika.language.translate.impl.AbstractTranslator
org.apache.tika.language.translate.impl.ExternalTranslator
- All Implemented Interfaces:
Translator
- Direct Known Subclasses:
MosesTranslator
Abstract class used to interact with command line/external Translators.
- Since:
- Tika 1.7
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckCommand(String checkCommandString, int... successCodes) Checks to see if the command can be run.runAndGetOutput(String command, String[] env, File workingDirectory) Run the given command and return the output written to standard out.Default translate method which uses built Tika language identification.Methods inherited from class AbstractTranslator
detectLanguageMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Translator
isAvailable, translate
-
Constructor Details
-
ExternalTranslator
public ExternalTranslator()
-
-
Method Details
-
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:
IOExceptionInterruptedException
-
checkCommand
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
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:
ExceptionTikaException- When there is an error translating.IOException
-