Package opennlp.tools.util.normalizer
Class LineBreakPreservingWhitespaceCharSequenceNormalizer
java.lang.Object
opennlp.tools.util.normalizer.LineBreakPreservingWhitespaceCharSequenceNormalizer
- All Implemented Interfaces:
Serializable,CharSequenceNormalizer,OffsetAwareNormalizer
public class LineBreakPreservingWhitespaceCharSequenceNormalizer
extends Object
implements OffsetAwareNormalizer
An
OffsetAwareNormalizer that collapses runs of Unicode whitespace like
WhitespaceCharSequenceNormalizer, but keeps line and paragraph structure: any whitespace
run that contains a line break collapses to a single newline (U+000A) instead of a space,
and leading and trailing whitespace is trimmed.
This is the form wanted for readable snippets and display: horizontal runs of spaces and tabs
become a single space, yet a blank line between paragraphs survives as one newline rather than
being flattened into the surrounding text. It reuses the cursor based
CharClass.collapsePreserving(CharSequence, CodePointSet, int) engine, so it recognizes the
full Unicode White_Space set.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final LineBreakPreservingWhitespaceCharSequenceNormalizerprivate static final CodePointSetprivate static final intprivate static final longprivate static final CharClass -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the shared, stateless instance.normalize(CharSequence text) Normalizes a sequence of characters.normalizeAligned(CharSequence text) Normalizestextand returns the result together with theAlignmentback to the input.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
NEWLINE
private static final int NEWLINE- See Also:
-
WHITESPACE
-
LINE_BREAKS
-
INSTANCE
-
-
Constructor Details
-
LineBreakPreservingWhitespaceCharSequenceNormalizer
public LineBreakPreservingWhitespaceCharSequenceNormalizer()
-
-
Method Details
-
getInstance
Returns the shared, stateless instance.- Returns:
- the shared, stateless instance
-
normalize
Normalizes a sequence of characters.- Specified by:
normalizein interfaceCharSequenceNormalizer- Parameters:
text- TheCharSequenceto normalize. Must not benull.- Returns:
- The normalized
CharSequence.
-
normalizeAligned
Normalizestextand returns the result together with theAlignmentback to the input. The normalized text is identical toCharSequenceNormalizer.normalize(CharSequence): that is,normalizeAligned(text).normalized()equalsnormalize(text).toString().- Specified by:
normalizeAlignedin interfaceOffsetAwareNormalizer- Parameters:
text- TheCharSequenceto normalize.- Returns:
- The normalized text paired with its alignment to
text.
-