Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract pattern data about compact number formats(555) #561

Merged
merged 1 commit into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class CLDRConstants {
public static final String CLDR_CORE = "cldr-core-";
public static final String CLDR_DATES_FULL = "cldr-dates-full-";
public static final String CLDR_MISC_FULL = "cldr-misc-full-";
public static final String CLDR_NUMBERS_FULL = "cldr-numbers-full-";
public static final String CLDR_VERSION = "32.0.0";
public static final String FILE_NAME = CLDR_VERSION + ".zip";
public static final String CONTEXT_TRANSFORM_JSON = "contextTransforms.json";
Expand Down Expand Up @@ -65,6 +66,7 @@ public class CLDRConstants {
public static final String CLDR_CORE_ALIASES = CLDRConstants.CLDR_CORE + CLDR_VERSION + "/supplemental/aliases.json";
public static final String CLDR_DATES_FULL_DATE_FIELDS = CLDR_DATES_FULL + "{0}/main/{1}/dateFields.json";
public static final String CLDR_DATES_FULL_CA_GREGORIAN = CLDR_DATES_FULL + "{0}/main/{1}/ca-gregorian.json";
public static final String CLDR_NUMBERS_FULL_NUMBERS = CLDR_NUMBERS_FULL + "{0}/main/{1}/numbers.json";

public static final String LANGUAGE_DATA_KEY_PATH = "supplemental.languageData";
public static final String PLURALS_KEY_PATH = "supplemental.plurals-type-cardinal";
Expand All @@ -74,4 +76,11 @@ public class CLDRConstants {

public static final String MISC_CONTEXT_TRANSFORM = CLDR_MISC_FULL + CLDR_VERSION + "/main/{0}/contextTransforms.json";
public static final String CONTEXT_TRANSFORM_NODE = "main.{0}.contextTransforms";

public static final String DEFAULT_NUMBER_SYSTEM = "main.{0}.numbers.defaultNumberingSystem";
public static final String SYMBOLS_NUMBER_SYSTEM = "main.{0}.numbers.symbols-numberSystem-{1}.{2}";
public static final String DECIMAL_FORMATS_NUMBER_SYSTEM = "main.{0}.numbers.decimalFormats-numberSystem-{1}.{2}";
public static final String PERCENT_FORMATS_NUMBER_SYSTEM = "main.{0}.numbers.percentFormats-numberSystem-{1}.{2}";
public static final String CURRENCY_FORMATS_NUMBER_SYSTEM = "main.{0}.numbers.currencyFormats-numberSystem-{1}.{2}";
public static final String SCIENTIFIC_FORMATS_NUMBER_SYSTEM = "main.{0}.numbers.scientificFormats-numberSystem-{1}.{2}";
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,36 @@ public class Constants {
public static final String TIME_FORMATS = "timeFormats";
public static final String DATE_TIME_FORMATS = "dateTimeFormats";
public static final String DATE_FIELDS = "dateFields";

// number data
public static final String DECIMAL = "decimal";
public static final String GROUP = "group";
public static final String LIST = "list";
public static final String PERCENT_SIGN = "percentSign";
public static final String PLUS_SIGN = "plusSign";
public static final String MINUS_SIGN = "minusSign";
public static final String EXPONENTIAL = "exponential";
public static final String SUPER_SCRIPT_EXPONENT = "superscriptingExponent";
public static final String PER_MILLE = "perMille";
public static final String INFINITY = "infinity";
public static final String NAN = "nan";
public static final String TIME_SEPARATOR = "timeSeparator";
public static final String STANDARD = "standard";
public static final String LONG = "long";
public static final String SHORT = "short";
public static final String LONG_DECIMAL_FORMATS = "long.decimalFormat";
public static final String SHORT_DECIMAL_FORMATS = "short.decimalFormat";
public static final String SHORT_STANDARD = "short.standard";
public static final String DECIMAL_FORMAT = "decimalFormat";
public static final String DECIMAL_FORMATS = "decimalFormats";
public static final String PERCENT_FORMATS = "percentFormats";
public static final String CURRENCY_FORMATS = "currencyFormats";
public static final String SCIENTIFIC_FORMATS = "scientificFormats";
public static final String NUMBER_SYMBOLS = "numberSymbols";
public static final String NUMBER_FORMATS = "numberFormats";
public static final String DEFAULT_NUMBER_SYSTEM = "defaultNumberingSystem";
public static final String DECIMAL_FORMATS_LONG = "decimalFormats-long";
public static final String DECIMAL_FORMATS_SHORT = "decimalFormats-short";
public static final String CURRENCY_FORMATS_SHORT = "currencyFormats-short";

}
Original file line number Diff line number Diff line change
Expand Up @@ -600,73 +600,100 @@ private static Map<String, Object> dateTimeFormatExtract(String locale, JSONObje

public static Map<String, Object> numberDataExtract(String locale) {
String zipPath = CLDRConstants.NUMBER_ZIP_FILE_PATH;
String fileName = "cldr-numbers-full-" + CLDR_VERSION + "/main/" + locale + "/numbers.json";
String fileName = MessageFormat.format(CLDRConstants.CLDR_NUMBERS_FULL_NUMBERS, CLDR_VERSION, locale);
String json = CLDRUtils.readZip(fileName, zipPath);
JSONObject numberContents = JSONUtil.string2JSON(json);

String defaultNumberingSystem = JSONUtil
.select(numberContents, MessageFormat.format(CLDRConstants.DEFAULT_NUMBER_SYSTEM, locale)).toString();

String decimal = JSONUtil
.select(numberContents, "main." + locale + ".numbers.symbols-numberSystem-latn.decimal").toString();
String group = JSONUtil.select(numberContents, "main." + locale + ".numbers.symbols-numberSystem-latn.group")
.select(numberContents, MessageFormat.format(CLDRConstants.SYMBOLS_NUMBER_SYSTEM, locale, defaultNumberingSystem, Constants.DECIMAL)).toString();
String group = JSONUtil.select(numberContents, MessageFormat.format(CLDRConstants.SYMBOLS_NUMBER_SYSTEM, locale, defaultNumberingSystem, Constants.GROUP))
.toString();
String list = JSONUtil.select(numberContents, "main." + locale + ".numbers.symbols-numberSystem-latn.list")
String list = JSONUtil.select(numberContents, MessageFormat.format(CLDRConstants.SYMBOLS_NUMBER_SYSTEM, locale, defaultNumberingSystem, Constants.LIST))
.toString();
String percentSign = JSONUtil
.select(numberContents, "main." + locale + ".numbers.symbols-numberSystem-latn.percentSign").toString();
.select(numberContents, MessageFormat.format(CLDRConstants.SYMBOLS_NUMBER_SYSTEM, locale, defaultNumberingSystem, Constants.PERCENT_SIGN)).toString();
String plusSign = JSONUtil
.select(numberContents, "main." + locale + ".numbers.symbols-numberSystem-latn.plusSign").toString();
.select(numberContents, MessageFormat.format(CLDRConstants.SYMBOLS_NUMBER_SYSTEM, locale, defaultNumberingSystem, Constants.PLUS_SIGN)).toString();
String minusSign = JSONUtil
.select(numberContents, "main." + locale + ".numbers.symbols-numberSystem-latn.minusSign").toString();
.select(numberContents, MessageFormat.format(CLDRConstants.SYMBOLS_NUMBER_SYSTEM, locale, defaultNumberingSystem, Constants.MINUS_SIGN)).toString();
String exponential = JSONUtil
.select(numberContents, "main." + locale + ".numbers.symbols-numberSystem-latn.exponential").toString();
.select(numberContents, MessageFormat.format(CLDRConstants.SYMBOLS_NUMBER_SYSTEM, locale, defaultNumberingSystem, Constants.EXPONENTIAL)).toString();
String superscriptingExponent = JSONUtil
.select(numberContents, "main." + locale + ".numbers.symbols-numberSystem-latn.superscriptingExponent")
.select(numberContents, MessageFormat.format(CLDRConstants.SYMBOLS_NUMBER_SYSTEM, locale, defaultNumberingSystem, Constants.SUPER_SCRIPT_EXPONENT))
.toString();
String perMille = JSONUtil
.select(numberContents, "main." + locale + ".numbers.symbols-numberSystem-latn.perMille").toString();
.select(numberContents, MessageFormat.format(CLDRConstants.SYMBOLS_NUMBER_SYSTEM, locale, defaultNumberingSystem, Constants.PER_MILLE)).toString();
String infinity = JSONUtil
.select(numberContents, "main." + locale + ".numbers.symbols-numberSystem-latn.infinity").toString();
String nan = JSONUtil.select(numberContents, "main." + locale + ".numbers.symbols-numberSystem-latn.nan")
.select(numberContents, MessageFormat.format(CLDRConstants.SYMBOLS_NUMBER_SYSTEM, locale, defaultNumberingSystem, Constants.INFINITY)).toString();
String nan = JSONUtil.select(numberContents, MessageFormat.format(CLDRConstants.SYMBOLS_NUMBER_SYSTEM, locale, defaultNumberingSystem, Constants.NAN))
.toString();
String timeSeparator = JSONUtil
.select(numberContents, "main." + locale + ".numbers.symbols-numberSystem-latn.timeSeparator")
.select(numberContents, MessageFormat.format(CLDRConstants.SYMBOLS_NUMBER_SYSTEM, locale, defaultNumberingSystem, Constants.TIME_SEPARATOR))
.toString();
Map<String, Object> numberSymbolsMap = new LinkedHashMap<String, Object>();
numberSymbolsMap.put("decimal", decimal);
numberSymbolsMap.put("group", group);
numberSymbolsMap.put("list", list);
numberSymbolsMap.put("percentSign", percentSign);
numberSymbolsMap.put("plusSign", plusSign);
numberSymbolsMap.put("minusSign", minusSign);
numberSymbolsMap.put("exponential", exponential);
numberSymbolsMap.put("superscriptingExponent", superscriptingExponent);
numberSymbolsMap.put("perMille", perMille);
numberSymbolsMap.put("infinity", infinity);
numberSymbolsMap.put("nan", nan);
numberSymbolsMap.put("timeSeparator", timeSeparator);

String decimalFormats = JSONUtil
.select(numberContents, "main." + locale + ".numbers.decimalFormats-numberSystem-latn.standard")
.toString();
String percentFormats = JSONUtil
.select(numberContents, "main." + locale + ".numbers.percentFormats-numberSystem-latn.standard")
.toString();
String currencyFormats = JSONUtil
.select(numberContents, "main." + locale + ".numbers.currencyFormats-numberSystem-latn.standard")
.toString();
String scientificFormats = JSONUtil
.select(numberContents, "main." + locale + ".numbers.scientificFormats-numberSystem-latn.standard")
.toString();
numberSymbolsMap.put(Constants.DECIMAL, decimal);
numberSymbolsMap.put(Constants.GROUP, group);
numberSymbolsMap.put(Constants.LIST, list);
numberSymbolsMap.put(Constants.PERCENT_SIGN, percentSign);
numberSymbolsMap.put(Constants.PLUS_SIGN, plusSign);
numberSymbolsMap.put(Constants.MINUS_SIGN, minusSign);
numberSymbolsMap.put(Constants.EXPONENTIAL, exponential);
numberSymbolsMap.put(Constants.SUPER_SCRIPT_EXPONENT, superscriptingExponent);
numberSymbolsMap.put(Constants.PER_MILLE, perMille);
numberSymbolsMap.put(Constants.INFINITY, infinity);
numberSymbolsMap.put(Constants.NAN, nan);
numberSymbolsMap.put(Constants.TIME_SEPARATOR, timeSeparator);

Map<String, Object> numberMap = new LinkedHashMap<>();
numberMap.put(Constants.DEFAULT_NUMBER_SYSTEM, defaultNumberingSystem);
numberMap.put(Constants.NUMBER_SYMBOLS, numberSymbolsMap);
numberMap.put(Constants.NUMBER_FORMATS, getNumberFormatData(numberContents, locale, defaultNumberingSystem, Constants.STANDARD));
return numberMap;
}

Map<String, Object> numberFormatsMap = new LinkedHashMap<String, Object>();
numberFormatsMap.put("decimalFormats", decimalFormats);
numberFormatsMap.put("percentFormats", percentFormats);
numberFormatsMap.put("currencyFormats", currencyFormats);
numberFormatsMap.put("scientificFormats", scientificFormats);
private static Map<String, Object> getNumberFormatData(JSONObject numberContents, String locale, String defaultNumberingSystem, String tag) {
Object decimalFormats = JSONUtil
.select(numberContents, MessageFormat.format(CLDRConstants.DECIMAL_FORMATS_NUMBER_SYSTEM, locale, defaultNumberingSystem, tag));
Object percentFormats = JSONUtil
.select(numberContents, MessageFormat.format(CLDRConstants.PERCENT_FORMATS_NUMBER_SYSTEM, locale, defaultNumberingSystem, tag));
Object currencyFormats = JSONUtil
.select(numberContents, MessageFormat.format(CLDRConstants.CURRENCY_FORMATS_NUMBER_SYSTEM, locale, defaultNumberingSystem, tag));
Object scientificFormats = JSONUtil
.select(numberContents, MessageFormat.format(CLDRConstants.SCIENTIFIC_FORMATS_NUMBER_SYSTEM, locale, defaultNumberingSystem, tag));
Object decimalFormats_long = JSONUtil
.select(numberContents, MessageFormat.format(CLDRConstants.DECIMAL_FORMATS_NUMBER_SYSTEM, locale, defaultNumberingSystem, Constants.LONG));
Object decimalFormats_short = JSONUtil
.select(numberContents, MessageFormat.format(CLDRConstants.DECIMAL_FORMATS_NUMBER_SYSTEM, locale, defaultNumberingSystem, Constants.SHORT));
Object currencyFormats_short = JSONUtil
.select(numberContents, MessageFormat.format(CLDRConstants.CURRENCY_FORMATS_NUMBER_SYSTEM, locale, defaultNumberingSystem, Constants.SHORT));

Map<String, Object> numberFormatsMap = new LinkedHashMap<>();
numberFormatsMap.put(Constants.DECIMAL_FORMATS, decimalFormats);
numberFormatsMap.put(Constants.PERCENT_FORMATS, percentFormats);
numberFormatsMap.put(Constants.CURRENCY_FORMATS, currencyFormats);
numberFormatsMap.put(Constants.SCIENTIFIC_FORMATS, scientificFormats);
numberFormatsMap.put(Constants.DECIMAL_FORMATS_LONG, CommonUtil.isEmpty(decimalFormats_long) ?
null: dataSort(decimalFormats_long, Constants.DECIMAL_FORMAT));
numberFormatsMap.put(Constants.DECIMAL_FORMATS_SHORT, CommonUtil.isEmpty(decimalFormats_long) ?
null: dataSort(decimalFormats_short, Constants.DECIMAL_FORMAT));
numberFormatsMap.put(Constants.CURRENCY_FORMATS_SHORT, CommonUtil.isEmpty(decimalFormats_long) ?
null: dataSort(currencyFormats_short, Constants.STANDARD));
return numberFormatsMap;

Map<String, Object> numberMap = new LinkedHashMap<String, Object>();
numberMap.put("numberSymbols", numberSymbolsMap);
numberMap.put("numberFormats", numberFormatsMap);
return numberMap;
}

private static Map<String, Object> dataSort(Object data, String key) {
if (data instanceof Map) {
Map<String, Object> datMap = (Map<String, Object>)data;
Map<String, Object> sortedMap = new HashMap<>();
sortedMap.put(key, JSONUtil.string2SortMap(datMap.get(key).toString()));
return sortedMap;
}

return null;
}

/**
Expand Down