Package net.sf.okapi.common.query
Interface IQuery
-
- All Superinterfaces:
AutoCloseable,Iterator<QueryResult>
- All Known Subinterfaces:
ITMQuery
- All Known Implementing Classes:
ApertiumMTConnector,BaseConnector,BilingualFileConnector,GoogleAutoMLTranslationConnector,GoogleMTv2Connector,KantanMTConnector,KantanMTv21Connector,Lingo24Connector,MicrosoftMTConnector,MMTConnector,MyMemoryTMConnector,PensieveTMConnector,TDASearchConnector,TranslateToolkitTMConnector
public interface IQuery extends AutoCloseable, Iterator<QueryResult>
Provides the methods common to all query engines of translation resources that can be queried for translating text units.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidbatchLeverage(List<ITextUnit> tus)Leverages a batch of text units (segmented or not) based on the current settings.List<List<QueryResult>>batchQuery(List<TextFragment> fragments)Starts a batch query for a given list ofTextFragments.List<List<QueryResult>>batchQueryText(List<String> plainTexts)Starts a batch query for a given list of plain texts.voidclearAttributes()Removes all attributes from this query engine.voidclose()Closes this connector.StringgetName()Gets the name of the connector.intgetNoQueryThreshold()Gets the threshold for when to avoid a query.IParametersgetParameters()Gets the current parameters of this connector.StringgetSettingsDisplay()Gets a display representation of the current settings for this connector.LocaleIdgetSourceLanguage()Gets the current source language for this query engine.LocaleIdgetTargetLanguage()Gets the current target language for this query engine.intgetWeight()Get the weight for this connector.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 text)Starts a query for a given text.voidremoveAttribute(String name)Removes a given attribute from this query engine.voidsetAttribute(String name, String value)Sets an attribute for this query engine.voidsetLanguages(LocaleId sourceLocale, LocaleId targetLocale)Sets the source and target languages for this query engine.voidsetNoQueryThreshold(int noQueryThreshold)Sets the threshold for when to avoid executing a query.voidsetParameters(IParameters params)Sets the parameters for opening and querying this connector.voidsetRootDirectory(String rootDir)Sets the root directory that may be used to replace the available ${rootDir} in the parameters of this object.voidsetWeight(int weight)Set the relative weight of thisIQueryconnector as compared to other connectors.-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Method Detail
-
getName
String getName()
Gets the name of the connector.- Returns:
- the name of the connector.
-
getSettingsDisplay
String getSettingsDisplay()
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.
-
setLanguages
void setLanguages(LocaleId sourceLocale, LocaleId targetLocale)
Sets the source and target languages for this query engine.- Parameters:
sourceLocale- Code of the source locale.targetLocale- Code of the target locale.
-
getSourceLanguage
LocaleId getSourceLanguage()
Gets the current source language for this query engine.- Returns:
- Code of the source language.
-
getTargetLanguage
LocaleId getTargetLanguage()
Gets the current target language for this query engine.- Returns:
- Code of the target language.
-
setAttribute
void setAttribute(String name, String value)
Sets an attribute for this query engine.- Parameters:
name- name of the attribute.value- Value of the attribute.
-
removeAttribute
void removeAttribute(String name)
Removes a given attribute from this query engine.- Parameters:
name- The name of the attribute to remove.
-
clearAttributes
void clearAttributes()
Removes all attributes from this query engine.
-
setParameters
void setParameters(IParameters params)
Sets the parameters for opening and querying this connector.- Parameters:
params- the parameters to set.
-
getParameters
IParameters getParameters()
Gets the current parameters of this connector.- Returns:
- the current parameters of this connector or null if no parameters are used.
-
open
void open()
Opens this query engine.
-
close
void close()
Closes this connector.- Specified by:
closein interfaceAutoCloseable
-
query
int query(String plainText)
Starts a query for a give plain text.- Parameters:
plainText- text to query.- Returns:
- The number of hits for the given query.
-
query
int query(TextFragment text)
Starts a query for a given text.- Parameters:
text- The text to query.- Returns:
- The number of hits for the given query.
-
leverage
void leverage(ITextUnit tu)
Leverages a text unit (segmented or not) based on the current settings. Any options or attributes needed must be set before calling this method.- Parameters:
tu- the text unit to leverage.
-
batchLeverage
void batchLeverage(List<ITextUnit> tus)
Leverages a batch of text units (segmented or not) based on the current settings. Any options or attributes needed must be set before calling this method.- Parameters:
tus- of the text unit to leverage.
-
batchQueryText
List<List<QueryResult>> batchQueryText(List<String> plainTexts)
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.- 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
List<List<QueryResult>> batchQuery(List<TextFragment> fragments)
Starts a batch query for a given list ofTextFragments. SomeIQueryimplementations are significantly faster when a using batch query.
Note that batchQuery does not use hasNext and next methods. Callers must use the returned list directly.- 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)
-
hasNext
boolean hasNext()
Indicates of there is a hit available.- Specified by:
hasNextin interfaceIterator<QueryResult>- Returns:
- True if a hit is available, false if not.
-
next
QueryResult next()
Gets the next hit for the last query.- Specified by:
nextin interfaceIterator<QueryResult>- Returns:
- A QueryResult object that holds the source and target text of the hit, or null if there is no more hit.
-
setRootDirectory
void setRootDirectory(String rootDir)
Sets the root directory that may be used to replace the available ${rootDir} in the parameters of this object.- Parameters:
rootDir- the root directory.
-
setWeight
void setWeight(int weight)
Set the relative weight of thisIQueryconnector as compared to other connectors. Used to setQueryResult.weight.- Parameters:
weight- the new relative weight.
-
getWeight
int getWeight()
Get the weight for this connector.- Returns:
- the weight for this connector
-
setNoQueryThreshold
void setNoQueryThreshold(int noQueryThreshold)
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.
- Parameters:
noQueryThreshold- no-query threshold (a value between 0 and 101).
-
getNoQueryThreshold
int getNoQueryThreshold()
Gets the threshold for when to avoid a query.- Returns:
- the current no-query threshold.
-
-