Class EmojiCharSequenceNormalizer
- All Implemented Interfaces:
Serializable,CharSequenceNormalizer
CharSequenceNormalizer implementation that replaces each run of complete emoji with
one space.
An emoji is a fully-qualified or minimally-qualified sequence of Unicode Emoji 18.0 in the
sense of UTS #51: a single emoji, an emoji
with U+FE0F, a flag, a keycap, a skin tone modifier sequence, a ZWJ sequence or a tag
sequence, as listed in emoji-test.txt. A minimally-qualified ZWJ sequence lacks U+FE0F
after a later element only, such as a woman raising hand written without U+FE0F after
U+2640. Adjacent emoji form one run and become one space; one redundant U+FE0F right after an
emoji is removed with it. Everything else is kept: a symbol with text presentation such as
U+2764 without U+FE0F, an unqualified sequence starting with such a symbol, letters and
ideographs from other planes,
private use characters, unpaired surrogates, and an emoji with a stray joiner, modifier,
selector, flag letter or tag next to it, which is kept as a whole instead of leaving a
fragment behind.
Since 3.0.0 only complete emoji sequences are removed. Under
CompatibilityMode.LEGACY the earlier output is produced for language detector models
trained with it: each maximal run of ASCII hyphens, characters from U+E000 to U+FFFF (private
use characters, CJK compatibility ideographs, Arabic and Hebrew presentation forms, fullwidth
and halfwidth forms, variation selectors), supplementary characters up to U+10FC00 whether
they are emoji or not, and unpaired surrogates from U+D83C on becomes one space, while emoji
in the Basic Multilingual Plane such as U+231A are kept.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intThe hyphen removed underCompatibilityMode.LEGACY.private static final EmojiCharSequenceNormalizerprivate static final intThe first code point of the range removed underCompatibilityMode.LEGACY: the high surrogate U+D83C.private static final intThe last code point of the range removed underCompatibilityMode.LEGACY.private static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic EmojiCharSequenceNormalizerReturns the shared, stateless instance.private booleanisLegacyMember(int codePoint) Returns whethercodePointis removed underCompatibilityMode.LEGACY.private intlegacyRunEnd(CharSequence text, int from) Returns the exclusive end of the run of legacy set members that starts atfrom.normalize(CharSequence text) Normalizes a sequence of characters.private ObjectReturns the shared instance, so deserialization keeps the singleton.private CharSequenceremoveLegacyRuns(CharSequence text) Replaces each maximal run of code points of the legacy set with one space.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
LEGACY_RANGE_FIRST
private static final int LEGACY_RANGE_FIRSTThe first code point of the range removed underCompatibilityMode.LEGACY: the high surrogate U+D83C. Before 3.0.0 this class used the regex[?--?]+, whose character class Java reads as U+D83C to U+10FC00 (the adjacent escapesform one supplementary code point), plus a literal hyphen and U+DFFF.- See Also:
-
LEGACY_RANGE_LAST
private static final int LEGACY_RANGE_LASTThe last code point of the range removed underCompatibilityMode.LEGACY.- See Also:
-
HYPHEN
private static final int HYPHENThe hyphen removed underCompatibilityMode.LEGACY.- See Also:
-
INSTANCE
-
-
Constructor Details
-
EmojiCharSequenceNormalizer
public EmojiCharSequenceNormalizer()
-
-
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.
-
removeLegacyRuns
Replaces each maximal run of code points of the legacy set with one space.- Parameters:
text- The text to scan; never null.- Returns:
- The input itself when nothing matched, otherwise the normalized copy.
-
legacyRunEnd
Returns the exclusive end of the run of legacy set members that starts atfrom.- Parameters:
text- The text to scan; never null.from- The index to scan from.- Returns:
- the exclusive end of the run of legacy set members that starts at
from
-
isLegacyMember
private boolean isLegacyMember(int codePoint) Returns whethercodePointis removed underCompatibilityMode.LEGACY. An unpaired surrogate is passed as its own value, the wayCharacter.codePointAt(CharSequence, int)reads it.- Parameters:
codePoint- The code point to test.- Returns:
- whether
codePointis removed underCompatibilityMode.LEGACY
-
readResolve
Returns the shared instance, so deserialization keeps the singleton.- Returns:
- the shared instance, so deserialization keeps the singleton
-