Class EmojiFlags

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

public final class EmojiFlags extends Object
The derived-facts layer of the emoji annotation record store: decodes flag emoji to ISO 3166 codes purely from the code point sequence, with no data file. An emoji flag sequence is two regional indicator symbols encoding an ISO 3166-1 alpha-2 code (U+1F1E9 U+1F1EA decodes to DE), and an emoji tag sequence over U+1F3F4 WAVING BLACK FLAG encodes an ISO 3166-2 subdivision code in tag characters (the England flag decodes to GB-ENG); both mechanisms are defined by UTS #51.

Decoding is mechanical and deliberately does not check assignment: U+1F1FD U+1F1FD decodes to XX even though no such region is assigned, because validity against the region registry is a join-time question for whatever gazetteer the user has installed (see the joined-facts layer), not a bundled fact. This is also why no per-flag rows exist in emoji-annotations.txt: the region code is fully determined by the sequence itself.

isoRegion(CharSequence) is the strict decoder: it fails loud on a sequence that is flag-shaped but malformed, such as a lone regional indicator or an unterminated tag sequence. isFlag(CharSequence) is the total predicate for bulk callers that must never throw on degenerate real-world text. The expected input is one symbol, for example one Term.original() token; the UAX #29 word tokenizer already segments a run of adjacent flags into regional indicator pairs.

  • Method Details

    • isFlag

      public static boolean isFlag(CharSequence symbol)
      Returns whether symbol is exactly one well-formed flag emoji. True only for a regional indicator pair or a terminated subdivision tag sequence; unlike isoRegion(CharSequence) this never throws on malformed sequences, so bulk callers (per-token annotation of arbitrary text) can probe safely.
      Parameters:
      symbol - The code point sequence of one symbol. Must not be null.
      Returns:
      whether symbol is exactly one well-formed flag emoji
      Throws:
      IllegalArgumentException - if symbol is null.
    • isoRegion

      public static Optional<String> isoRegion(CharSequence symbol)
      Decodes one flag emoji to its ISO 3166 code: a regional indicator pair to the ISO 3166-1 alpha-2 code (DE) and a subdivision tag sequence to the ISO 3166-2 code (GB-ENG).
      Parameters:
      symbol - The code point sequence of one symbol. Must not be null.
      Returns:
      The ISO 3166 code, or empty when symbol is not flag-shaped at all (no leading regional indicator and no tag sequence over U+1F3F4; a lone U+1F3F4 and the ZWJ pirate flag are not region flags).
      Throws:
      IllegalArgumentException - if symbol is null, or if it is flag-shaped but malformed: a lone regional indicator, more or fewer than exactly two regional indicators, or a tag sequence that is unterminated, too short for a subdivision code, not letter-led, or followed by trailing content.