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

public abstract class ExternalTranslator extends AbstractTranslator
Abstract class used to interact with command line/external Translators.
Since:
Tika 1.7
See Also:
  • 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:
      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