Class Alignment.Builder

java.lang.Object
opennlp.tools.util.normalizer.Alignment.Builder
Enclosing class:
Alignment

public static final class Alignment.Builder extends Object
Builds an Alignment as the normalized text is produced, by recording each edit in order. Call equal(int) for characters copied through unchanged and replace(int, int) for a block that was rewritten (including deletions and insertions), then build(int).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a builder with a small default capacity of DEFAULT_CAPACITY entries.
    Builder(int expectedLength)
    Creates a builder pre-sized for a normalized text of about expectedLength characters, so recording the edits of a typical pass (one entry per normalized character) does not regrow the backing arrays.
  • Method Summary

    Modifier and Type
    Method
    Description
    build(int originalLength)
    Finalizes the alignment.
    equal(int charCount)
    Records charCount characters copied through unchanged (a one to one run).
    replace(int originalCount, int normalizedCount)
    Records a rewritten block: originalCount original characters that produced normalizedCount normalized characters.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Builder

      public Builder()
      Creates a builder with a small default capacity of DEFAULT_CAPACITY entries.
    • Builder

      public Builder(int expectedLength)
      Creates a builder pre-sized for a normalized text of about expectedLength characters, so recording the edits of a typical pass (one entry per normalized character) does not regrow the backing arrays. The value is a sizing hint only; it does not limit how many edits can be recorded.
      Parameters:
      expectedLength - The expected normalized length, typically the length of the text being normalized; must not be negative.
      Throws:
      IllegalArgumentException - Thrown if expectedLength is negative.
  • Method Details

    • equal

      public Alignment.Builder equal(int charCount)
      Records charCount characters copied through unchanged (a one to one run).
      Parameters:
      charCount - The number of UTF-16 characters; must not be negative.
      Returns:
      This builder.
      Throws:
      IllegalArgumentException - Thrown if charCount is negative.
    • replace

      public Alignment.Builder replace(int originalCount, int normalizedCount)
      Records a rewritten block: originalCount original characters that produced normalizedCount normalized characters. Each produced character is attributed to the whole original block, since a collapse or expansion cannot be subdivided. 0 for normalizedCount is a deletion; 0 for originalCount is an insertion.
      Parameters:
      originalCount - The number of original characters consumed; must not be negative.
      normalizedCount - The number of normalized characters produced; must not be negative.
      Returns:
      This builder.
      Throws:
      IllegalArgumentException - Thrown if originalCount or normalizedCount is negative.
    • build

      public Alignment build(int originalLength)
      Finalizes the alignment.
      Parameters:
      originalLength - The full length of the original text.
      Returns:
      The immutable Alignment.
      Throws:
      IllegalStateException - Thrown if the recorded edits do not consume exactly originalLength original characters (a sign that some input was not accounted for).