Class MarianTranslator

  • All Implemented Interfaces:
    Translator

    public class MarianTranslator
    extends AbstractTranslator
    Translator that uses the Marian NMT decoder for translation.

    Users must install Marian NMT and configure model locations before using this Translator.

    • Constructor Detail

      • MarianTranslator

        public MarianTranslator()
        Default constructor.
    • Method Detail

      • 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:
        TikaException - on any error performing translation.
        IOException - on any I/O error performing translation.
      • translate

        public String translate​(String text,
                                String sourceLanguage,
                                String targetLanguage)
                         throws TikaException,
                                IOException
        Translate method with specific source and target languages.
        Parameters:
        text - The text to translate.
        sourceLanguage - The language to translate from (for example, "en").
        targetLanguage - The desired language to translate to (for example, "hi").
        Returns:
        The translated text.
        Throws:
        TikaException - on any error performing translation.
        IOException - on any I/O error performing translation.
      • isAvailable

        public boolean isAvailable()
        Returns:
        true if this Translator is probably able to translate right now.
      • isAvailable

        public boolean isAvailable​(String sourceLanguage,
                                   String targetLanguage)
        Checks if the approproate Marian engine is available.
        Parameters:
        sourceLanguage - The language to translate from (for example, "en").
        targetLanguage - The desired language to translate to (for example, "hi").
        Returns: