Class BaseConnector

    • Constructor Detail

      • BaseConnector

        public BaseConnector()
    • Method Detail

      • getSourceLanguage

        public LocaleId getSourceLanguage()
        Description copied from interface: IQuery
        Gets the current source language for this query engine.
        Specified by:
        getSourceLanguage in interface IQuery
        Returns:
        Code of the source language.
      • getTargetLanguage

        public LocaleId getTargetLanguage()
        Description copied from interface: IQuery
        Gets the current target language for this query engine.
        Specified by:
        getTargetLanguage in interface IQuery
        Returns:
        Code of the target language.
      • setLanguages

        public void setLanguages​(LocaleId sourceLocale,
                                 LocaleId targetLocale)
        Description copied from interface: IQuery
        Sets the source and target languages for this query engine.
        Specified by:
        setLanguages in interface IQuery
        Parameters:
        sourceLocale - Code of the source locale.
        targetLocale - Code of the target locale.
      • hasNext

        public boolean hasNext()
        Description copied from interface: IQuery
        Indicates of there is a hit available.
        Specified by:
        hasNext in interface IQuery
        Specified by:
        hasNext in interface Iterator<QueryResult>
        Returns:
        True if a hit is available, false if not.
      • 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>
        Returns:
        A QueryResult object that holds the source and target text of the hit, or null if there is no more hit.
      • clearAttributes

        public void clearAttributes()
        Description copied from interface: IQuery
        Removes all attributes from this query engine.
        Specified by:
        clearAttributes in interface IQuery
      • removeAttribute

        public void removeAttribute​(String name)
        Description copied from interface: IQuery
        Removes a given attribute from this query engine.
        Specified by:
        removeAttribute in interface IQuery
        Parameters:
        name - The name of the attribute to remove.
      • setAttribute

        public void setAttribute​(String name,
                                 String value)
        Description copied from interface: IQuery
        Sets an attribute for this query engine.
        Specified by:
        setAttribute in interface IQuery
        Parameters:
        name - name of the attribute.
        value - Value of the attribute.
      • setRootDirectory

        public void setRootDirectory​(String rootDir)
        Description copied from interface: IQuery
        Sets the root directory that may be used to replace the available ${rootDir} in the parameters of this object.
        Specified by:
        setRootDirectory in interface IQuery
        Parameters:
        rootDir - the root directory.
      • getParameters

        public IParameters getParameters()
        Description copied from interface: IQuery
        Gets the current parameters of this connector.
        Specified by:
        getParameters in interface IQuery
        Returns:
        the current parameters of this connector or null if no parameters are used.
      • setParameters

        public void setParameters​(IParameters params)
        Description copied from interface: IQuery
        Sets the parameters for opening and querying this connector.
        Specified by:
        setParameters in interface IQuery
        Parameters:
        params - the parameters to set.
      • getWeight

        public int getWeight()
        Description copied from interface: IQuery
        Get the weight for this connector.
        Specified by:
        getWeight in interface IQuery
        Returns:
        the weight for this connector
      • setWeight

        public void setWeight​(int weight)
        Description copied from interface: IQuery
        Set the relative weight of this IQuery connector as compared to other connectors. Used to set QueryResult.weight.
        Specified by:
        setWeight in interface IQuery
        Parameters:
        weight - the new relative weight.
      • batchQueryText

        public List<List<QueryResult>> batchQueryText​(List<String> plainTexts)
        Description copied from interface: IQuery
        Starts a batch query for a given list of plain texts.
        Note that batchQueryText does not use hasNext and next methods. Callers must use the returned list directly.
        Specified by:
        batchQueryText in interface IQuery
        Parameters:
        plainTexts - list of the plain texts to translate.
        Returns:
        a list of lists of query result. Each list corresponds to a source text (in the same order)
      • batchQuery

        public List<List<QueryResult>> batchQuery​(List<TextFragment> fragments)
        Slow default implementation using query!! Override to take advantage of servers batch API
        Specified by:
        batchQuery in interface IQuery
        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)
      • leverage

        public void leverage​(ITextUnit tu)
        Description copied from interface: IQuery
        Leverages a text unit (segmented or not) based on the current settings. Any options or attributes needed must be set before calling this method.
        Specified by:
        leverage in interface IQuery
        Parameters:
        tu - the text unit to leverage.
      • batchLeverage

        public void batchLeverage​(List<ITextUnit> tus)
        Slow default implementation using leverage(TextUnit). Override in sub-class if you want a custom batchLeverage
        Specified by:
        batchLeverage in interface IQuery
        Parameters:
        tus - list of the text units to process.
      • setNoQueryThreshold

        public void setNoQueryThreshold​(int noQueryThreshold)
        Description copied from interface: IQuery
        Sets the threshold for when to avoid executing a query.

        If the entry to leverage has already one candidate with a score equals or above this value, no query is performed. Use 101 to always allow the query.

        Specified by:
        setNoQueryThreshold in interface IQuery
        Parameters:
        noQueryThreshold - no-query threshold (a value between 0 and 101).
      • getNoQueryThreshold

        public int getNoQueryThreshold()
        Description copied from interface: IQuery
        Gets the threshold for when to avoid a query.
        Specified by:
        getNoQueryThreshold in interface IQuery
        Returns:
        the current no-query threshold.
      • leverageUsingBatchQuery

        protected void leverageUsingBatchQuery​(ITextUnit tu)
        Call this method inside the overriding leverage(ITextUnit) method of the derived class, if that class offers a fast batchQuery(List) method.
        Parameters:
        tu - the text unit to leverage.
      • batchLeverageUsingBatchQuery

        protected void batchLeverageUsingBatchQuery​(List<ITextUnit> tuList)
        Call this method inside the overriding batchLeverage(List) method of the derived class, if that class offers a fast batchQuery(List) method.
        Parameters:
        tuList - list of the text units to leverage.
      • toInternalCode

        protected String toInternalCode​(LocaleId locId)
        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.
        Parameters:
        locId - the locale identifier to convert.
        Returns:
        the internal string code for language/locale code for this connector.