public class QueryManager extends Object implements Iterator<QueryResult>
| Constructor and Description |
|---|
QueryManager()
Creates a new QueryManager object.
|
| Modifier and Type | Method and Description |
|---|---|
int |
addAndInitializeResource(IQuery connector,
String resourceName,
IParameters params)
Adds a translation resource to the manager and initializes it with the
current source and target language of this manager, as well as any
attributes that is set, and the current threshold and maximum hits if it is relevant.
|
int |
addAndInitializeResource(String connectorClass,
String resourceName,
ClassLoader loader,
String connectorParams)
Creates a translation resource and its parameters from their class names,
adds it to the manager and initializes it with the
current source and target language of this manager, as well as any
attributes that is set, and the current threshold and maximum hits if it is relevant.
|
int |
addAndInitializeResource(String connectorClass,
String resourceName,
String connectorParams)
Creates a translation resource and its parameters from their class names,
adds it to the manager and initializes it with the
current source and target language of this manager, as well as any
attributes that is set, and the current threshold and maximum hits if it is relevant.
|
int |
addResource(IQuery connector,
String name)
Adds a translation resource to the manager.
|
static boolean |
canLeverage(Segment srcSeg,
Segment trgSeg,
boolean leverageIfTargetIsEmpty,
boolean leverageIfTargetIsSameAsSource)
Indicates if we can fill a given target segment with leveraged translation based on
whether it is empty and whether it is the same as the source segment.
|
static boolean |
canLeverage(TextContainer srcTc,
TextContainer trgTc,
boolean leverageIfTargetIsEmpty,
boolean leverageIfTargetIsSameAsSource)
Indicates if we can fill a given target TextContent with leveraged translation based on
whether it is empty and whether it is the same as the source TextContent.
|
void |
clearAttributes()
Removes all attributes from this manager and all the translation
resources in this manager.
|
void |
close()
Closes all translation resources in this manager.
|
int |
getExactBestMatches()
Gets the number of best matches that are exact (100%) since the last call to
resetCounters(). |
int |
getFuzzyBestMatches()
Gets the number of best matches that are fuzzy (less that 100%, more than 0%) since the last call
to
resetCounters(). |
IQuery |
getInterface(int resourceId)
Gets the IQuery interface for a given translation resource.
|
String |
getName(int resourceId)
Gets the name for a given translation resource.
|
ResourceItem |
getResource(int resourceId)
Gets the configuration data for a given translation resource.
|
Map<Integer,ResourceItem> |
getResources()
Gets the configuration data for all the translation resources in this manager.
|
List<QueryResult> |
getResults()
Gets the list of all hit results of the last query.
|
LocaleId |
getSourceLanguage()
Gets the current source locale for this manager.
|
LocaleId |
getTargetLanguage()
Gets the current target locale for this manager.
|
int |
getTotalSegments()
Gets the total number of segments processed since the last call to
resetCounters(). |
boolean |
hasNext()
Indicates of there is a hit available.
|
void |
leverage(ITextUnit tu)
Leverages a text unit (segmented or not) based on the current settings.
|
QueryResult |
next()
Gets the next hit for the last query.
|
int |
query(String plainText)
Queries all enabled translation resources for a given plain text.
|
int |
query(TextFragment text)
Queries all enabled translation resources for a given text fragment.
|
void |
remove(int resourceId)
Removes a given translation resource.
|
void |
removeAttribute(String name)
Removes a given attribute from this manager and all translation
resources in this manager.
|
void |
resetCounters()
Resets the counters used to calculate the number of segments leveraged.
|
void |
rewind()
Resets the current result to the first one if there is one.
|
void |
setAttribute(String name,
String value)
Sets an attribute for this manager and all translation resources in
this manager.
|
void |
setEnabled(int resourceId,
boolean enabled)
Enables or disables a given translation resource.
|
void |
setLanguages(LocaleId sourceLocale,
LocaleId targetLocale)
Sets the source and target locales for this manager and for all
translation resources in this manager.
|
void |
setMaximumHits(int max)
Sets the maximum number of hits to return for this query manager
and all the relevant translation resources it holds.
|
void |
setNoQueryThreshold(int noQueryThreshold)
Sets the no-query threshold for this query manager.
|
void |
setOptions(int thresholdToFill,
boolean fillIfTargetIsEmpty,
boolean fillIfTargetIsSameAsSource,
boolean downgradeIdenticalBestMatches,
String targetPrefix,
int thresholdToPrefix,
boolean copySourceOnNoText)
Sets the options for performing the leverage.
|
void |
setRootDirectory(String rootDir)
Sets the root directory for this query manager
and all translation resources it holds.
|
void |
setThreshold(int value)
Sets the threshold for this query manager and all the relevant
translation resources it holds.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEachRemaining, removepublic static boolean canLeverage(Segment srcSeg, Segment trgSeg, boolean leverageIfTargetIsEmpty, boolean leverageIfTargetIsSameAsSource)
srcSeg - the source segment.trgSeg - the target segment.leverageIfTargetIsEmpty - true if we leverage only if the target is empty.leverageIfTargetIsSameAsSource - true if we leverage if the target is not empty but is the same as the source.public static boolean canLeverage(TextContainer srcTc, TextContainer trgTc, boolean leverageIfTargetIsEmpty, boolean leverageIfTargetIsSameAsSource)
srcTc - the source TextContent.trgTc - the target TextContent.leverageIfTargetIsEmpty - true if we leverage only if the target is empty.leverageIfTargetIsSameAsSource - true if we leverage if the target is not empty but is the same as the source.public int addResource(IQuery connector, String name)
connector - The translation resource connector to add.name - Name of the translation resource to add.public int addAndInitializeResource(IQuery connector, String resourceName, IParameters params)
connector - The translation resource connector to add.resourceName - Name of the translation resource to add.params - the parameters for this connector.RuntimeException - if an error occurs.public int addAndInitializeResource(String connectorClass, String resourceName, String connectorParams)
connectorClass - the name of the class for the connector.resourceName - the name of the translation resource (can be null).connectorParams - connector parameters stored in a string.RuntimeException - if an error occurs.public int addAndInitializeResource(String connectorClass, String resourceName, ClassLoader loader, String connectorParams)
connectorClass - the name of the class for the connector.resourceName - the name of the translation resource (can be null).loader - class loader from which the connector class must be loadedconnectorParams - connector parameters stored in a string.RuntimeException - if an error occurs.public void setEnabled(int resourceId,
boolean enabled)
resourceId - ID of the translation resource to enable or disable.enabled - True to enable the resource, false to disable it.public void remove(int resourceId)
resourceId - ID of the translation resource to remove.public IQuery getInterface(int resourceId)
resourceId - ID of the translation resource to lookup.public ResourceItem getResource(int resourceId)
resourceId - ID of the translation resource to lookup.public String getName(int resourceId)
resourceId - ID of the translation resource to lookup.public Map<Integer,ResourceItem> getResources()
public void close()
public List<QueryResult> getResults()
public void rewind()
public boolean hasNext()
hasNext in interface Iterator<QueryResult>public QueryResult next()
next in interface Iterator<QueryResult>public int query(String plainText)
plainText - The text to query.public int query(TextFragment text)
text - The text to query.public void setAttribute(String name, String value)
name - name of the attribute.value - Value of the attribute.public void removeAttribute(String name)
name - The name of the attribute to remove.public void clearAttributes()
public void setLanguages(LocaleId sourceLocale, LocaleId targetLocale)
sourceLocale - Code of the source locale to set.targetLocale - Code of the target locale to set.public LocaleId getSourceLanguage()
public LocaleId getTargetLanguage()
public void setThreshold(int value)
value - the threshold value to set.public void setMaximumHits(int max)
max - the maximum value to set.public void setRootDirectory(String rootDir)
rootDir - the root directory.public void setNoQueryThreshold(int noQueryThreshold)
noQueryThreshold - the value of the no-query threshold (between 0 and 101).
Use 101 to always allow the query.public void setOptions(int thresholdToFill,
boolean fillIfTargetIsEmpty,
boolean fillIfTargetIsSameAsSource,
boolean downgradeIdenticalBestMatches,
String targetPrefix,
int thresholdToPrefix,
boolean copySourceOnNoText)
thresholdToFill - if the first match has a score equal or above this value,
the target text of the match is placed in the target content. To avoid any filling of
the target: simply use a high value (e.g. Integer.MAX_VALUE).fillIfTargetIsEmpty - true to fill the target only if its content is currently empty.fillIfTargetIsSameAsSource - true to fill the target if fillIfTargetIsEmpty is true and
the source and target content are the same.downgradeIdenticalBestMatches - true to reduce the score of best matches when
they are identical.targetPrefix - A prefix to place at the front of the candidate target if it is
leveraged into the text unit. Use null to not set a prefix.thresholdToPrefix - if a target prefix is defined and the score is equal or below this
threshold the prefix is added. This parameter is ignored if the target prefix is null.copySourceOnNoText - true to copy the source content for the target segments that have
no text (but they may have codes and/or white spaces).public void leverage(ITextUnit tu)
tu - the text unit to leverage.setAttribute(String, String),
setLanguages(LocaleId, LocaleId),
setMaximumHits(int),
setNoQueryThreshold(int),
setOptions(int, boolean, boolean, boolean, String, int, boolean),
setRootDirectory(String),
setThreshold(int)public void resetCounters()
getExactBestMatches(),
getTotalSegments()public int getTotalSegments()
resetCounters().public int getExactBestMatches()
resetCounters().public int getFuzzyBestMatches()
resetCounters().Copyright © 2021. All rights reserved.