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. See OPENNLP-1870.

  • 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 - if join is null.
  • Method Details

    • annotate

      public Optional<EmojiAnnotation> annotate(Term term)
      Annotates one term, keyed on its original text (see the class note on why the original layer is the one annotations describe).
      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 - if term is null.
      IllegalStateException - 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 - if symbol is null.
      IllegalStateException - 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 - if token or features is null.
      IllegalStateException - if the configured join violates its contract (see annotate(CharSequence)).