Class DefaultTranslatorFactory

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Map<ai.djl.util.Pair<java.lang.reflect.Type,​java.lang.reflect.Type>,​Translator<?,​?>> translators  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Set<ai.djl.util.Pair<java.lang.reflect.Type,​java.lang.reflect.Type>> getSupportedTypes()
      Returns supported input/output classes.
      boolean isSupported​(java.lang.Class<?> input, java.lang.Class<?> output)
      Returns if the input/output is supported by the TranslatorFactory.
      Translator<?,​?> newInstance​(java.lang.Class<?> input, java.lang.Class<?> output, Model model, java.util.Map<java.lang.String,​?> arguments)
      Returns a new instance of the Translator class.
      <I,​O>
      void
      registerTranslator​(java.lang.Class<I> input, java.lang.Class<O> output, Translator<I,​O> translator)
      Registers a Translator with the TranslatorFactory.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • translators

        protected java.util.Map<ai.djl.util.Pair<java.lang.reflect.Type,​java.lang.reflect.Type>,​Translator<?,​?>> translators
    • Constructor Detail

      • DefaultTranslatorFactory

        public DefaultTranslatorFactory()
    • Method Detail

      • registerTranslator

        public <I,​O> void registerTranslator​(java.lang.Class<I> input,
                                                   java.lang.Class<O> output,
                                                   Translator<I,​O> translator)
        Registers a Translator with the TranslatorFactory.
        Type Parameters:
        I - the model input type
        O - the model output type
        Parameters:
        input - the input data type
        output - the output data type
        translator - the Translator to be registered
      • getSupportedTypes

        public java.util.Set<ai.djl.util.Pair<java.lang.reflect.Type,​java.lang.reflect.Type>> getSupportedTypes()
        Returns supported input/output classes.
        Specified by:
        getSupportedTypes in interface TranslatorFactory
        Returns:
        a set of supported input/output classes
      • isSupported

        public boolean isSupported​(java.lang.Class<?> input,
                                   java.lang.Class<?> output)
        Returns if the input/output is supported by the TranslatorFactory.
        Specified by:
        isSupported in interface TranslatorFactory
        Parameters:
        input - the input class
        output - the output class
        Returns:
        true if the input/output type is supported
      • newInstance

        public Translator<?,​?> newInstance​(java.lang.Class<?> input,
                                                 java.lang.Class<?> output,
                                                 Model model,
                                                 java.util.Map<java.lang.String,​?> arguments)
                                          throws TranslateException
        Returns a new instance of the Translator class.
        Specified by:
        newInstance in interface TranslatorFactory
        Parameters:
        input - the input class
        output - the output class
        model - the Model that uses the Translator
        arguments - the configurations for a new Translator instance
        Returns:
        a new instance of the Translator class
        Throws:
        TranslateException - if failed to create Translator instance