diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/Emoji.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/Emoji.java index ee3de41bd8a..30e669a8c22 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/Emoji.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/Emoji.java @@ -19,6 +19,7 @@ import java.util.Map.Entry; import java.util.Set; import org.unicode.cldr.draft.FileUtilities; +import org.unicode.cldr.util.PathHeader.PageId; public class Emoji { public static final String EMOJI_VARIANT = "\uFE0F"; @@ -74,16 +75,14 @@ public class Emoji { static { /* - # group: Smileys & People - # subgroup: face-positive - 1F600 ; fully-qualified # 😀 grinning face - */ + * Example from emoji-test.txt: + * # group: Smileys & Emotion + * # subgroup: face-smiling + * 1F600 ; fully-qualified # 😀 grinning face + */ Splitter semi = Splitter.on(CharMatcher.anyOf(";#")).trimResults(); String majorCategory = null; String minorCategory = null; - long majorOrder = 0; - long minorOrder = 0; - // Multimap,String> majorPlusMinorToEmoji = TreeMultimap.create(); for (String line : FileUtilities.in(Emoji.class, "data/emoji/emoji-test.txt")) { if (line.startsWith("#")) { line = line.substring(1).trim(); @@ -91,17 +90,13 @@ public class Emoji { majorCategory = line.substring("group:".length()).trim(); Long oldMajorOrder = majorToOrder.get(majorCategory); if (oldMajorOrder == null) { - majorToOrder.put(majorCategory, majorOrder = majorToOrder.size()); - } else { - majorOrder = oldMajorOrder; + majorToOrder.put(majorCategory, (long) majorToOrder.size()); } } else if (line.startsWith("subgroup:")) { minorCategory = line.substring("subgroup:".length()).trim(); Long oldMinorOrder = minorToOrder.get(minorCategory); if (oldMinorOrder == null) { - minorToOrder.put(minorCategory, minorOrder = minorToOrder.size()); - } else { - minorOrder = oldMinorOrder; + minorToOrder.put(minorCategory, (long) minorToOrder.size()); } } continue; @@ -113,17 +108,7 @@ public class Emoji { Iterator it = semi.split(line).iterator(); String emojiHex = it.next(); - if (emojiHex.contains("1F48F")) { - int debug = 0; - } - String original = Utility.fromHex(emojiHex, 4, " "); - if (original.contains("💏")) { - if (false) { - System.out.println(original + "\t" + Utility.hex(original)); - } - } - String type = it.next(); if (type.startsWith("fully-qualified")) { allRgi.add(original); @@ -151,13 +136,8 @@ public class Emoji { if (!emojiToOrder.containsKey(minimal)) { putUnique(emojiToOrder, minimal, emojiToOrder.size() * 100L); } - // - // majorPlusMinorToEmoji.put(Pair.of(majorOrder, minorOrder), minimal); boolean singleton = CharSequences.getSingleCodePoint(minimal) != Integer.MAX_VALUE; - // if (!emojiToOrder.containsKey(minimal)) { - // emojiToOrder.put(minimal, emojiToOrder.size()); - // } // skip constructed values if (minimal.contains(COMBINING_ENCLOSING_KEYCAP) @@ -177,11 +157,6 @@ public class Emoji { nonConstructed.add(minimal); } } - // for (Entry, String> entry : majorPlusMinorToEmoji.entries()) - // { - // String minimal = entry.getValue(); - // emojiToOrder.put(minimal, emojiToOrder.size()); - // } emojiToMajorCategory.freeze(); emojiToMinorCategory.freeze(); nonConstructed.add(MODIFIERS); // needed for names @@ -381,4 +356,35 @@ private static ImmutableSet buildPaths(String suffix) { } return builder.build(); } + + /** + * Return the PageId for the given emoji, making adjustments for pages that are united in + * emoji-test.txt but divided in Survey Tool, such as Symbols, Symbols2, and Symbols3 + * + * @param emoji the emoji as a string + * @return the adjusted PageId + */ + public static PageId getPageId(String emoji) { + final String major = getMajorCategory(emoji); + final String minor = getMinorCategory(emoji); + final PageId pageId = PageId.forString(major); + switch (pageId) { + case People: + if (minorToOrder.get(minor) < minorToOrder.get("person-fantasy")) { + return PageId.People; + } else { + return PageId.People2; + } + case Symbols: + if (minorToOrder.get(minor) < minorToOrder.get("transport-sign")) { + return PageId.Symbols; + } else if (minorToOrder.get(minor) < minorToOrder.get("other-symbol")) { + return PageId.Symbols2; + } else { + return PageId.Symbols3; + } + default: + return pageId; + } + } } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/PathHeader.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/PathHeader.java index 03ba221fc8a..d83721c1557 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/PathHeader.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/PathHeader.java @@ -309,12 +309,14 @@ public enum PageId { // Symbols, Flags] Smileys(SectionId.Characters, "Smileys & Emotion"), People(SectionId.Characters, "People & Body"), + People2(SectionId.Characters, "People & Body 2"), Animals_Nature(SectionId.Characters, "Animals & Nature"), Food_Drink(SectionId.Characters, "Food & Drink"), Travel_Places(SectionId.Characters, "Travel & Places"), Activities(SectionId.Characters), Objects(SectionId.Characters), Symbols2(SectionId.Characters), + Symbols3(SectionId.Characters), Flags(SectionId.Characters), Component(SectionId.Characters), Typography(SectionId.Characters), @@ -2197,28 +2199,7 @@ public String transform(String source) { new Transform() { @Override public String transform(String source) { - String major = Emoji.getMajorCategory(source); - // check that result is reasonable by running through PageId. - switch (major) { - default: - PageId pageId2 = PageId.forString(major); - if (pageId2.getSectionId() != SectionId.Characters) { - if (pageId2 == PageId.Symbols) { - pageId2 = PageId.Symbols2; - } - } - return pageId2.toString(); - case "Smileys & People": - String minorCat = Emoji.getMinorCategory(source); - if (minorCat.equals("skin-tone") - || minorCat.equals("hair-style")) { - return PageId.Component.toString(); - } else if (!minorCat.contains("face")) { - return PageId.People.toString(); - } else { - return PageId.Smileys.toString(); - } - } + return Emoji.getPageId(source).toString(); } }); functionMap.put(