Class MicrosoftMTConnector
- java.lang.Object
-
- net.sf.okapi.lib.translation.BaseConnector
-
- net.sf.okapi.connectors.microsoft.MicrosoftMTConnector
-
- All Implemented Interfaces:
AutoCloseable,Iterator<QueryResult>,IQuery,ITMQuery
public class MicrosoftMTConnector extends BaseConnector implements ITMQuery
-
-
Constructor Summary
Constructors Constructor Description MicrosoftMTConnector()MicrosoftMTConnector(org.apache.http.impl.client.CloseableHttpClient httpClient)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> List<List<QueryResult>>_batchQuery(List<String> texts, List<T> originalText, net.sf.okapi.connectors.microsoft.QueryResultBuilder<T> qrBuilder)protected <T> int_query(String queryText, T originalText, net.sf.okapi.connectors.microsoft.QueryResultBuilder<T> resultBuilder)protected <T> List<List<QueryResult>>_subBatchQuery(List<String> texts, List<T> originalText, net.sf.okapi.connectors.microsoft.QueryResultBuilder<T> qrBuilder)voidbatchLeverage(List<ITextUnit> tuList)Slow default implementation using leverage(TextUnit).List<List<QueryResult>>batchQuery(List<TextFragment> fragments)Slow default implementation using query!! Override to take advantage of servers batch APIList<List<QueryResult>>batchQueryText(List<String> plainTexts)Starts a batch query for a given list of plain texts.voidclose()Closes this connector.intgetMaximumHits()Gets the current maximum number of hits to retrieve.StringgetName()Gets the name of the connector.ParametersgetParameters()Gets the current parameters of this connector.StringgetSettingsDisplay()Gets a display representation of the current settings for this connector.intgetThreshold()Gets the current threshold value to use for the query.booleanhasNext()Indicates of there is a hit available.voidleverage(ITextUnit tu)Leverages a text unit (segmented or not) based on the current settings.QueryResultnext()Gets the next hit for the last query.voidopen()Opens this query engine.intquery(String plainText)Starts a query for a give plain text.intquery(TextFragment frag)Starts a query for a given text.voidsetLanguages(LocaleId sourceLocale, LocaleId targetLocale)Sets the source and target languages for this query engine.voidsetMaximumHits(int maximumHits)Sets the maximum number of hits to retrieve.voidsetParameters(IParameters params)Sets the parameters for opening and querying this connector.voidsetThreshold(int threshold)Sets the threshold value to use for the query.protected StringtoInternalCode(LocaleId locale)Converts a locale identifier to the internal string value for a language/locale code for this connector.-
Methods inherited from class net.sf.okapi.lib.translation.BaseConnector
batchLeverageUsingBatchQuery, clearAttributes, getNoQueryThreshold, getSourceLanguage, getTargetLanguage, getWeight, leverageUsingBatchQuery, removeAttribute, setAttribute, setNoQueryThreshold, setRootDirectory, setWeight
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.okapi.common.query.IQuery
clearAttributes, getNoQueryThreshold, getSourceLanguage, getTargetLanguage, getWeight, removeAttribute, setAttribute, setNoQueryThreshold, setRootDirectory, setWeight
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Method Detail
-
close
public void close()
Description copied from interface:IQueryCloses this connector.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceIQuery
-
getName
public String getName()
Description copied from interface:IQueryGets the name of the connector.
-
getSettingsDisplay
public String getSettingsDisplay()
Description copied from interface:IQueryGets 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.- Specified by:
getSettingsDisplayin interfaceIQuery- Returns:
- a display representation of the current settings.
-
open
public void open()
Description copied from interface:IQueryOpens this query engine.
-
_query
protected <T> int _query(String queryText, T originalText, net.sf.okapi.connectors.microsoft.QueryResultBuilder<T> resultBuilder)
-
query
public int query(String plainText)
Description copied from interface:IQueryStarts a query for a give plain text.
-
query
public int query(TextFragment frag)
Description copied from interface:IQueryStarts a query for a given text.
-
_batchQuery
protected <T> List<List<QueryResult>> _batchQuery(List<String> texts, List<T> originalText, net.sf.okapi.connectors.microsoft.QueryResultBuilder<T> qrBuilder)
-
_subBatchQuery
protected <T> List<List<QueryResult>> _subBatchQuery(List<String> texts, List<T> originalText, net.sf.okapi.connectors.microsoft.QueryResultBuilder<T> qrBuilder)
-
leverage
public void leverage(ITextUnit tu)
Description copied from interface:IQueryLeverages 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:
leveragein interfaceIQuery- Overrides:
leveragein classBaseConnector- Parameters:
tu- the text unit to leverage.
-
batchLeverage
public void batchLeverage(List<ITextUnit> tuList)
Description copied from class:BaseConnectorSlow default implementation using leverage(TextUnit). Override in sub-class if you want a custom batchLeverage- Specified by:
batchLeveragein interfaceIQuery- Overrides:
batchLeveragein classBaseConnector- Parameters:
tuList- list of the text units to process.
-
batchQueryText
public List<List<QueryResult>> batchQueryText(List<String> plainTexts)
Description copied from interface:IQueryStarts 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:
batchQueryTextin interfaceIQuery- Overrides:
batchQueryTextin classBaseConnector- 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)
Description copied from class:BaseConnectorSlow default implementation using query!! Override to take advantage of servers batch API- Specified by:
batchQueryin interfaceIQuery- Overrides:
batchQueryin classBaseConnector- 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)
-
toInternalCode
protected String toInternalCode(LocaleId locale)
Description copied from class:BaseConnectorConverts 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:
toInternalCodein classBaseConnector- Parameters:
locale- the locale identifier to convert.- Returns:
- the internal string code for language/locale code for this connector.
-
getParameters
public Parameters getParameters()
Description copied from interface:IQueryGets the current parameters of this connector.- Specified by:
getParametersin interfaceIQuery- Overrides:
getParametersin classBaseConnector- Returns:
- the current parameters of this connector or null if no parameters are used.
-
setParameters
public void setParameters(IParameters params)
Description copied from interface:IQuerySets the parameters for opening and querying this connector.- Specified by:
setParametersin interfaceIQuery- Overrides:
setParametersin classBaseConnector- Parameters:
params- the parameters to set.
-
hasNext
public boolean hasNext()
Description copied from interface:IQueryIndicates of there is a hit available.- Specified by:
hasNextin interfaceIQuery- Specified by:
hasNextin interfaceIterator<QueryResult>- Overrides:
hasNextin classBaseConnector- Returns:
- True if a hit is available, false if not.
-
next
public QueryResult next()
Description copied from interface:IQueryGets the next hit for the last query.- Specified by:
nextin interfaceIQuery- Specified by:
nextin interfaceIterator<QueryResult>- Overrides:
nextin classBaseConnector- Returns:
- A QueryResult object that holds the source and target text of the hit, or null if there is no more hit.
-
getMaximumHits
public int getMaximumHits()
Description copied from interface:ITMQueryGets the current maximum number of hits to retrieve.- Specified by:
getMaximumHitsin interfaceITMQuery- Returns:
- the current maximum number of hits to retrieve.
-
setMaximumHits
public void setMaximumHits(int maximumHits)
Description copied from interface:ITMQuerySets the maximum number of hits to retrieve.- Specified by:
setMaximumHitsin interfaceITMQuery- Parameters:
maximumHits- The maximum number of hits to retrieve.
-
getThreshold
public int getThreshold()
Description copied from interface:ITMQueryGets the current threshold value to use for the query.- Specified by:
getThresholdin interfaceITMQuery- Returns:
- The current threshold value to use for the query.
-
setThreshold
public void setThreshold(int threshold)
Description copied from interface:ITMQuerySets the threshold value to use for the query.- Specified by:
setThresholdin interfaceITMQuery- Parameters:
threshold- The threshold value (between 0 and 100).
-
setLanguages
public void setLanguages(LocaleId sourceLocale, LocaleId targetLocale)
Description copied from interface:IQuerySets the source and target languages for this query engine.- Specified by:
setLanguagesin interfaceIQuery- Overrides:
setLanguagesin classBaseConnector- Parameters:
sourceLocale- Code of the source locale.targetLocale- Code of the target locale.
-
-