Package opennlp.tools.util.normalizer
Class EmojiAnnotator
java.lang.Object
opennlp.tools.util.normalizer.EmojiAnnotator
Assembles one
EmojiAnnotation per symbol from bundled facts
(EmojiAnnotations), derived facts (EmojiFlags), and optional joined facts
(EmojiAnnotationJoin). annotate(Term) keys on Term.original();
non-emoji tokens and degenerate flag-shaped text return empty. Instances are immutable and
thread-safe when the join is.
Annotations are per-symbol metadata, not text transforms; a parallel surface beside
Term rather than Dimension constants.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final StringFeature-name prefix for the document-category hint, for exampleemojiCategory=SMILEYS_AND_EMOTION.private static final StringFeature-name prefix for a flag's ISO 3166 region, for exampleemojiRegion=DE.private static final StringFeature-name prefix for the coarse sentiment score, for exampleemojiSentiment=2.private static final StringFeature-name prefix for the coarse entity type, for exampleemojiType=HEART.private static final charprivate static final Stringprivate final EmojiAnnotationJoinprivate static final String -
Constructor Summary
ConstructorsConstructorDescriptionCreates an annotator over the bundled and derived layers only.Creates an annotator that also resolves joined facts throughjoin. -
Method Summary
Modifier and TypeMethodDescriptionannotate(CharSequence symbol) Annotates one symbol.Annotates one term, keyed on itsoriginaltext.voidcollectFeatures(CharSequence token, Collection<String> features) Appends this annotator's features fortokentofeatures: one entry per present annotation attribute (sentiment, entity type, category, region), each already name-prefixed.private static booleanisAnnotatableToken(CharSequence token) Returns whethertokencould carry an emoji annotation and is worth looking up.
-
Field Details
-
FEATURE_SENTIMENT_PREFIX
Feature-name prefix for the coarse sentiment score, for exampleemojiSentiment=2.- See Also:
-
FEATURE_TYPE_PREFIX
Feature-name prefix for the coarse entity type, for exampleemojiType=HEART.- See Also:
-
FEATURE_CATEGORY_PREFIX
Feature-name prefix for the document-category hint, for exampleemojiCategory=SMILEYS_AND_EMOTION.- See Also:
-
FEATURE_REGION_PREFIX
Feature-name prefix for a flag's ISO 3166 region, for exampleemojiRegion=DE.- See Also:
-
FLAG_SEQUENCE
- See Also:
-
TAG_SEQUENCE
- See Also:
-
DERIVED_NOTE
- See Also:
-
FIRST_NON_ASCII
private static final char FIRST_NON_ASCII- See Also:
-
join
-
-
Constructor Details
-
EmojiAnnotator
public EmojiAnnotator()Creates an annotator over the bundled and derived layers only. -
EmojiAnnotator
Creates an annotator that also resolves joined facts throughjoin.- Parameters:
join- The joined-facts hook, called while a record is assembled. Must not benull.- Throws:
IllegalArgumentException- Thrown ifjoinisnull.
-
-
Method Details
-
annotate
Annotates one term, keyed on itsoriginaltext.- Parameters:
term- The term to annotate. Must not benull.- Returns:
- The assembled record, or empty when the term is not an annotated symbol.
- Throws:
IllegalArgumentException- Thrown iftermisnull.IllegalStateException- Thrown if the configured join violates its contract (returnsnullor a key colliding with an existing attribute).
-
annotate
Annotates one symbol.- Parameters:
symbol- The code point sequence of one symbol (one token). U+FE0F presentation selectors are ignored. Must not benull.- Returns:
- The assembled record, or empty when
symbolis not an annotated symbol. - Throws:
IllegalArgumentException- Thrown ifsymbolisnull.IllegalStateException- Thrown if the configured join violates its contract (returnsnullor a key colliding with an existing attribute).
-
collectFeatures
Appends this annotator's features fortokentofeatures: one entry per present annotation attribute (sentiment, entity type, category, region), each already name-prefixed. A token that carries no emoji annotation contributes nothing, so callers may pass every token.- Parameters:
token- The token to describe. Must not benull.features- The collection to append feature strings to. Must not benull.- Throws:
IllegalArgumentException- Thrown iftokenorfeaturesisnull.IllegalStateException- Thrown if the configured join violates its contract (seeannotate(CharSequence)).
-
isAnnotatableToken
Returns whethertokencould carry an emoji annotation and is worth looking up. Every annotatable symbol (a pictograph, a regional indicator, or the waving black flag) starts beyond ASCII, audited inEmojiAnnotationsTest; this fast-paths empty and ordinary tokens before any lookup or decode runs.- Returns:
- whether
tokencould carry an emoji annotation and is worth looking up
-