Class EmojiAnnotations

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

public final class EmojiAnnotations extends Object
The bundled-facts layer of the emoji annotation record store: license-clean, provenance-tagged attributes intrinsic to a pictograph (name, coarse sentiment, entity type, document category), loaded on first use from the project-authored emoji-annotations.txt resource. Each row of that file is one attribute of one symbol (codepoints ; attribute ; value ; source ; notes), so every value carries its own provenance and adding an attribute later is new rows plus loader support instead of a file-format break. The loader fails loud on an unknown attribute or a malformed row: the data and the code move together, so an unrecognized attribute is corruption, not extensibility.

Data licensing: the name values are the CLDR short names and the entity-type/category values are derived from the group and subgroup headers of the upstream emoji-test.txt (UTS #51, Unicode License V3, see the NOTICE file); the sentiment scores are original project judgments tagged UNSPECIFIED. No third-party sentiment data set is copied; in particular the Emoji Sentiment Ranking (CC BY-SA) is not used in any form.

EmojiAnnotator is the accessor. Lookups strip U+FE0F (emoji presentation selector) because it does not change identity; bundled rows are keyed without it. Flag emoji have no bundled rows: region is derived, and gazetteer ids are never baked in.

  • Field Details

  • Constructor Details

    • EmojiAnnotations

      private EmojiAnnotations()
  • Method Details

    • lookup

      public static Optional<EmojiAnnotation> lookup(CharSequence symbol)
      Returns the bundled annotation record of one emoji. The bundled data is loaded on the first call; a failed load is not cached, so the next call loads again.
      Parameters:
      symbol - The code point sequence of one symbol, for example one Term.original() token. U+FE0F presentation selectors are ignored. Must not be null.
      Returns:
      The record, or empty when the bundled data does not annotate the symbol.
      Throws:
      IllegalArgumentException - Thrown if symbol is null, or if the bundled data is malformed.
      IllegalStateException - Thrown if the bundled data resource is missing.
      UncheckedIOException - Thrown if the bundled data resource cannot be read.
    • stripPresentationSelector

      static String stripPresentationSelector(CharSequence symbol)
      Removes every U+FE0F VARIATION SELECTOR-16 from symbol. When none is present, a String argument is returned as is and any other CharSequence is copied once by CharSequence.toString(). Package-visible so EmojiAnnotator keys derived-only records the same way.
      Parameters:
      symbol - The code point sequence to strip.
      Returns:
      The sequence without presentation selectors; symbol's own text when it contains none.
    • load

      private static Map<String,EmojiAnnotation> load()
      Returns the records parsed from the bundled emoji-annotations.txt resource.
      Returns:
      the records parsed from the bundled emoji-annotations.txt resource
      Throws:
      IllegalStateException - if the resource is missing.
      UncheckedIOException - if the resource cannot be read.
    • parse

      static Map<String,EmojiAnnotation> parse(InputStream in) throws IOException
      Parses annotation rows of the form codepoints ; attribute ; value ; source ; notes with space-separated hexadecimal code points; '#' starts a comment line. The notes column is the fifth and final field, so it may contain ';'. Package-private so the malformed-data handling can be exercised without the bundled resource.
      Parameters:
      in - The stream to read, in UTF-8; consumed and closed by this method.
      Returns:
      One immutable record per annotated symbol, keyed by the selector-stripped symbol.
      Throws:
      IOException - Thrown if reading in fails.
      IllegalArgumentException - Thrown if a row is malformed.
    • validate

      private static void validate(String attribute, String value, String source, int lineNumber, String content)
    • decode

      private static String decode(String hexCodePoints, int lineNumber, String content)