Class KantanMTv21Connector

  • All Implemented Interfaces:
    AutoCloseable, Iterator<QueryResult>, IQuery

    public class KantanMTv21Connector
    extends BaseConnector
    Connector for the KantanMT API v2.1. The engine must be started separately (through the KantanMT web interface, or via API) and is assumed to be running by this connector. As the engine initialization process takes several minutes, the connector does not perform initialization on its own in the open() method.
    See Also:
    http://docs.kantanmt.apiary.io Note: KantanMT uses TLS 1.2, which is supported by default by Java 8 (but not Java 7)
    • Constructor Detail

      • KantanMTv21Connector

        public KantanMTv21Connector()
    • Method Detail

      • getName

        public String getName()
        Description copied from interface: IQuery
        Gets the name of the connector.
        Returns:
        the name of the connector.
      • getSettingsDisplay

        public String getSettingsDisplay()
        Description copied from interface: IQuery
        Gets a display representation of the current settings for this connector. This can be a display of some of the parameters for example, or some explanations about default non-modifiable settings.
        Returns:
        a display representation of the current settings.
      • open

        public void open()
        Description copied from interface: IQuery
        Opens this query engine.
      • close

        public void close()
        Description copied from interface: IQuery
        Closes this connector.
      • toInternalCode

        protected String toInternalCode​(LocaleId locId)
        Description copied from class: BaseConnector
        Converts a locale identifier to the internal string value for a language/locale code for this connector. By default, this simply returns the string of the given LocaleId.
        Overrides:
        toInternalCode in class BaseConnector
        Parameters:
        locId - the locale identifier to convert.
        Returns:
        the internal string code for language/locale code for this connector.
      • query

        public int query​(String plainText)
        Description copied from interface: IQuery
        Starts a query for a give plain text.
        Parameters:
        plainText - text to query.
        Returns:
        The number of hits for the given query.
      • query

        public int query​(TextFragment tf)
        Description copied from interface: IQuery
        Starts a query for a given text.
        Parameters:
        tf - The text to query.
        Returns:
        The number of hits for the given query.
      • next

        public QueryResult next()
        Description copied from interface: IQuery
        Gets the next hit for the last query.
        Specified by:
        next in interface IQuery
        Specified by:
        next in interface Iterator<QueryResult>
        Overrides:
        next in class BaseConnector
        Returns:
        A QueryResult object that holds the source and target text of the hit, or null if there is no more hit.
      • batchQuery

        public List<List<QueryResult>> batchQuery​(List<TextFragment> fragments)
        Description copied from class: BaseConnector
        Slow default implementation using query!! Override to take advantage of servers batch API
        Specified by:
        batchQuery in interface IQuery
        Overrides:
        batchQuery in class BaseConnector
        Parameters:
        fragments - list of the text fragments to translate.
        Returns:
        a list of lists of query result. Each list corresponds to a source text (in the same order)
      • getEngines

        public String getEngines()
        Gets the information about the available engines.
        Returns:
        A JSON string with the engine information.
      • getEngineStatus

        public String getEngineStatus​(String engine)
        Get the status of an engine.
        Parameters:
        engine - the name of the engine to check.
        Returns:
        the status information ('running' for when it is online and ready, etc.)
      • startEngine

        public String startEngine​(String engine)
        Starts an engine (do nothing if it's already started).
        Parameters:
        engine - the name of the engine to start.
        Returns:
        the status of the engine after the call (e.g. 'running' if it is running already).
      • stopEngine

        public String stopEngine​(String engine)
        Stops an engine (do nothing if it's already stopped).
        Parameters:
        engine - the name of the engine to start.
        Returns:
        the status of the engine after the call (e.g. 'terminating' if it is being stopped).