net.sf.okapi.common.annotation

## Class AltTranslationsAnnotation

- java.lang.Object
- - net.sf.okapi.common.annotation.AltTranslationsAnnotation

- All Implemented Interfaces:
    java.lang.Iterable<AltTranslation>, IAnnotation

      public class AltTranslationsAnnotation
      extends java.lang.Object
      implements IAnnotation, java.lang.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 and Description
    `AltTranslationsAnnotation()` Creates a new empty AltTranslationsAnnotation object.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(AltTranslation alt)` Adds an existing `AltTranslation` object to this annotation.
    `AltTranslation` | `add(LocaleId sourceLocId, LocaleId targetLocId, TextFragment originalSource, TextFragment alternateSource, TextFragment alternateTarget, MatchType type, int combinedScore, java.lang.String origin)` Adds a new entry to the list of alternate translations.
    `AltTranslation` | `add(LocaleId sourceLocId, LocaleId targetLocId, TextFragment originalSource, TextFragment alternateSource, TextFragment alternateTarget, MatchType type, int combinedScore, java.lang.String origin, int fuzzyScore, int qualityScore)` Adds a new entry to the list of alternate translations.
    `void` | `downgradeIdenticalBestMatches(boolean forceSort, int threshold)` Downgrades, and possibly removes, all the 100% best matches that are identical.
    `java.lang.String` | `getCurrentToolId()`
    `AltTranslation` | `getFirst()` Gets the first entry in the list of alternate translations.
    `AltTranslation` | `getLast()` Gets the last entry in the list of alternate translations.
    `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.
    `boolean` | `isEmpty()` Indicates if the list of alternate translation is empty.
    `java.util.Iterator<AltTranslation>` | `iterator()` Creates a new iterator for the entries in this annotations.
    `void` | `setCurrentToolId(java.lang.String toolId)`
    `int` | `size()` Gets the number of entries in this annotation.
    `void` | `sort()` Sorts the list of `AltTranslation`s in the order defined by `AltTranslation.compareTo(AltTranslation)`.
    `java.lang.String` | `toString()` 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`

- - ### Constructor Detail

    - #### AltTranslationsAnnotation

          public AltTranslationsAnnotation()

      Creates a new empty AltTranslationsAnnotation object.

  - ### Method Detail

    - #### add

          public void add(AltTranslation alt)

      Adds an existing `AltTranslation` object to this annotation.
      Parameters:
        `alt` - the `AltTranslation` object to add.

    - #### add

          public AltTranslation add(LocaleId sourceLocId,
                           LocaleId targetLocId,
                           TextFragment originalSource,
                           TextFragment alternateSource,
                           TextFragment alternateTarget,
                           MatchType type,
                           int combinedScore,
                           java.lang.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 `AltTranslation` object created and added to this annotation.

    - #### add

          public AltTranslation add(LocaleId sourceLocId,
                           LocaleId targetLocId,
                           TextFragment originalSource,
                           TextFragment alternateSource,
                           TextFragment alternateTarget,
                           MatchType type,
                           int combinedScore,
                           java.lang.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 source
        `qualityScore` - - optional quality score from the TM or MT engine
      Returns:
        the `AltTranslation` object created and added to this annotation.

    - #### iterator

          public java.util.Iterator<AltTranslation> iterator()

      Creates a new iterator for the entries in this annotations.
      Specified by:
        `iterator` in interface `java.lang.Iterable<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 of `AltTranslation`s in the order defined by `AltTranslation.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 java.lang.String getCurrentToolId()

    - #### setCurrentToolId

          public void setCurrentToolId(java.lang.String toolId)

    - #### toString

          public java.lang.String toString()

      Description copied from interface: `IAnnotation`
      Gets a human readable representation of this annotation.
      Specified by:
        `toString` in interface `IAnnotation`
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        a human readable representation of this annotation.