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.

  • Constructor Details

    • AlignedText

      public AlignedText(CharSequence original, CharSequence normalized, Alignment alignment)
      Creates an instance of a AlignedText record class.
      Parameters:
      original - the value for the original record component
      normalized - the value for the normalized record component
      alignment - the value for the alignment record component
  • Method Details

    • normalizedString

      public String normalizedString()
      Returns the normalized text as a String.

      This is the materialized result of the normalization. All implementations build the normalized form via a StringBuilder and call toString(), so this is a cheap conversion that does not allocate a new buffer.

      Returns:
      The normalized text as an immutable String.
    • 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