Record Class EmojiAnnotation

java.lang.Object
java.lang.Record
opennlp.tools.util.normalizer.EmojiAnnotation
Record Components:
symbol - The annotated code point sequence, without the U+FE0F presentation selector.
attributes - The attribute values keyed by attribute name (NAME, SENTIMENT, ENTITY_TYPE, CATEGORY).

public record EmojiAnnotation(String symbol, Map<String,EmojiAnnotation.Value> attributes) extends Record
The annotation record of one emoji: an extensible per-symbol store of attribute values, each carrying its own provenance. A record is assembled from up to three strictly separated layers: bundled facts from emoji-annotations.txt (see EmojiAnnotations), derived facts computed from the code point sequence itself, and joined facts resolved at run time against user-installed data. The typed accessors (name(), sentiment(), entityType(), category()) are projections of the attributes() map, so an attribute added later is new rows plus an accessor, not a shape change.

Every attribute is optional: a consumer that only wants one dimension pays nothing for the rest, and a record never fabricates a value it has no source for. Instances are immutable and thread-safe.

  • Field Details

  • Constructor Details

    • EmojiAnnotation

      public EmojiAnnotation(String symbol, Map<String,EmojiAnnotation.Value> attributes)
      Creates a record; normally records come from EmojiAnnotations.lookup(CharSequence).
      Parameters:
      symbol - The annotated code point sequence. Must not be null or empty.
      attributes - The attribute values keyed by attribute name. Must not be null or contain null keys or values; it is defensively copied.
      Throws:
      IllegalArgumentException - if symbol is null or empty, or if attributes is null or contains a null key or value.
  • Method Details

    • attribute

      public Optional<EmojiAnnotation.Value> attribute(String name)
      Returns the value of one attribute with its provenance.
      Parameters:
      name - The attribute name, for example NAME. Must not be null.
      Returns:
      The value, or empty when this record does not carry the attribute.
      Throws:
      IllegalArgumentException - if name is null.
    • name

      public Optional<String> name()
      Returns the human-readable name (the CLDR short name), or empty when not annotated.
      Returns:
      the human-readable name (the CLDR short name), or empty when not annotated
    • isoRegion

      public Optional<String> isoRegion()
      Returns the ISO 3166 code of a flag emoji (DE, GB-ENG), or empty when this record is not a flag. Populated by the derived layer through EmojiAnnotator.
      Returns:
      the ISO 3166 code of a flag emoji (DE, GB-ENG), or empty when this record is not a flag
    • sentiment

      public OptionalInt sentiment()
      Returns the project-authored coarse sentiment score in -2..2, or empty when not annotated.
      Returns:
      the project-authored coarse sentiment score in -2..2, or empty when not annotated
      Throws:
      IllegalStateException - if the stored value is not an integer, which cannot happen for records loaded from the bundled data (the loader validates it).
    • entityType

      public Optional<EmojiEntityType> entityType()
      Returns the coarse entity type, or empty when not annotated.
      Returns:
      the coarse entity type, or empty when not annotated
      Throws:
      IllegalStateException - if the stored value is not an EmojiEntityType constant, which cannot happen for records loaded from the bundled data (the loader validates it).
    • category

      public Optional<EmojiCategory> category()
      Returns the document-category hint, or empty when not annotated.
      Returns:
      the document-category hint, or empty when not annotated
      Throws:
      IllegalStateException - if the stored value is not an EmojiCategory constant, which cannot happen for records loaded from the bundled data (the loader validates it).
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • symbol

      public String symbol()
      Returns the value of the symbol record component.
      Returns:
      the value of the symbol record component
    • attributes

      public Map<String,EmojiAnnotation.Value> attributes()
      Returns the value of the attributes record component.
      Returns:
      the value of the attributes record component