Package opennlp.tools.util.normalizer
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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AlignmentThe field for thealignmentrecord component.private final CharSequenceThe field for thenormalizedrecord component.private final CharSequenceThe field for theoriginalrecord component. -
Constructor Summary
ConstructorsConstructorDescriptionAlignedText(CharSequence original, CharSequence normalized, Alignment alignment) Validates the components. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thealignmentrecord component.andThen(AlignedText next) Composes this result with a stage that further normalizes this result's normalized text.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.Returns the value of thenormalizedrecord component.Returns the normalized text as aString, that isnormalized().toString().original()Returns the value of theoriginalrecord component.toNormalizedSpan(int originalStart, int originalEnd) Maps a span of the original text forward to the normalized text.toOriginalSpan(int normalizedStart, int normalizedEnd) Maps a span of the normalized text back to the tightest span of the original text.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
original
The field for theoriginalrecord component. -
normalized
The field for thenormalizedrecord component. -
alignment
The field for thealignmentrecord component.
-
-
Constructor Details
-
AlignedText
Validates the components.- Throws:
IllegalArgumentException- Thrown if a component isnull, or if the lengths oforiginalandnormalizeddo not match the lengths ofalignment.
-
-
Method Details
-
normalizedString
Returns the normalized text as aString, that isnormalized().toString().- Returns:
- The normalized text as an immutable
String.
-
andThen
Composes this result with a stage that further normalizes this result's normalized text.If this maps
original -> middleandnextmapsmiddle -> final, the result keeps thisoriginal(), takes thenormalized()text ofnext, and maps between them withAlignment.andThen(Alignment).- Parameters:
next- The next stage, produced from this result's normalized text. Must not benull.- Returns:
- The composed result.
- Throws:
IllegalArgumentException- Thrown ifnextisnull, or if its alignment's original length does not equal this alignment's normalized length.
-
toOriginalSpan
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
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
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
original
Returns the value of theoriginalrecord component.- Returns:
- the value of the
originalrecord component
-
normalized
Returns the value of thenormalizedrecord component.- Returns:
- the value of the
normalizedrecord component
-
alignment
Returns the value of thealignmentrecord component.- Returns:
- the value of the
alignmentrecord component
-