Package net.sf.okapi.common.annotation
Class AltTranslationsAnnotation
- java.lang.Object
-
- net.sf.okapi.common.annotation.AltTranslationsAnnotation
-
- All Implemented Interfaces:
Cloneable,Iterable<AltTranslation>,IAnnotation
public class AltTranslationsAnnotation extends Object implements IAnnotation, Iterable<AltTranslation>
Annotation for storing one or more alternate translations for a target content.When used, this annotation is designed to be attached to the segments or the container of the targets.
-
-
Constructor Summary
Constructors Constructor Description AltTranslationsAnnotation()Creates a new empty AltTranslationsAnnotation object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(AltTranslation alt)Adds an existingAltTranslationobject to this annotation.AltTranslationadd(LocaleId sourceLocId, LocaleId targetLocId, TextFragment originalSource, TextFragment alternateSource, TextFragment alternateTarget, MatchType type, int combinedScore, String origin)Adds a new entry to the list of alternate translations.AltTranslationadd(LocaleId sourceLocId, LocaleId targetLocId, TextFragment originalSource, TextFragment alternateSource, TextFragment alternateTarget, MatchType type, int combinedScore, String origin, int fuzzyScore, int qualityScore)Adds a new entry to the list of alternate translations.voiddowngradeIdenticalBestMatches(boolean forceSort, int threshold)Downgrades, and possibly removes, all the 100% best matches that are identical.StringgetCurrentToolId()AltTranslationgetFirst()Gets the first entry in the list of alternate translations.AltTranslationgetLast()Gets the last entry in the list of alternate translations.booleanhasSeveralBestMatches(boolean forceSort)Indicates if a) there are several matches of 100% with identical rank and at least two of them have different translations.booleanisEmpty()Indicates if the list of alternate translation is empty.Iterator<AltTranslation>iterator()Creates a new iterator for the entries in this annotations.voidsetCurrentToolId(String toolId)intsize()Gets the number of entries in this annotation.voidsort()Sorts the list ofAltTranslations in the order defined byAltTranslation.compareTo(AltTranslation).StringtoString()Gets a human readable representation of this annotation.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
add
public void add(AltTranslation alt)
Adds an existingAltTranslationobject to this annotation.- Parameters:
alt- theAltTranslationobject to add.
-
add
public AltTranslation add(LocaleId sourceLocId, LocaleId targetLocId, TextFragment originalSource, TextFragment alternateSource, TextFragment alternateTarget, MatchType type, int combinedScore, String origin)
Adds a new entry to the list of alternate translations.- Parameters:
sourceLocId- the locale of the source.targetLocId- the locale of the target.originalSource- the original source content.alternateSource- the source content corresponding to the alternate translation.alternateTarget- the content of alternate translation.type- the type of alternate translation.combinedScore- the combined score for this alternate translation (must be between 0 and 100).origin- an optional identifier for the origin of this alternate translation.- Returns:
- the
AltTranslationobject created and added to this annotation.
-
add
public AltTranslation add(LocaleId sourceLocId, LocaleId targetLocId, TextFragment originalSource, TextFragment alternateSource, TextFragment alternateTarget, MatchType type, int combinedScore, String origin, int fuzzyScore, int qualityScore)
Adds a new entry to the list of alternate translations.- Parameters:
sourceLocId- the locale of the source.targetLocId- the locale of the target.originalSource- the original source content.alternateSource- the source content corresponding to the alternate translation.alternateTarget- the content of alternate translation.type- the type of alternate translation.combinedScore- the combined score for this alternate translation (must be between 0 and 100).origin- an optional identifier for the origin of this alternate translation.fuzzyScore- - fuzzy score (string distance) between the original source and alternate translation sourcequalityScore- - optional quality score from the TM or MT engine- Returns:
- the
AltTranslationobject created and added to this annotation.
-
iterator
public Iterator<AltTranslation> iterator()
Creates a new iterator for the entries in this annotations.- Specified by:
iteratorin interfaceIterable<AltTranslation>- Returns:
- a new iterator for the entries in this annotations.
-
getFirst
public AltTranslation getFirst()
Gets the first entry in the list of alternate translations.- Returns:
- the first alternate translation entry or null if the list is empty.
-
getLast
public AltTranslation getLast()
Gets the last entry in the list of alternate translations.- Returns:
- the last alternate translation entry or null if the list is empty.
-
isEmpty
public boolean isEmpty()
Indicates if the list of alternate translation is empty.- Returns:
- true if the list is empty.
-
size
public int size()
Gets the number of entries in this annotation.- Returns:
- the number of alternate translations available.
-
sort
public void sort()
Sorts the list ofAltTranslations in the order defined byAltTranslation.compareTo(AltTranslation).
-
hasSeveralBestMatches
public boolean hasSeveralBestMatches(boolean forceSort)
Indicates if a) there are several matches of 100% with identical rank and at least two of them have different translations.- Parameters:
forceSort- true to force the entries to be sorted. If set to false, the code assumes the entries have been sorted already.- Returns:
- true if the conditions above are true.
-
downgradeIdenticalBestMatches
public void downgradeIdenticalBestMatches(boolean forceSort, int threshold)Downgrades, and possibly removes, all the 100% best matches that are identical.A set of matches may have entries that have the same source but different targets, they are not duplicated. Some callers may need to treat exact matches like that as fuzzy matches to avoid triggering automated processes.
This methods examine the set of alternate translations here and downgrade by 1% the score of any top entry fall into that category.
- Parameters:
forceSort- true to re-sort the annotations. If you set this option to false the entries are expected to be already properly sorted to have the best matches first.threshold- threshold under which the matches should be removed.
-
getCurrentToolId
public String getCurrentToolId()
-
setCurrentToolId
public void setCurrentToolId(String toolId)
-
toString
public String toString()
Description copied from interface:IAnnotationGets a human readable representation of this annotation.- Specified by:
toStringin interfaceIAnnotation- Overrides:
toStringin classObject- Returns:
- a human readable representation of this annotation.
-
-