Package opennlp.tools.util.normalizer
Class EmojiAnnotations
java.lang.Object
opennlp.tools.util.normalizer.EmojiAnnotations
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final BundledUnicodeData.Lazy<Map<String, EmojiAnnotation>> private static final StringStarts a comment line inemoji-annotations.txt.private static final charField separator inemoji-annotations.txt(codepoints ; attribute ; value ; source ; notes).private static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Stringprivate static Map<String, EmojiAnnotation> load()Returns the records parsed from the bundledemoji-annotations.txtresource.static Optional<EmojiAnnotation> lookup(CharSequence symbol) Returns the bundled annotation record of one emoji.(package private) static Map<String, EmojiAnnotation> parse(InputStream in) Parses annotation rows of the formcodepoints ; attribute ; value ; source ; noteswith space-separated hexadecimal code points;'#'starts a comment line.(package private) static StringRemoves every U+FE0F VARIATION SELECTOR-16 fromsymbol.private static void
-
Field Details
-
RESOURCE
- See Also:
-
COMMENT_PREFIX
Starts a comment line inemoji-annotations.txt.- See Also:
-
FIELD_SEPARATOR
private static final char FIELD_SEPARATORField separator inemoji-annotations.txt(codepoints ; attribute ; value ; source ; notes).- See Also:
-
ANNOTATIONS
-
-
Constructor Details
-
EmojiAnnotations
private EmojiAnnotations()
-
-
Method Details
-
lookup
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 oneTerm.original()token. U+FE0F presentation selectors are ignored. Must not benull.- Returns:
- The record, or empty when the bundled data does not annotate the symbol.
- Throws:
IllegalArgumentException- Thrown ifsymbolisnull, 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
Removes every U+FE0F VARIATION SELECTOR-16 fromsymbol. When none is present, aStringargument is returned as is and any otherCharSequenceis copied once byCharSequence.toString(). Package-visible soEmojiAnnotatorkeys 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
Returns the records parsed from the bundledemoji-annotations.txtresource.- Returns:
- the records parsed from the bundled
emoji-annotations.txtresource - Throws:
IllegalStateException- if the resource is missing.UncheckedIOException- if the resource cannot be read.
-
parse
Parses annotation rows of the formcodepoints ; attribute ; value ; source ; noteswith 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 readinginfails.IllegalArgumentException- Thrown if a row is malformed.
-
validate
-
decode
-