Package opennlp.tools.util.normalizer
Class WhitespaceCharSequenceNormalizer
java.lang.Object
opennlp.tools.util.normalizer.WhitespaceCharSequenceNormalizer
- All Implemented Interfaces:
Serializable,CharSequenceNormalizer,OffsetAwareNormalizer
A
CharSequenceNormalizer that collapses each run of Unicode whitespace to a single ASCII
space and trims the edges, reusing the cursor based CharClass.whitespace() engine.
Unlike a \s regular expression, this recognizes the full Unicode White_Space
set (no-break space, ideographic space, the typographic spaces, line and paragraph separators,
and so on), so spacing copied from the web, PDFs, or non-Latin sources normalizes consistently.
It is the Unicode-aware counterpart to ShrinkCharSequenceNormalizer.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final WhitespaceCharSequenceNormalizerprivate 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:
-
WHITESPACE
-
INSTANCE
-
-
Constructor Details
-
WhitespaceCharSequenceNormalizer
public WhitespaceCharSequenceNormalizer()
-
-
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.
-