Class EmojiAnnotator

java.lang.Object
opennlp.tools.util.normalizer.EmojiAnnotator

public final class EmojiAnnotator extends Object
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 Details

    • FEATURE_SENTIMENT_PREFIX

      private static final String FEATURE_SENTIMENT_PREFIX
      Feature-name prefix for the coarse sentiment score, for example emojiSentiment=2.
      See Also:
    • FEATURE_TYPE_PREFIX

      private static final String FEATURE_TYPE_PREFIX
      Feature-name prefix for the coarse entity type, for example emojiType=HEART.
      See Also:
    • FEATURE_CATEGORY_PREFIX

      private static final String FEATURE_CATEGORY_PREFIX
      Feature-name prefix for the document-category hint, for example emojiCategory=SMILEYS_AND_EMOTION.
      See Also:
    • FEATURE_REGION_PREFIX

      private static final String FEATURE_REGION_PREFIX
      Feature-name prefix for a flag's ISO 3166 region, for example emojiRegion=DE.
      See Also:
    • FLAG_SEQUENCE

      private static final String FLAG_SEQUENCE
      See Also:
    • TAG_SEQUENCE

      private static final String TAG_SEQUENCE
      See Also:
    • DERIVED_NOTE

      private static final String DERIVED_NOTE
      See Also:
    • FIRST_NON_ASCII

      private static final char FIRST_NON_ASCII
      See Also:
    • join

      private final EmojiAnnotationJoin join
  • Constructor Details

    • EmojiAnnotator

      public EmojiAnnotator()
      Creates an annotator over the bundled and derived layers only.
    • EmojiAnnotator

      public EmojiAnnotator(EmojiAnnotationJoin join)
      Creates an annotator that also resolves joined facts through join.
      Parameters:
      join - The joined-facts hook, called while a record is assembled. Must not be null.
      Throws:
      IllegalArgumentException - Thrown if join is null.
  • Method Details

    • annotate

      public Optional<EmojiAnnotation> annotate(Term term)
      Annotates one term, keyed on its original text.
      Parameters:
      term - The term to annotate. Must not be null.
      Returns:
      The assembled record, or empty when the term is not an annotated symbol.
      Throws:
      IllegalArgumentException - Thrown if term is null.
      IllegalStateException - Thrown if the configured join violates its contract (returns null or a key colliding with an existing attribute).
    • annotate

      public Optional<EmojiAnnotation> annotate(CharSequence symbol)
      Annotates one symbol.
      Parameters:
      symbol - The code point sequence of one symbol (one token). U+FE0F presentation selectors are ignored. Must not be null.
      Returns:
      The assembled record, or empty when symbol is not an annotated symbol.
      Throws:
      IllegalArgumentException - Thrown if symbol is null.
      IllegalStateException - Thrown if the configured join violates its contract (returns null or a key colliding with an existing attribute).
    • collectFeatures

      public void collectFeatures(CharSequence token, Collection<String> features)
      Appends this annotator's features for token to features: 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 be null.
      features - The collection to append feature strings to. Must not be null.
      Throws:
      IllegalArgumentException - Thrown if token or features is null.
      IllegalStateException - Thrown if the configured join violates its contract (see annotate(CharSequence)).
    • isAnnotatableToken

      private static boolean isAnnotatableToken(CharSequence token)
      Returns whether token could 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 in EmojiAnnotationsTest; this fast-paths empty and ordinary tokens before any lookup or decode runs.
      Returns:
      whether token could carry an emoji annotation and is worth looking up