Package opennlp.tools.util.normalizer
Class ShrinkCharSequenceNormalizer
java.lang.Object
opennlp.tools.util.normalizer.ShrinkCharSequenceNormalizer
- All Implemented Interfaces:
Serializable,CharSequenceNormalizer
A
CharSequenceNormalizer implementation that shrinks repeated whitespace and repeated
characters in text, in three steps:
- Each run of two or more ASCII whitespace characters (tab, line feed, vertical tab, form feed, carriage return, or space) collapses to a single space. A lone whitespace character is kept as it is.
- Each run of three or more repeats of one code point shrinks to two copies of its first
occurrence, comparing repeats case-insensitively over ASCII; a run never starts on a
line terminator. For example,
"coooool"becomes"cool". - Every leading and trailing character at or below
U+0020is dropped, the same ruleString.trim()applies.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ShrinkCharSequenceNormalizerprivate static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ShrinkCharSequenceNormalizerReturns the shared, stateless instance.normalize(CharSequence text) Normalizes a sequence of characters.private CharSequenceShrinks each run of three or more repeats of one code point to two copies of its first occurrence.private CharSequenceshrinkWhitespace(CharSequence text) Replaces each run of two or more ASCII whitespace characters with a single space; a lone whitespace character stays as it is.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
INSTANCE
-
-
Constructor Details
-
ShrinkCharSequenceNormalizer
public ShrinkCharSequenceNormalizer()
-
-
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.
-
shrinkWhitespace
Replaces each run of two or more ASCII whitespace characters with a single space; a lone whitespace character stays as it is.- Parameters:
text- The text to scan; never null.- Returns:
- The input itself when no run was found, otherwise the shrunk copy.
-
shrinkRepeatedCodePoints
Shrinks each run of three or more repeats of one code point to two copies of its first occurrence. The run's first code point must not be a line terminator, every repeat advances by the first occurrence's char count while comparing whole code points ASCII case-insensitively, and a failed attempt resumes at the next char.- Parameters:
text- The text to scan; never null.- Returns:
- The input itself when no run was found, otherwise the shrunk copy.
-