Package opennlp.tools.util.normalizer
Class ParagraphPreservingWhitespaceCharSequenceNormalizer
java.lang.Object
opennlp.tools.util.normalizer.ParagraphPreservingWhitespaceCharSequenceNormalizer
- All Implemented Interfaces:
Serializable,CharSequenceNormalizer,OffsetAwareNormalizer
public class ParagraphPreservingWhitespaceCharSequenceNormalizer
extends Object
implements OffsetAwareNormalizer
An
OffsetAwareNormalizer that unwraps hard-wrapped prose while keeping real paragraph
breaks. Within each whitespace run, at most one logical line break (including CRLF as a
single break) collapses to a single space; two or more collapse to one newline
(U+000A). Leading and trailing whitespace is trimmed.
This is the form wanted before sentence detection on Gutenberg-style or other fixed-width
plain text: intra-paragraph line wraps become spaces, blank-line paragraph boundaries survive as
newlines. It reuses the cursor based CharClass.collapseParagraphPreserving(CharSequence, CodePointSet, int) engine, so it recognizes the full Unicode White_Space set.
For display-oriented text where every line break should survive, use
LineBreakPreservingWhitespaceCharSequenceNormalizer instead. For raw markdown with lists,
code blocks, or other single-newline structure, apply this normalizer only to extracted prose.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ParagraphPreservingWhitespaceCharSequenceNormalizerprivate 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.private Object
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
NEWLINE
private static final int NEWLINE- See Also:
-
WHITESPACE
-
LINE_BREAKS
-
INSTANCE
-
-
Constructor Details
-
ParagraphPreservingWhitespaceCharSequenceNormalizer
public ParagraphPreservingWhitespaceCharSequenceNormalizer()
-
-
Method Details
-
getInstance
Returns the shared, stateless instance.- Returns:
- the shared, stateless instance
-
readResolve
-
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.
-