Record Class AlignedText

java.lang.Object
java.lang.Record
opennlp.tools.util.normalizer.AlignedText
Record Components:
original - The untouched source text.
normalized - The normalized text.
alignment - The alignment between the normalized and original text.

public record AlignedText(CharSequence original, CharSequence normalized, Alignment alignment) extends Record
The result of a normalization that keeps the original text alongside the normalized form and a full Alignment between them.

The original is the source of truth, the normalized form is the derived view tuned for matching and search, and the alignment maps spans between them through deletions, collapses, and expansions. Use toOriginalSpan(int, int) to report a match found in the normalized form against the original.

Since:
3.0.0
  • Constructor Details

  • Method Details

    • normalizedString

      public String normalizedString()
      Returns the normalized text as a String, that is normalized().toString().
      Returns:
      The normalized text as an immutable String.
    • andThen

      public AlignedText andThen(AlignedText next)
      Composes this result with a stage that further normalizes this result's normalized text.

      If this maps original -> middle and next maps middle -> final, the result keeps this original(), takes the normalized() text of next, and maps between them with Alignment.andThen(Alignment).

      Parameters:
      next - The next stage, produced from this result's normalized text. Must not be null.
      Returns:
      The composed result.
      Throws:
      IllegalArgumentException - Thrown if next is null, or if its alignment's original length does not equal this alignment's normalized length.
    • toOriginalSpan

      public Span toOriginalSpan(int normalizedStart, int normalizedEnd)
      Maps a span of the normalized text back to the tightest span of the original text.
      Parameters:
      normalizedStart - The inclusive start offset in the normalized text.
      normalizedEnd - The exclusive end offset in the normalized text.
      Returns:
      The corresponding original span.
    • toNormalizedSpan

      public Span toNormalizedSpan(int originalStart, int originalEnd)
      Maps a span of the original text forward to the normalized text.
      Parameters:
      originalStart - The inclusive start offset in the original text.
      originalEnd - The exclusive end offset in the original text.
      Returns:
      The corresponding normalized span.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • original

      public CharSequence original()
      Returns the value of the original record component.
      Returns:
      the value of the original record component
    • normalized

      public CharSequence normalized()
      Returns the value of the normalized record component.
      Returns:
      the value of the normalized record component
    • alignment

      public Alignment alignment()
      Returns the value of the alignment record component.
      Returns:
      the value of the alignment record component