Package net.sf.okapi.connectors.google
Class GoogleMTv2Connector
- java.lang.Object
-
- net.sf.okapi.lib.translation.BaseConnector
-
- net.sf.okapi.connectors.google.GoogleMTv2Connector
-
- All Implemented Interfaces:
AutoCloseable,Iterator<QueryResult>,IQuery
public class GoogleMTv2Connector extends BaseConnector
-
-
Constructor Summary
Constructors Constructor Description GoogleMTv2Connector()GoogleMTv2Connector(GoogleMTAPI api)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> List<List<QueryResult>>_batchQuery(List<String> texts, List<T> originalTexts, net.sf.okapi.connectors.google.QueryResultBuilder<T> qrBuilder)protected <T> int_query(String queryText, T originalText, net.sf.okapi.connectors.google.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.protected LocaleIdconvertGoogleLanguageCode(String lang)protected <T> List<TranslationResponse>executeQuery(GoogleQueryBuilder<T> qb, net.sf.okapi.connectors.google.QueryResultBuilder<T> qrBuilder)protected <T> TranslationResponseexecuteSingleSegmentQuery(GoogleQueryBuilder<T> qb, String sourceText)protected <T> List<List<QueryResult>>flushQuery(GoogleQueryBuilder<T> qb, net.sf.okapi.connectors.google.QueryResultBuilder<T> qrBuilder)StringgetName()Gets the name of the connector.GoogleMTv2ParametersgetParameters()Gets the current parameters of this connector.StringgetSettingsDisplay()Gets a display representation of the current settings for this connector.List<LocaleId>getSupportedLanguages()voidleverage(ITextUnit tu)Leverages a text unit (segmented or not) based on the current settings.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.voidsetParameters(IParameters params)Sets the parameters for opening and querying this connector.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, hasNext, leverageUsingBatchQuery, next, removeAttribute, setAttribute, setLanguages, 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 java.util.Iterator
forEachRemaining, remove
-
-
-
-
Constructor Detail
-
GoogleMTv2Connector
public GoogleMTv2Connector()
-
GoogleMTv2Connector
public GoogleMTv2Connector(GoogleMTAPI api)
-
-
Method Detail
-
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.
-
getParameters
public GoogleMTv2Parameters 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.
-
close
public void close()
Description copied from interface:IQueryCloses this connector.
-
getName
public String getName()
Description copied from interface:IQueryGets the name of the connector.- Returns:
- 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.- Returns:
- a display representation of the current settings.
-
open
public void open()
Description copied from interface:IQueryOpens this query engine.
-
query
public int query(String plainText)
Description copied from interface:IQueryStarts 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 frag)
Description copied from interface:IQueryStarts a query for a given text.- Parameters:
frag- The text to query.- Returns:
- The number of hits for the given query.
-
_query
protected <T> int _query(String queryText, T originalText, net.sf.okapi.connectors.google.QueryResultBuilder<T> qrBuilder)
-
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)
-
_batchQuery
protected <T> List<List<QueryResult>> _batchQuery(List<String> texts, List<T> originalTexts, net.sf.okapi.connectors.google.QueryResultBuilder<T> qrBuilder)
-
flushQuery
protected <T> List<List<QueryResult>> flushQuery(GoogleQueryBuilder<T> qb, net.sf.okapi.connectors.google.QueryResultBuilder<T> qrBuilder)
-
executeSingleSegmentQuery
protected <T> TranslationResponse executeSingleSegmentQuery(GoogleQueryBuilder<T> qb, String sourceText)
-
executeQuery
protected <T> List<TranslationResponse> executeQuery(GoogleQueryBuilder<T> qb, net.sf.okapi.connectors.google.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.
-
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.
-
-