*/
package com.ibm.icu.dev.test.format;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-
-import com.ibm.icu.dev.util.Relation;
import com.ibm.icu.text.PluralRules;
-import com.ibm.icu.text.PluralRules.NumberInfo;
import com.ibm.icu.text.PluralRules.PluralType;
import com.ibm.icu.util.ULocale;
static final PluralRulesFactory NORMAL = new PluralRulesFactoryVanilla();
- static final PluralRulesFactory ALTERNATE = new PluralRulesFactoryWithOverrides();
-
private PluralRulesFactory() {}
static class PluralRulesFactoryVanilla extends PluralRulesFactory {
return PluralRules.getFunctionalEquivalent(locale, isAvailable);
}
}
-
- static class PluralRulesFactoryWithOverrides extends PluralRulesFactory {
- @Override
- boolean hasOverride(ULocale locale) {
- return getPluralOverrides().containsKey(locale);
- }
-
- @Override
- public PluralRules forLocale(ULocale locale, PluralType ordinal) {
- PluralRules override = ordinal != PluralType.CARDINAL
- ? null
- : getPluralOverrides().get(locale);
- return override != null
- ? override
- : PluralRules.forLocale(locale, ordinal);
- }
-
- @Override
- public ULocale[] getAvailableULocales() {
- return PluralRules.getAvailableULocales(); // TODO fix if we add more locales
- }
-
- static final Map<String,ULocale> rulesToULocale = new HashMap();
-
- @Override
- public ULocale getFunctionalEquivalent(ULocale locale, boolean[] isAvailable) {
- if (rulesToULocale.isEmpty()) {
- for (ULocale locale2 : getAvailableULocales()) {
- String rules = forLocale(locale2).toString();
- ULocale old = rulesToULocale.get(rules);
- if (old == null) {
- rulesToULocale.put(rules, locale2);
- }
- }
- }
- String rules = forLocale(locale).toString();
- ULocale result = rulesToULocale.get(rules);
- return result == null ? ULocale.ROOT : result;
- }
- };
-
- static class SamplePatterns {
- final Map<String,String> keywordToPattern = new TreeMap(PluralRules.KEYWORD_COMPARATOR);
- final Map<String,String> keywordToErrors = new HashMap();
- public void put(ULocale locale, String keyword, String sample) {
- if (keywordToPattern.containsKey(keyword)) {
- throw new IllegalArgumentException("Duplicate keyword <" + keyword + "> for " + locale);
- } else {
- keywordToPattern.put(keyword, sample.replace(" ", "\u00A0"));
- }
- }
- public void checkErrors(Set<String> set) {
- final Map<String,String> skeletonToKeyword = new HashMap();
- for (String keyword : set) {
- String error = "";
- String sample = keywordToPattern.get(keyword);
- String skeleton = sample.replace(" ", "").replaceAll("\\s*\\{0\\}\\s*", "");
- String oldSkeletonKeyword = skeletonToKeyword.get(skeleton);
- if (oldSkeletonKeyword != null) {
- if (error.length() != 0) {
- error += ", ";
- }
- error += "Duplicate keyword skeleton <" + keyword + ", " + skeleton + ">, same as for: <" + oldSkeletonKeyword + ">";
- } else {
- skeletonToKeyword.put(skeleton, keyword);
- }
- if (error.length() == 0) {
- keywordToErrors.put(keyword, "");
- } else {
- keywordToErrors.put(keyword, "\tERROR: " + error);
- }
- }
- }
- }
-
-
- public static Map<ULocale, SamplePatterns> getLocaleToSamplePatterns() {
- if (LOCALE_TO_SAMPLE_PATTERNS == null) {
- loadData();
- }
- return LOCALE_TO_SAMPLE_PATTERNS;
- }
- public static Map<ULocale, PluralRules> getPluralOverrides() {
- if (OVERRIDES == null) {
- loadData();
- }
- return OVERRIDES;
- }
- public static Relation<ULocale, NumberInfo> getExtraSamples() {
- if (EXTRA_SAMPLES == null) {
- loadData();
- }
- return EXTRA_SAMPLES;
- }
-
- private static Map<ULocale, SamplePatterns> LOCALE_TO_SAMPLE_PATTERNS = null;
- private static Map<ULocale,PluralRules> OVERRIDES = null;
- private static Relation<ULocale,NumberInfo> EXTRA_SAMPLES = null;
-
- private static void loadData() {
- LinkedHashMap<ULocale, SamplePatterns> temp = new LinkedHashMap<ULocale, SamplePatterns>();
- HashMap<ULocale, PluralRules> tempOverrides = new HashMap<ULocale,PluralRules>();
- Relation<ULocale, NumberInfo> tempSamples = Relation.of(new HashMap<ULocale,Set<NumberInfo>>(), HashSet.class);
- for (String[] row : SAMPLE_PATTERNS) {
- ULocale locale = new ULocale(row[0]);
- String keyword = row[1];
- String sample = row[2];
- SamplePatterns samplePatterns = temp.get(locale);
- if (samplePatterns == null) {
- temp.put(locale, samplePatterns = new SamplePatterns());
- }
- samplePatterns.put(locale, keyword, sample);
- }
- for (String[] pair : overrides) {
- for (String locale : pair[0].split("\\s*,\\s*")) {
- ULocale uLocale = new ULocale(locale);
- if (tempOverrides.containsKey(uLocale)) {
- throw new IllegalArgumentException("Duplicate locale: " + uLocale);
- }
- try {
- PluralRules rules = PluralRules.parseDescription(pair[1]);
- tempOverrides.put(uLocale, rules);
- } catch (Exception e) {
- throw new IllegalArgumentException(locale + "\t" + pair[1], e);
- }
- }
- }
- for (String[] pair : EXTRA_SAMPLE_SOURCE) {
- for (String locale : pair[0].split("\\s*,\\s*")) {
- ULocale uLocale = new ULocale(locale);
- if (tempSamples.containsKey(uLocale)) {
- throw new IllegalArgumentException("Duplicate locale: " + uLocale);
- }
- for (String item : pair[1].split("\\s*,\\s*")) {
- tempSamples.put(uLocale, new PluralRules.NumberInfo(item));
- }
- }
- }
- LOCALE_TO_SAMPLE_PATTERNS = Collections.unmodifiableMap(temp);
- OVERRIDES = Collections.unmodifiableMap(tempOverrides);
- EXTRA_SAMPLES = (Relation<ULocale, NumberInfo>) tempSamples.freeze();
- }
-
-
-// static String[][] OLDRULES = {
-// {"af", "one: n is 1"},
-// {"am", "one: n in 0..1"},
-// {"ar", "zero: n is 0; one: n is 1; two: n is 2; few: n mod 100 in 3..10; many: n mod 100 in 11..99"},
-// {"az", "other: null"},
-// {"bg", "one: n is 1"},
-// {"bn", "one: n is 1"},
-// {"ca", "one: n is 1"},
-// {"cs", "one: n is 1; few: n in 2..4"},
-// {"cy", "zero: n is 0; one: n is 1; two: n is 2; few: n is 3; many: n is 6"},
-// {"da", "one: n is 1"},
-// {"de", "one: n is 1"},
-// {"el", "one: n is 1"},
-// {"en", "one: n is 1"},
-// {"es", "one: n is 1"},
-// {"et", "one: n is 1"},
-// {"eu", "one: n is 1"},
-// {"fa", "other: null"},
-// {"fi", "one: n is 1"},
-// {"fil", "one: n in 0..1"},
-// {"fr", "one: n within 0..2 and n is not 2"},
-// {"gl", "one: n is 1"},
-// {"gu", "one: n is 1"},
-// {"hi", "one: n in 0..1"},
-// {"hr", "one: n mod 10 is 1 and n mod 100 is not 11; few: n mod 10 in 2..4 and n mod 100 not in 12..14; many: n mod 10 is 0 or n mod 10 in 5..9 or n mod 100 in 11..14"},
-// {"hu", "other: null"},
-// {"hy", "one: n is 1"},
-// {"id", "other: null"},
-// {"is", "one: n is 1"},
-// {"it", "one: n is 1"},
-// {"he", "one: n is 1; two: n is 2; many: n is not 0 and n mod 10 is 0"},
-// {"ja", "other: null"},
-// {"ka", "other: null"},
-// {"kk", "one: n is 1"},
-// {"km", "other: null"},
-// {"kn", "other: null"},
-// {"ko", "other: null"},
-// {"ky", "one: n is 1"},
-// {"lo", "other: null"},
-// {"lt", "one: n mod 10 is 1 and n mod 100 not in 11..19; few: n mod 10 in 2..9 and n mod 100 not in 11..19"},
-// {"lv", "zero: n is 0; one: n mod 10 is 1 and n mod 100 is not 11"},
-// {"mk", "one: n mod 10 is 1 and n is not 11"},
-// {"ml", "one: n is 1"},
-// {"mn", "one: n is 1"},
-// {"mr", "one: n is 1"},
-// {"ms", "other: null"},
-// {"my", "other: null"},
-// {"ne", "one: n is 1"},
-// {"nl", "one: n is 1"},
-// {"nb", "one: n is 1"},
-// {"pa", "one: n is 1"},
-// {"pl", "one: n is 1; few: n mod 10 in 2..4 and n mod 100 not in 12..14; many: n is not 1 and n mod 10 in 0..1 or n mod 10 in 5..9 or n mod 100 in 12..14"},
-// {"ps", "one: n is 1"},
-// {"pt", "one: n is 1"},
-// {"ro", "one: n is 1; few: n is 0 or n is not 1 and n mod 100 in 1..19"},
-// {"ru", "one: n mod 10 is 1 and n mod 100 is not 11; few: n mod 10 in 2..4 and n mod 100 not in 12..14; many: n mod 10 is 0 or n mod 10 in 5..9 or n mod 100 in 11..14"},
-// {"si", "other: null"},
-// {"sk", "one: n is 1; few: n in 2..4"},
-// {"sl", "one: n mod 100 is 1; two: n mod 100 is 2; few: n mod 100 in 3..4"},
-// {"sq", "one: n is 1"},
-// {"sr", "one: n mod 10 is 1 and n mod 100 is not 11; few: n mod 10 in 2..4 and n mod 100 not in 12..14; many: n mod 10 is 0 or n mod 10 in 5..9 or n mod 100 in 11..14"},
-// {"sv", "one: n is 1"},
-// {"sw", "one: n is 1"},
-// {"ta", "one: n is 1"},
-// {"te", "one: n is 1"},
-// {"th", "other: null"},
-// {"tr", "other: null"},
-// {"uk", "one: n mod 10 is 1 and n mod 100 is not 11; few: n mod 10 in 2..4 and n mod 100 not in 12..14; many: n mod 10 is 0 or n mod 10 in 5..9 or n mod 100 in 11..14"},
-// {"ur", "one: n is 1"},
-// {"uz", "other: null"},
-// {"vi", "other: null"},
-// {"zh", "other: null"},
-// {"zu", "one: n is 1"},
-// };
-
- static String[][] SAMPLE_PATTERNS = {
- {"und", "zero", "{0} ADD-SAMPLE-ZERO"},
- {"und", "one", "{0} ADD-SAMPLE-ONE"},
- {"und", "two", "{0} ADD-SAMPLE-TWO"},
- {"und", "few", "{0} ADD-SAMPLE-FEW"},
- {"und", "many", "{0} ADD-SAMPLE-MANY"},
- {"und", "other", "{0} ADD-SAMPLE-OTHER"},
- {"af", "one", "{0} dag"},
- {"af", "other", "{0} dae"},
- {"am", "one", "{0} ቀን"},
- {"am", "other", "{0} ቀናት"}, // fixed to 'other'
- {"ar", "few", "{0} ساعات"},
- {"ar", "many", "{0} ساعة"},
- {"ar", "one", "ساعة"},
- {"ar", "other", "{0} ساعة"},
- {"ar", "two", "ساعتان"},
- {"ar", "zero", "{0} ساعة"},
- {"az", "one", "Sizin alış-veriş katınızda {0} X var. Onu almaq istəyirsiniz mi?"},
- {"az", "other", "Sizin alış-veriş kartınızda {0} X var. Onları almaq istəyirsiniz mi?"},
- {"bg", "one", "{0} ден"},
- {"bg", "other", "{0} дена"},
- {"bn", "one", "সসে {0}টি আপেল নিয়ে সেটা খেল"},
- {"bn", "other", "সসে {0}টি আপেল নিয়ে সেগুলি খেল"},
- {"br", "few", "{0} deiz"},
- {"br", "many", "{0} a zeizioù"},
- {"br", "one", "{0} deiz"},
- {"br", "other", "{0} deiz"},
- {"br", "two", "{0} zeiz"},
- {"ca", "one", "{0} dia"},
- {"ca", "other", "{0} dies"},
- {"cs", "few", "{0} dny"},
- {"cs", "one", "{0} den"},
- {"cs", "other", "{0} dní"},
- {"cs", "many", "{0} dne"}, // added from spreadsheet
- {"cy", "zero", "{0} cŵn, {0} cathod"},
- {"cy", "one", "{0} ci, {0} gath"},
- {"cy", "two", "{0} gi, {0} gath"},
- {"cy", "few", "{0} chi, {0} cath"},
- {"cy", "many", "{0} chi, {0} chath"},
- {"cy", "other", "{0} ci, {0} cath"},
- {"da", "one", "{0} dag"},
- {"da", "other", "{0} dage"},
- {"de", "one", "{0} Tag"},
- {"de", "other", "{0} Tage"},
- {"dz", "other", "ཉིནམ་ {0} "},
- {"el", "one", "{0} ημέρα"},
- {"el", "other", "{0} ημέρες"},
- {"es", "one", "{0} día"},
- {"es", "other", "{0} días"},
- {"et", "one", "{0} ööpäev"},
- {"et", "other", "{0} ööpäeva"},
- {"eu", "one", "Nire {0} lagunarekin nago"},
- {"eu", "other", "Nire {0} lagunekin nago"},
- {"fa", "one", "او {0} فیلم در هفته میبیند که کمدی است."},
- {"fa", "other", "او {0} فیلم در هفته میبیند که کمدی هستند."},
- {"fi", "one", "{0} päivä"},
- {"fi", "other", "{0} päivää"},
- {"fil", "one", "sa {0} araw"},
- {"fil", "other", "sa {0} (na) araw"},
- {"fr", "one", "{0} jour"},
- {"fr", "other", "{0} jours"},
- {"gl", "one", "{0} día"},
- {"gl", "other", "{0} días"},
- {"gu", "one", "{0} કિલોગ્રામ"},
- {"gu", "other", "{0} કિલોગ્રામ્સ"},
- {"he", "many", "{0} שנה"},
- {"he", "one", "שנה"},
- {"he", "other", "{0} שנים"},
- {"he", "two", "שנתיים"},
- {"hi", "one", "{0} घंटा"},
- {"hi", "other", "{0} घंटे"},
- {"hr", "few", "za {0} mjeseca"},
- {"hr", "many", "za {0} mjeseci"},
- {"hr", "one", "za {0} mjesec"},
- {"hr", "other", "za {0} mjeseci"},
- {"hu", "one", "A kosárban van {0} X. Meg akarja venni?"},
- {"hu", "other", "A kosárban van {0} X. Meg akarja venni őket?"},
- {"hy", "one", "այդ {0} ժամը"},
- {"hy", "other", "այդ {0} ժամերը"},
- {"id", "other", "{0} hari"},
- {"is", "one", "{0} dagur"},
- {"is", "other", "{0} dagar"},
- {"it", "one", "{0} giorno"},
- {"it", "other", "{0} giorni"},
- {"ja", "other", "{0}日"},
- {"ka", "one", "თქვენი კალათა შეიცავს {0} X-ს. გსურთ მისი შეძენა?"}, //
- {"ka", "other", "თქვენი კალათა შეიცავს {0} X-ს. გსურთ მათი შეძენა?"}, //
- {"kk", "one", "Кәрзеңкеде {0} X бар. Оны сатып алғыңыз келе ме?"}, //
- {"kk", "other", "Кәрзеңкеде {0} X бар. Оларды сатып алғыңыз келе ме?"}, //
- {"km", "other", "{0} ថ្ងៃ"},
- {"kn", "one", "{0} ದಿನ"},
- {"kn", "other", "{0} ದಿನಗಳು"},
- {"ko", "other", "{0}일"},
- {"ky", "one", "Сиздин дүкөнчүлөө картыңызда {0} X бар. Аны сатып алайын дейсизби?"},
- {"ky", "other", "Сиздин дүкөнчүлөө картыңызда {0} X бар. Аларды сатып алайын дейсизби?"},
- {"lo", "other", "{0} ມື້"},
- {"lt", "few", "{0} dienos"},
- {"lt", "one", "{0} diena"},
- {"lt", "other", "{0} dienų"},
- {"lv", "one", "{0} diennakts"},
- {"lv", "other", "{0} diennaktis"},
- {"lv", "zero", "{0} diennakšu"},
- {"mk", "one", "{0} ден"},
- {"mk", "other", "{0} дена"},
- {"ml", "one", "{0} വ്യക്തി"},
- {"ml", "other", "{0} വ്യക്തികൾ"},
- {"mn", "one", "Таны картанд {0} X байна. Та энийг худалдаж авмаар байна уу?"},
- {"mn", "other", "Таны картанд {0} Х байна. Та эднийг худалдаж авмаар байна уу?"},
- {"mr", "one", "{0} घर"},
- {"mr", "other", "{0} घरे"},
- {"ms", "other", "{0} hari"},
- {"my", "other", "{0}ရက္"},
- {"nb", "one", "{0} dag"},
- {"nb", "other", "{0} dager"},
- {"ne", "one", "तपाईंसँग {0} निमन्त्रणा छ"},
- {"ne", "other", "तपाईँसँग {0} निमन्त्रणाहरू छन्"},
- // {"ne", "", "{0} दिन बाँकी छ ।"},
- // {"ne", "", "{0} दिन बाँकी छ ।"},
- // {"ne", "", "{0} दिन बाँकी छ ।"},
- // {"ne", "", "{0} जनाहरू पाहुना बाँकी छ ।"},
- {"nl", "one", "{0} dag"},
- {"nl", "other", "{0} dagen"},
- {"pa", "one", "{0} ਘੰਟਾ"},
- {"pa", "other", "{0} ਘੰਟੇ"},
- {"pl", "few", "{0} miesiące"},
- {"pl", "many", "{0} miesięcy"},
- {"pl", "one", "{0} miesiąc"},
- {"pl", "other", "{0} miesiąca"},
- {"pt", "one", "{0} ponto"},
- {"pt", "other", "{0} pontos"},
- // {"pt_PT", "one", "{0} dia"},
- // {"pt_PT", "other", "{0} dias"},
- {"ro", "few", "{0} zile"},
- {"ro", "one", "{0} zi"},
- {"ro", "other", "{0} de zile"},
- {"ru", "few", "{0} года"},
- {"ru", "many", "{0} лет"},
- {"ru", "one", "{0} год"},
- {"ru", "other", "{0} года"},
- {"si", "one", "මට පොත් {0}ක් තිබේ. මම එය කියවීමි.්"},
- {"si", "other", "මට පොත් {0}ක් තිබේ. මම ඒවා කියවීමි."},
- {"sk", "few", "{0} dni"},
- {"sk", "one", "{0} deň"},
- {"sk", "other", "{0} dní"},
- {"sk", "many", "{0} dňa"}, // added from spreadsheet
- {"sl", "few", "{0} ure"},
- {"sl", "one", "{0} ura"},
- {"sl", "other", "{0} ur"},
- {"sl", "two", "{0} uri"},
- {"sq", "one", "{0} libër"},
- {"sq", "other", "{0} libra"},
- {"sr", "few", "{0} сата"},
- {"sr", "many", "{0} сати"},
- {"sr", "one", "{0} сат"},
- {"sr", "other", "{0} сати"},
- {"sv", "one", "om {0} dag"},
- {"sv", "other", "om {0} dagar"},
- {"sw", "one", "siku {0} iliyopita"},
- {"sw", "other", "siku {0} zilizopita"},
- {"ta", "one", "{0} நாள்"},
- {"ta", "other", "{0} நாட்கள்"},
- {"te", "one", "{0} రోజు"},
- {"te", "other", "{0} రోజులు"},
- {"th", "other", "{0} วัน"},
- {"tr", "one", "Sizin alış-veriş kartınızda {0} X var. Onu almak istiyor musunuz?"},
- {"tr", "other", "Sizin alış-veriş kartınızda {0} X var. Onları almak istiyor musunuz?"},
- {"uk", "few", "{0} дні"},
- {"uk", "many", "{0} днів"},
- {"uk", "one", "{0} день"},
- {"uk", "other", "{0} дня"},
- {"ur", "one", "{0} گھنٹہ"},
- {"ur", "other", "{0} گھنٹے"},
- {"uz", "one", "Xarid savatingizda {0} X bor. Uni sotib olishni xohlaysizmi?"},
- {"uz", "other", "Xaridingiz savatida {0} X bor. Ularni sotib olishni xohlaysizmi?"},
- {"vi", "other", "{0} ngày"},
- {"zh", "other", "{0} 天"},
- {"zh_Hant", "other", "{0} 日"},
- {"en", "one", "{0} day"}, // added from spreadsheet
- {"en", "other", "{0} days"}, // added from spreadsheet
- {"zu", "one", "{0} usuku"}, // added from spreadsheet
- {"zu", "other", "{0} izinsuku"}, // added from spreadsheet
- };
-
- static String[][] EXTRA_SAMPLE_SOURCE = {
- {"he,iw","10,20"},
- {"und,az,ka,kk,ky,mk,mn,my,pa,sq,uz","0,0.0,0.1,1,1.0,1.1,2.0,2.1,3,4,5,10,11,1.2,1.121"},
- };
-
- static String[][] overrides = {
- {"gu,mr,kn,am,fa", "one: n within 0..1"},
- {"ta,te,kk,uz,ky,hu,az,ka,mn,tr", "one: n is 1"},
- {"bn", "one: n within 0..1"},
- {"en,ca,de,et,fi,gl,it,nl,sw,ur", "one: j is 1"},
- {"sv", "one: j is 1 or f is 1"},
- {"pt", "one: n is 1 or f is 1"},
- {"si", "one: n in 0,1 or i is 0 and f is 1"},
- {"cs,sk", "one: j is 1; few: j in 2..4; many: v is not 0"},
- //{"cy", "one: n is 1; two: n is 2; few: n is 3; many: n is 6"},
- //{"el", "one: j is 1 or i is 0 and f is 1"},
- {"da,is", "one: j is 1 or f is 1"},
- {"fil,tl", "one: j in 0..1"},
- {"he,iw", "one: j is 1; two: j is 2; many: j not in 0..10 and j mod 10 is 0", "10,20"},
- {"hi", "one: n within 0..1"},
- {"hy", "one: n within 0..2 and n is not 2"},
- // {"hr", "one: j mod 10 is 1 and j mod 100 is not 11; few: j mod 10 in 2..4 and j mod 100 not in 12..14; many: j mod 10 is 0 or j mod 10 in 5..9 or j mod 100 in 11..14"},
- {"lv", "zero: n mod 10 is 0" +
- " or n mod 10 in 11..19" +
- " or v is 2 and f mod 10 in 11..19;" +
- "one: n mod 10 is 1 and n mod 100 is not 11" +
- " or v is 2 and f mod 10 is 1 and f mod 100 is not 11" +
- " or v is not 2 and f mod 10 is 1"},
- // {"lv", "zero: n mod 10 is 0" +
- // " or n mod 10 in 11..19" +
- // " or v in 1..6 and f is not 0 and f mod 10 is 0" +
- // " or v in 1..6 and f mod 10 in 11..19;" +
- // "one: n mod 10 is 1 and n mod 100 is not 11" +
- // " or v in 1..6 and f mod 10 is 1 and f mod 100 is not 11" +
- // " or v not in 0..6 and f mod 10 is 1"},
- {"pl", "one: j is 1; few: j mod 10 in 2..4 and j mod 100 not in 12..14; many: j is not 1 and j mod 10 in 0..1 or j mod 10 in 5..9 or j mod 100 in 12..14"},
- {"sl", "one: j mod 100 is 1; two: j mod 100 is 2; few: j mod 100 in 3..4 or v is not 0"},
- // {"sr", "one: j mod 10 is 1 and j mod 100 is not 11" +
- // " or v in 1..6 and f mod 10 is 1 and f mod 100 is not 11" +
- // " or v not in 0..6 and f mod 10 is 1;" +
- // "few: j mod 10 in 2..4 and j mod 100 not in 12..14" +
- // " or v in 1..6 and f mod 10 in 2..4 and f mod 100 not in 12..14" +
- // " or v not in 0..6 and f mod 10 in 2..4"
- // },
- {"sr,hr,sh,bs", "one: j mod 10 is 1 and j mod 100 is not 11" +
- " or f mod 10 is 1 and f mod 100 is not 11;" +
- "few: j mod 10 in 2..4 and j mod 100 not in 12..14" +
- " or f mod 10 in 2..4 and f mod 100 not in 12..14"
- },
- // +
- // " ; many: j mod 10 is 0 " +
- // " or j mod 10 in 5..9 " +
- // " or j mod 100 in 11..14" +
- // " or v in 1..6 and f mod 10 is 0" +
- // " or v in 1..6 and f mod 10 in 5..9" +
- // " or v in 1..6 and f mod 100 in 11..14" +
- // " or v not in 0..6 and f mod 10 in 5..9"
- {"mo,ro", "one: j is 1; few: v is not 0 or n is 0 or n is not 1 and n mod 100 in 1..19"},
- {"ru", "one: j mod 10 is 1 and j mod 100 is not 11;" +
- " many: j mod 10 is 0 or j mod 10 in 5..9 or j mod 100 in 11..14"
- // + "; many: j mod 10 is 0 or j mod 10 in 5..9 or j mod 100 in 11..14"
- },
- {"uk", "one: j mod 10 is 1 and j mod 100 is not 11; " +
- "few: j mod 10 in 2..4 and j mod 100 not in 12..14; " +
- "many: j mod 10 is 0 or j mod 10 in 5..9 or j mod 100 in 11..14"},
- {"zu", "one: n within 0..1"},
- {"mk", "one: n mod 10 in 0..1 and n mod 100 not in 0,11 or f mod 10 is 1 and f mod 10 is not 11"},
- {"pa", "one: n in 0..1"},
- };
-
}
+++ /dev/null
-/*
- *******************************************************************************
- * Copyright (C) 2013, Google Inc. and International Business Machines Corporation and *
- * others. All Rights Reserved. *
- *******************************************************************************
- */
-package com.ibm.icu.dev.test.format;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.Map.Entry;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import com.ibm.icu.dev.test.format.PluralRulesFactory.SamplePatterns;
-import com.ibm.icu.dev.test.format.PluralRulesTest.StandardPluralCategories;
-import com.ibm.icu.dev.util.CollectionUtilities;
-import com.ibm.icu.dev.util.Relation;
-import com.ibm.icu.impl.Row;
-import com.ibm.icu.text.NumberFormat;
-import com.ibm.icu.text.PluralRules;
-import com.ibm.icu.text.PluralRules.NumberInfo;
-import com.ibm.icu.util.ULocale;
-
-/**
- * @author markdavis
- */
-public class WritePluralRulesData {
- // TODO use options
- public static final String TARGETDIR = "/Users/markdavis/Google Drive/Backup-2012-10-09/Documents/indigo/Generated/icu/plural-verification/";
-
- public static void main(String[] args) throws Exception {
- if (args.length == 0) {
- args = new String[] {"verify"};
- }
- for (String arg : args) {
- if (arg.equalsIgnoreCase("original")) {
- generateSamples(SampleStyle.original);
- } else if (arg.startsWith("verify")) {
- showRules();
- generateSamples(SampleStyle.samples);
- generateSamples(SampleStyle.verify);
- } else if (arg.equalsIgnoreCase("oldSnap")) {
- generateLOCALE_SNAPSHOT(PluralRulesFactory.NORMAL);
- } else if (arg.equalsIgnoreCase("ranges")) {
- generateRanges(PluralRulesFactory.NORMAL);
- } else if (arg.equalsIgnoreCase("newSnap")) {
- generateLOCALE_SNAPSHOT(PluralRulesFactory.ALTERNATE);
- } else if (arg.equalsIgnoreCase("fromList")) {
- getOriginalSamples();
- } else {
- throw new IllegalArgumentException("Bad arg: <" + arg + ">");
- }
- }
- }
-
- /**
- * @param normal
- */
- private static void generateRanges(PluralRulesFactory normal) {
- Map<ULocale, SamplePatterns> patternMap = PluralRulesFactory.getLocaleToSamplePatterns();
- NumberFormat enf = NumberFormat.getInstance(ULocale.ENGLISH);
-
- for (String localeString : FOCUS_LOCALES) {
- ULocale locale = new ULocale(localeString);
- PluralRules pr = normal.forLocale(locale);
- SamplePatterns patterns = patternMap.get(locale);
- if (patterns == null) {
- System.out.println("Skipping " + locale);
- continue;
- }
- System.out.println();
- NumberFormat nf = NumberFormat.getInstance(new ULocale(localeString + "@numbers=latn"));
- Map<String,NumberInfo[]> samples = getSampleRanges(pr);
-
- Set<String> keywords = pr.getKeywords();
- for (String keyword1 : keywords) {
- NumberInfo sample1 = samples.get(keyword1)[0];
-
- for (String keyword2 : keywords) {
- NumberInfo sample2 = samples.get(keyword2)[1];
- if (sample2.source <= sample1.source) {
- continue;
- }
- // pick the pattern for the second item
- String pattern = patterns.keywordToPattern.get(keyword2);
- if (pattern == null) {
- throw new IllegalArgumentException("Missing pattern for <" + keyword2 + "> for " + locale);
- }
- String formattedRange = format(nf, sample1) + "-" + format(nf, sample2);
- String eformattedRange = format(enf, sample1) + "-" + format(enf, sample2);
- String result = pattern.contains("{0}") ? pattern.replace("{0}", formattedRange)
- : pattern + " " + formattedRange;
- System.out.println(locale + "\t"
- + eformattedRange + " items\t"
- + keyword1 + "\t" + keyword2 + "\t"
- + result
- );
- }
- }
- }
- }
-
- private static String format(NumberFormat nf, NumberInfo sample1) {
- nf.setMaximumFractionDigits(sample1.visibleFractionDigitCount);
- nf.setMinimumFractionDigits(sample1.visibleFractionDigitCount);
- String format = nf.format(sample1.source);
- return format;
- }
-
- /**
- * @param pr
- * @return
- */
- private static Map<String, NumberInfo[]> getSampleRanges(PluralRules pr) {
- Map<String, NumberInfo[]> result = new HashMap();
- for (int i = 0; i < 1000; ++i) {
- String keyword = pr.select(i);
- addRangeMaybe(result, i, keyword);
- }
- for (String keyword : pr.getKeywords()) {
- for (Double x : pr.getSamples(keyword)) {
- addRangeMaybe(result, x, keyword);
- }
- }
- return result;
- }
-
- private static void addRangeMaybe(Map<String, NumberInfo[]> result, double i, String keyword) {
- NumberInfo[] range = result.get(keyword);
- if (range == null) {
- result.put(keyword, range = new NumberInfo[2]);
- range[0] = new NumberInfo(Double.MAX_VALUE);
- range[1] = new NumberInfo(Double.MIN_VALUE);
- }
- if (i < range[0].source) {
- range[0] = new NumberInfo(i);
- }
- if (i > range[1].source) {
- range[1] = new NumberInfo(i);
- }
- }
-
- /**
- * @param samples
- * @return
- */
- private static Double getBiggest(Collection<Double> samples) {
- Double result = null;
- for (Double item : samples) {
- if (result == null || result < item) {
- result = item;
- }
- }
- return result;
- }
-
- static final String[] FOCUS_LOCALES = ("af,am,ar,az,bg,bn,ca,cs,cy,da,de,el,en,es,et,eu,fa,fi,fil,fr,gl,gu," +
- "hi,hr,hu,hy,id,is,it,he,ja,ka,kk,km,kn,ko,ky,lo,lt,lv,mk,ml,mn,mr,ms,my,ne,nl,nb," +
- "pa,pl,pt,ro,ru,si,sk,sl,sq,sr,sv,sw,ta,te,th,tr,uk,ur,uz,vi,zh,zu").split("\\s*,\\s*");
-
-
- static final String[][] ORIGINAL_SAMPLES = {
- {"af", "0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"am", "0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"ar", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.003, 0.01, 0.010, 0.011, 0.012, 0.013, 0.02, 0.020, 0.03, 0.1, 0.10, 0.100, 0.101, 0.102, 0.11, 0.12, 0.13, 0.2, 0.20, 0.3, 1.0, 1.00, 1.000, 1.002, 1.003, 1.010, 1.011, 1.012, 1.013, 1.02, 1.020, 1.03, 1.10, 1.100, 1.101, 1.102, 1.11, 1.12, 1.13, 1.2, 1.20, 1.3, 2.0, 2.00, 2.000, 2.001, 2.003, 2.01, 2.010, 2.011, 2.012, 2.013, 2.020, 2.03, 2.1, 2.10, 2.100, 2.101, 2.102, 2.11, 2.12, 2.13, 2.20, 2.3, 3.0, 3.00, 3.000, 3.001, 3.002, 3.01, 3.011, 3.012, 3.013, 3.02, 3.020, 3.1, 3.100, 3.101, 3.102, 3.11, 3.12, 3.13, 3.2, 3.20, 11.0, 11.00, 11.000, 11.001, 11.002, 11.003, 11.01, 11.010, 11.02, 11.03, 11.1, 11.10, 11.100, 11.101, 11.102, 11.2, 11.3, 100.0, 100.00, 100.000, 100.001, 100.002, 100.003, 100.01, 100.010, 100.011, 100.012, 100.013, 100.02, 100.020, 100.03, 100.1, 100.10, 100.11, 100.12, 100.13, 100.2, 100.20, 100.3"},
- {"bg", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"br", "0.0, 0.00, 0.000, 0.001, 0.002, 0.003, 0.005, 0.01, 0.010, 0.011, 0.012, 0.013, 0.02, 0.03, 0.05, 0.1, 0.10, 0.11, 0.12, 0.13, 0.2, 0.3, 0.5, 1.0, 1.00, 1.000, 1.002, 1.003, 1.005, 1.010, 1.011, 1.012, 1.013, 1.02, 1.03, 1.05, 1.10, 1.11, 1.12, 1.13, 1.2, 1.3, 1.5, 2, 2.0, 2.00, 2.000, 2.001, 2.003, 2.005, 2.01, 2.010, 2.011, 2.012, 2.013, 2.03, 2.05, 2.1, 2.10, 2.11, 2.12, 2.13, 2.3, 2.5, 3.0, 3.00, 3.000, 3.001, 3.002, 3.005, 3.01, 3.010, 3.011, 3.012, 3.013, 3.02, 3.05, 3.1, 3.10, 3.11, 3.12, 3.13, 3.2, 3.5, 5.0, 5.00, 5.000, 5.001, 5.002, 5.003, 5.01, 5.02, 5.03, 5.1, 5.2, 5.3, 1000000.0, 1000000.00, 1000000.000, 1000000.001, 1000000.002, 1000000.003, 1000000.005, 1000000.01, 1000000.010, 1000000.011, 1000000.012, 1000000.013, 1000000.02, 1000000.03, 1000000.05, 1000000.1, 1000000.10, 1000000.11, 1000000.12, 1000000.13, 1000000.2, 1000000.3, 1000000.5"},
- {"ca", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"cs", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.005, 0.01, 0.010, 0.011, 0.012, 0.02, 0.05, 0.1, 0.10, 0.11, 0.12, 0.2, 0.5, 1.0, 1.00, 1.000, 1.002, 1.005, 1.010, 1.011, 1.012, 1.02, 1.05, 1.10, 1.11, 1.12, 1.2, 1.5, 2.0, 2.00, 2.000, 2.001, 2.005, 2.01, 2.010, 2.011, 2.012, 2.05, 2.1, 2.10, 2.11, 2.12, 2.5, 5.0, 5.00, 5.000, 5.001, 5.002, 5.01, 5.02, 5.1, 5.2"},
- {"cy", "0.0, 0.00, 0.000, 0.001, 0.002, 0.003, 0.004, 0.006, 0.01, 0.010, 0.011, 0.012, 0.013, 0.016, 0.02, 0.03, 0.04, 0.06, 0.1, 0.10, 0.11, 0.12, 0.13, 0.16, 0.2, 0.3, 0.4, 0.6, 1.0, 1.00, 1.000, 1.002, 1.003, 1.004, 1.006, 1.010, 1.011, 1.012, 1.013, 1.016, 1.02, 1.03, 1.04, 1.06, 1.10, 1.11, 1.12, 1.13, 1.16, 1.2, 1.3, 1.4, 1.6, 2.0, 2.00, 2.000, 2.001, 2.003, 2.004, 2.006, 2.01, 2.010, 2.011, 2.012, 2.013, 2.016, 2.03, 2.04, 2.06, 2.1, 2.10, 2.11, 2.12, 2.13, 2.16, 2.3, 2.4, 2.6, 3.0, 3.00, 3.000, 3.001, 3.002, 3.004, 3.006, 3.01, 3.010, 3.011, 3.012, 3.013, 3.016, 3.02, 3.04, 3.06, 3.1, 3.10, 3.11, 3.12, 3.13, 3.16, 3.2, 3.4, 3.6, 4.0, 4.00, 4.000, 4.001, 4.002, 4.003, 4.006, 4.01, 4.02, 4.03, 4.06, 4.1, 4.2, 4.3, 4.6, 6.0, 6.00, 6.000, 6.001, 6.002, 6.003, 6.004, 6.01, 6.010, 6.011, 6.012, 6.013, 6.016, 6.02, 6.03, 6.04, 6.1, 6.10, 6.11, 6.12, 6.13, 6.16, 6.2, 6.3, 6.4, 8"},
- {"da", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"de", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"dz", "0, 0.0, 0.00, 0.000, 0.001, 0.01, 0.010, 0.1, 0.10, 1.0, 1.00, 1.000"},
- {"el", "2, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"es", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"et", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"eu", "0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1, 4"},
- {"fa", "0, 0.0, 0.00, 0.000, 0.001, 0.01, 0.010, 0.1, 0.10, 1.0, 1.00, 1.000"},
- {"fi", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"fil", "0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 0.5, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"fr", "0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"gl", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"gu", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"he", "0.0, 0.00, 0.000, 0.001, 0.002, 0.003, 0.01, 0.010, 0.011, 0.012, 0.02, 0.03, 0.1, 0.10, 0.11, 0.12, 0.2, 0.3, 1.0, 1.00, 1.000, 1.002, 1.003, 1.010, 1.011, 1.012, 1.02, 1.03, 1.10, 1.11, 1.12, 1.2, 1.3, 2.0, 2.00, 2.000, 2.001, 2.003, 2.01, 2.010, 2.011, 2.012, 2.03, 2.1, 2.10, 2.11, 2.12, 2.3, 3.0, 3.00, 3.000, 3.001, 3.002, 3.01, 3.010, 3.02, 3.1, 3.10, 3.2, 10.0, 10.00, 10.000, 10.001, 10.002, 10.003, 10.01, 10.011, 10.012, 10.02, 10.03, 10.1, 10.11, 10.12, 10.2, 10.3"},
- {"hi", "0.0, 0.00, 1.0, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.0, 1.0, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"hr", "0.0, 0.00, 0.000, 0.001, 0.002, 0.005, 0.01, 0.010, 0.011, 0.012, 0.02, 0.05, 0.1, 0.10, 0.11, 0.12, 0.2, 0.5, 0.5, 1.0, 1.00, 1.000, 1.002, 1.005, 1.010, 1.011, 1.012, 1.02, 1.05, 1.10, 1.11, 1.12, 1.2, 1.5, 2.0, 2.00, 2.000, 2.001, 2.005, 2.01, 2.010, 2.011, 2.012, 2.05, 2.1, 2.10, 2.11, 2.12, 2.5, 5.0, 5.00, 5.000, 5.001, 5.002, 5.01, 5.02, 5.1, 5.2"},
- {"hu", "0, 0.0, 0.00, 0.000, 0.001, 0.01, 0.010, 0.1, 0.10, 1.0, 1.00, 1.000"},
- {"hy", "0, 0, 0, 0, 0.001, 0.002, 0.003, 0.01, 0.01, 0.011, 0.012, 0.013, 0.02, 0.02, 0.03, 0.1, 0.1, 0.1, 0.101, 0.102, 0.11, 0.12, 0.13, 0.2, 0.2, 0.3, 1, 1, 1, 1.002, 1.003, 1.01, 1.011, 1.012, 1.013, 1.02, 1.02, 1.03, 1.1, 1.1, 1.101, 1.102, 1.11, 1.12, 1.13, 1.2, 1.2, 1.3, 2, 2, 2, 2.001, 2.003, 2.01, 2.01, 2.011, 2.012, 2.013, 2.02, 2.03, 2.1, 2.1, 2.1, 2.101, 2.102, 2.11, 2.12, 2.13, 2.2, 2.3, 3, 3, 3, 3.001, 3.002, 3.01, 3.011, 3.012, 3.013, 3.02, 3.02, 3.1, 3.1, 3.101, 3.102, 3.11, 3.12, 3.13, 3.2, 3.2, 11, 11, 11, 11.001, 11.002, 11.003, 11.01, 11.01, 11.02, 11.03, 11.1, 11.1, 11.1, 11.101, 11.102, 11.2, 11.3, 100, 100, 100, 100.001, 100.002, 100.003, 100.01, 100.01, 100.011, 100.012, 100.013, 100.02, 100.02, 100.03, 100.1, 100.1, 100.11, 100.12, 100.13, 100.2, 100.2, 100.3"},
- {"id", "0, 0.0, 0.00, 0.000, 0.001, 0.01, 0.010, 0.1, 0.10, 1.0, 1.00, 1.000"},
- {"is", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"it", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"ja", "0, 0.0, 0.00, 0.000, 0.001, 0.01, 0.010, 0.1, 0.10, 1.0, 1.00, 1.000"},
- {"km", "0, 0.0, 0.00, 0.000, 0.001, 0.01, 0.010, 0.1, 0.10, 1.0, 1.00, 1.000"},
- {"kn", "0, 0.0, 0.00, 0.000, 0.001, 0.01, 0.010, 0.1, 0.10, 1.0, 1.00, 1.000"},
- {"ko", "0, 0.0, 0.00, 0.000, 0.001, 0.01, 0.010, 0.1, 0.10, 1.0, 1.00, 1.000"},
- {"lo", "0, 0.0, 0.00, 0.000, 0.001, 0.01, 0.010, 0.1, 0.10, 1.0, 1.00, 1.000"},
- {"lt", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.012, 0.02, 0.1, 0.10, 0.11, 0.12, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.012, 1.02, 1.10, 1.11, 1.12, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.010, 2.011, 2.012, 2.1, 2.10, 2.11, 2.12, 10.0, 10.00, 10.000, 10.001, 10.002, 10.01, 10.02, 10.1, 10.2"},
- {"lv", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"ml", "0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"mr", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"ms", "0, 0.0, 0.00, 0.000, 0.001, 0.01, 0.010, 0.1, 0.10, 1.0, 1.00, 1.000"},
- {"nb", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"ne", "0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1, 2, 1, 0, 2, 1, 0"},
- {"nl", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"pl", "0.0, 0.00, 0.000, 0.001, 0.002, 0.005, 0.01, 0.010, 0.011, 0.012, 0.02, 0.05, 0.1, 0.10, 0.11, 0.12, 0.2, 0.5, 0.5, 1.0, 1.00, 1.000, 1.002, 1.005, 1.010, 1.011, 1.012, 1.02, 1.05, 1.10, 1.11, 1.12, 1.2, 1.5, 2.0, 2.00, 2.000, 2.001, 2.005, 2.01, 2.010, 2.011, 2.012, 2.05, 2.1, 2.10, 2.11, 2.12, 2.5, 5.0, 5.00, 5.000, 5.001, 5.002, 5.01, 5.02, 5.1, 5.2"},
- {"pt", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"pt_PT", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"ro", "0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.020, 0.021, 0.022, 0.1, 0.10, 0.11, 0.2, 0.20, 0.21, 0.22, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.020, 1.021, 1.022, 1.10, 1.11, 1.2, 1.20, 1.21, 1.22, 2.0, 2.00, 2.000, 2.001, 2.01, 2.020, 2.021, 2.022, 2.1, 2.20, 2.21, 2.22, 20, 20.0, 20.00, 20.000, 20.001, 20.002, 20.01, 20.010, 20.011, 20.02, 20.1, 20.10, 20.11, 20.2"},
- {"ru", "0.0, 0.00, 0.000, 0.001, 0.002, 0.005, 0.01, 0.010, 0.011, 0.012, 0.02, 0.05, 0.1, 0.10, 0.11, 0.12, 0.2, 0.5, 0.5, 1.0, 1.00, 1.000, 1.002, 1.005, 1.010, 1.011, 1.012, 1.02, 1.05, 1.10, 1.11, 1.12, 1.2, 1.5, 2.0, 2.00, 2.000, 2.001, 2.005, 2.01, 2.010, 2.011, 2.012, 2.05, 2.1, 2.10, 2.11, 2.12, 2.5, 5.0, 5.00, 5.000, 5.001, 5.002, 5.01, 5.02, 5.1, 5.2"},
- {"si", "0, 0.0, 0.00, 0.000, 0.001, 0.01, 0.010, 0.1, 0.10, 1.0, 1.00, 1.000"},
- {"sk", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.005, 0.01, 0.010, 0.011, 0.012, 0.02, 0.05, 0.1, 0.10, 0.11, 0.12, 0.2, 0.5, 1.0, 1.00, 1.000, 1.002, 1.005, 1.010, 1.011, 1.012, 1.02, 1.05, 1.10, 1.11, 1.12, 1.2, 1.5, 2.0, 2.00, 2.000, 2.001, 2.005, 2.01, 2.010, 2.011, 2.012, 2.05, 2.1, 2.10, 2.11, 2.12, 2.5, 5.0, 5.00, 5.000, 5.001, 5.002, 5.01, 5.02, 5.1, 5.2"},
- {"sl", "0.0, 0.00, 0.000, 0.001, 0.002, 0.003, 0.005, 0.01, 0.010, 0.011, 0.012, 0.013, 0.02, 0.03, 0.05, 0.1, 0.10, 0.11, 0.12, 0.13, 0.2, 0.3, 0.5, 1.0, 1.00, 1.000, 1.002, 1.003, 1.005, 1.010, 1.011, 1.012, 1.013, 1.02, 1.03, 1.05, 1.10, 1.11, 1.12, 1.13, 1.2, 1.3, 1.5, 2, 2.0, 2.00, 2.000, 2.001, 2.003, 2.005, 2.01, 2.010, 2.011, 2.012, 2.013, 2.03, 2.05, 2.1, 2.10, 2.11, 2.12, 2.13, 2.3, 2.5, 3.0, 3.00, 3.000, 3.001, 3.002, 3.005, 3.01, 3.010, 3.011, 3.012, 3.013, 3.02, 3.05, 3.1, 3.10, 3.11, 3.12, 3.13, 3.2, 3.5, 5.0, 5.00, 5.000, 5.001, 5.002, 5.003, 5.01, 5.02, 5.03, 5.1, 5.2, 5.3"},
- {"sr", "0.0, 0.00, 0.000, 0.001, 0.002, 0.005, 0.01, 0.010, 0.011, 0.012, 0.02, 0.05, 0.1, 0.10, 0.11, 0.12, 0.2, 0.5, 0.5, 1.0, 1.00, 1.000, 1.002, 1.005, 1.010, 1.011, 1.012, 1.02, 1.05, 1.10, 1.11, 1.12, 1.2, 1.5, 2.0, 2.00, 2.000, 2.001, 2.005, 2.01, 2.010, 2.011, 2.012, 2.05, 2.1, 2.10, 2.11, 2.12, 2.5, 5.0, 5.00, 5.000, 5.001, 5.002, 5.01, 5.02, 5.1, 5.2"},
- {"sv", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"sw", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"ta", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"te", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"th", "0, 0.0, 0.00, 0.000, 0.001, 0.01, 0.010, 0.1, 0.10, 1.0, 1.00, 1.000"},
- {"tr", "0, 0.0, 0.00, 0.000, 0.001, 0.01, 0.010, 0.1, 0.10, 1.0, 1.00, 1.000"},
- {"uk", "0.0, 0.00, 0.000, 0.001, 0.002, 0.005, 0.01, 0.010, 0.011, 0.012, 0.02, 0.05, 0.1, 0.10, 0.11, 0.12, 0.2, 0.5, 0.5, 1.0, 1.00, 1.000, 1.002, 1.005, 1.010, 1.011, 1.012, 1.02, 1.05, 1.10, 1.11, 1.12, 1.2, 1.5, 2.0, 2.00, 2.000, 2.001, 2.005, 2.01, 2.010, 2.011, 2.012, 2.05, 2.1, 2.10, 2.11, 2.12, 2.5, 5.0, 5.00, 5.000, 5.001, 5.002, 5.01, 5.02, 5.1, 5.2"},
- {"ur", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1"},
- {"vi", "0, 0.0, 0.00, 0.000, 0.001, 0.01, 0.010, 0.1, 0.10, 1.0, 1.00, 1.000"},
- {"zh", "0, 0.0, 0.00, 0.000, 0.001, 0.01, 0.010, 0.1, 0.10, 1.0, 1.00, 1.000"},
- {"zh_Hant", "0, 0.0, 0.00, 0.000, 0.001, 0.01, 0.010, 0.1, 0.10, 1.0, 1.00, 1.000"},
- {"zu", "0, 0.0, 0.00, 0.000, 0.001, 0.002, 0.01, 0.010, 0.011, 0.02, 0.1, 0.10, 0.11, 0.2, 1, 1.0, 1.00, 1.000, 1.002, 1.010, 1.011, 1.02, 1.10, 1.11, 1.2, 2, 2.0, 2.00, 2.000, 2.001, 2.01, 2.1, 10"},
- };
- static final Map<ULocale,List<NumberInfo>> LOCALE_TO_ORIGINALS = new HashMap();
- static {
- for (String[] pair : ORIGINAL_SAMPLES) {
- ArrayList<NumberInfo> row = new ArrayList();
- for (String s : pair[1].split("\\s*,\\s*")) {
- row.add(new NumberInfo(s));
- }
- LOCALE_TO_ORIGINALS.put(new ULocale(pair[0]), row);
- }
- }
-
- public static void getOriginalSamples() {
- try {
- File file = new File("/Users/markdavis/workspace/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/plurals.txt");
- BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
- Map<String,String> localeToSamples = new TreeMap();
- Matcher m = Pattern.compile("\\d+([.]\\d+)?").matcher("");
- int count = 0;
- while (true) {
- String line = br.readLine();
- ++count;
- if (line == null) break;
- line = line.trim();
- if (line.startsWith("#")) {
- continue;
- }
- String[] parts = line.split("\t");
- try {
- String locale = parts[0];
- String pattern = parts[1];
- boolean found = m.reset(pattern).find();
- if (parts.length != 2 || !found) {
- throw new ArrayIndexOutOfBoundsException();
- }
- String sample = found
- ? m.group()
- : "-1";
- String samples = localeToSamples.get(locale);
- localeToSamples.put(locale, samples == null ? sample : samples + ", " + sample);
- } catch (Exception e) {
- throw new IllegalArgumentException(count + " Line <" + line + ">", e);
- }
- }
- br.close();
- for (Entry<String, String> entry : localeToSamples.entrySet()) {
- System.out.println("{\"" + entry.getKey() + "\", \"" + entry.getValue() + "\"},");
- }
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- public static void generateLOCALE_SNAPSHOT(PluralRulesFactory pluralRulesFactory) {
- StringBuilder builder = new StringBuilder();
- Map<Set<StandardPluralCategories>, Relation<String, ULocale>> keywordsToData = new TreeMap(StandardPluralCategories.SHORTEST_FIRST);
- for (ULocale locale : pluralRulesFactory.getAvailableULocales()) {
- builder.setLength(0);
- PluralRules rules = pluralRulesFactory.forLocale(locale);
- boolean firstKeyword = true;
- EnumSet<StandardPluralCategories> keywords = StandardPluralCategories.getSet(rules.getKeywords());
- Relation<String, ULocale> samplesToLocales = keywordsToData.get(keywords);
- if (samplesToLocales == null) {
- keywordsToData.put(keywords, samplesToLocales = Relation.of(
- new LinkedHashMap<String,Set<ULocale>>(), LinkedHashSet.class));
- }
- //System.out.println(locale);
- for (StandardPluralCategories keyword : keywords) {
- if (firstKeyword) {
- firstKeyword = false;
- } else {
- builder.append(";\t");
- }
- Collection<NumberInfo> samples = rules.getFractionSamples(keyword.toString());
- if (samples.size() == 0) {
- throw new IllegalArgumentException();
- }
- builder.append(keyword).append(": ");
- boolean first = true;
- for (NumberInfo n : samples) {
- if (first) {
- first = false;
- } else {
- builder.append(", ");
- }
- builder.append(n);
- // for (double j : samples) {
- // double sample = i + j/100;
- // }
- }
- }
- samplesToLocales.put(builder.toString(), locale);
- }
- System.out.println(" static final String[] LOCALE_SNAPSHOT = {");
- for (Entry<Set<StandardPluralCategories>, Relation<String, ULocale>> keywordsAndData : keywordsToData.entrySet()) {
- System.out.println("\n // " + keywordsAndData.getKey());
- for (Entry<String, Set<ULocale>> samplesAndLocales : keywordsAndData.getValue().keyValuesSet()) {
- Set<ULocale> locales = samplesAndLocales.getValue();
- // check functional equivalence
- boolean[] isAvailable = new boolean[1];
- for (ULocale locale : locales) {
- ULocale base = pluralRulesFactory.getFunctionalEquivalent(locale, isAvailable);
- if (!locales.contains(base) && base.toString().length() != 0) {
- System.out.println("**" + locales + " doesn't contain " + base);
- }
- }
-
- System.out.println(
- " \"" + CollectionUtilities.join(locales, ",")
- + ";\t" + samplesAndLocales.getKey() + "\",");
- }
- }
- System.out.println(" };");
- }
-
- private static class OldNewData extends Row.R5<String, String, String, String, String> {
- public OldNewData(String oldRules, String oldSamples, String newRules, String newSamples, String intDiff) {
- super(oldRules, oldSamples, newRules, newSamples, intDiff);
- }
- }
-
- public static void showRules() throws IOException {
- BufferedWriter writer = getWriter("all-" + SampleStyle.rules + ".tsv");
-
- if (true) {
- // for debugging
- PluralRules rules = PluralRulesFactory.ALTERNATE.forLocale(new ULocale("lv"));
- rules.select(2.0d, 2, 0);
- }
- // System.out.println(new TreeSet(Arrays.asList(locales)));
- Relation<Map<String,OldNewData>, String> rulesToLocale = Relation.of(
- new TreeMap<Map<String,OldNewData>, Set<String>>(
- new CollectionUtilities.MapComparator<String,OldNewData>()), TreeSet.class);
- for (String localeString : FOCUS_LOCALES) {
- ULocale locale = new ULocale(localeString);
- PluralRules oldRules = PluralRulesFactory.NORMAL.forLocale(locale);
- PluralRules newRules = PluralRulesFactory.ALTERNATE.hasOverride(locale) ? PluralRulesFactory.ALTERNATE.forLocale(locale) : null;
- Set<String> keywords = oldRules.getKeywords();
- if (newRules != null) {
- TreeSet<String> temp = new TreeSet<String>(PluralRules.KEYWORD_COMPARATOR);
- temp.addAll(keywords);
- temp.addAll(newRules.getKeywords());
- keywords = temp;
- }
- Map<String,OldNewData> temp = new LinkedHashMap();
- for (String keyword : keywords) {
- Collection<NumberInfo> oldFractionSamples = oldRules.getFractionSamples(keyword);
- Collection<NumberInfo> newFractionSamples = newRules == null ? null : newRules.getFractionSamples(keyword);
-
- // add extra samples if we have some, or if the rules differ
-
- if (newRules != null) {
- oldFractionSamples = oldFractionSamples == null ? new TreeSet()
- : new TreeSet(oldFractionSamples);
- newFractionSamples = newFractionSamples == null ? new TreeSet()
- : new TreeSet(newFractionSamples);
- // if (extraSamples != null) {
- // for (NumberPlus sample : extraSamples) {
- // if (oldRules.select(sample.source, sample.visibleFractionDigitCount, sample.fractionalDigits).equals(keyword)) {
- // oldFractionSamples.add(sample);
- // }
- // if (newRules != null && newRules.select(sample.source, sample.visibleFractionDigitCount, sample.fractionalDigits).equals(keyword)) {
- // newFractionSamples.add(sample);
- // }
- // }
- // }
-
- // if the rules differ, then add samples from each to the other
- if (newRules != null) {
- for (NumberInfo sample : oldRules.getFractionSamples()) {
- if (newRules.select(sample).equals(keyword)) {
- newFractionSamples.add(sample);
- }
- }
- for (NumberInfo sample : newRules.getFractionSamples()) {
- if (oldRules.select(sample).equals(keyword)) {
- oldFractionSamples.add(sample);
- }
- }
- }
- }
-
- String intDiff = newRules == null ? "" : getDiffs(oldFractionSamples, newFractionSamples);
-
- String oldRulesString = rulesForDisplay(oldRules, keyword);
- if (oldRulesString == null) {
- oldRulesString = "";
- }
- String newRulesString = newRules == null ? "" : rulesForDisplay(newRules, keyword);
- if (newRulesString == null) {
- newRulesString = "";
- }
- if (oldRulesString.length() == 0 && newRulesString.length() != 0) {
- oldRulesString = "<NEW SPLITS>";
- } else if (oldRulesString.length() != 0 && newRulesString.length() == 0 && newRules != null) {
- newRulesString = "<NEW MERGES>";
- }
- temp.put(keyword, new OldNewData(
- oldRulesString,
- oldFractionSamples == null ? "" : "'" + CollectionUtilities.join(oldFractionSamples, ", "),
- newRulesString,
- newFractionSamples == null ? "" : "'" + CollectionUtilities.join(newFractionSamples, ", "),
- intDiff.length() == 0 ? "" : "'" + intDiff
- ));
- }
- rulesToLocale.put(temp, locale.toString());
- }
- writer.write("Locales\tPC\tOld Rules\tOld Sample Numbers\tNew Rules\tNew Sample Numbers\tInt-Diff\n");
- for (Entry<Map<String, OldNewData>, Set<String>> entry : rulesToLocale.keyValuesSet()) {
- String localeList = CollectionUtilities.join(entry.getValue(), " ");
- for (Entry<String, OldNewData> keywordRulesSamples : entry.getKey().entrySet()) {
- writer.write(
- localeList // locale
- + "\t" + keywordRulesSamples.getKey() // keyword
- + "\t" + keywordRulesSamples.getValue().get0() // rules
- + "\t" + keywordRulesSamples.getValue().get1() // samples
- + "\t" + keywordRulesSamples.getValue().get2() // rules
- + "\t" + keywordRulesSamples.getValue().get3() // samples
- + "\t" + keywordRulesSamples.getValue().get4() // int diff
- + "\n"
- );
- localeList = "";
- }
- }
-
- if (false) {
- System.out.println("\n\nOld Rules for Locales");
- for (String localeString : FOCUS_LOCALES) {
- ULocale locale = new ULocale(localeString);
- PluralRules oldRules = PluralRules.forLocale(locale);
- System.out.println("{\"" + locale.toString() + "\", \"" + oldRules.toString() + "\"},");
- }
- }
- writer.close();
- }
-
- /**
- * @param oldFractionSamples
- * @param newFractionSamples
- * @return
- */
- private static String getDiffs(Collection<NumberInfo> oldFractionSamples,
- Collection<NumberInfo> newFractionSamples) {
- oldFractionSamples = oldFractionSamples == null ? Collections.EMPTY_SET : oldFractionSamples;
- newFractionSamples = newFractionSamples == null ? Collections.EMPTY_SET : newFractionSamples;
-
- TreeSet<NumberInfo> additions = new TreeSet(newFractionSamples);
- additions.removeAll(oldFractionSamples);
- TreeSet<NumberInfo> removals = new TreeSet(oldFractionSamples);
- removals.removeAll(newFractionSamples);
- StringBuffer result = new StringBuffer();
- addInts(additions, "+", result);
- addInts(removals, "-", result);
- return result.toString();
- }
-
- private static void addInts(TreeSet<NumberInfo> additions, String title, StringBuffer result) {
- for (NumberInfo n : additions) {
- if (n.visibleFractionDigitCount == 0) {
- if (result.length() != 0) {
- result.append("; ");
- }
- result.append(title).append(n);
- }
- }
- }
-
- static final Set<String> NEW_LOCALES = new HashSet(Arrays.asList("az,ka,kk,ky,mk,mn,my,pa,sq,uz".split("\\s*,\\s*")));
-
-
- enum SampleStyle {original, samples, rules, verify}
-
- static void generateSamples(SampleStyle sampleStyle) throws IOException {
- LinkedHashSet<ULocale> skippedLocales = new LinkedHashSet<ULocale>();
- BufferedWriter writer = null;
- if (sampleStyle != SampleStyle.verify) {
- writer = getWriter("all-" + sampleStyle + ".tsv");
- //writer.write("Plural Category\tEnglish Number\tFormatted Sample\tAcceptable?\tReplacement\n");
- writer.write("Locale\tPC\tPattern\tSamples\tRules\tErrors (" + sampleStyle + ")\n");
- }
-
- for (String localeString : FOCUS_LOCALES) {
- ULocale locale = new ULocale(localeString);
- if (sampleStyle == SampleStyle.verify) {
- writer = getWriter("fraction-" + locale + ".tsv");
- writer.write("Plural Category\tEnglish Number\tFormatted Sample\tAcceptable?\tReplacement\n");
- }
-
- NumberFormat nf = NumberFormat.getInstance(new ULocale(locale.toString()+"@numbers=latn"));
- PluralRules newRules = PluralRulesFactory.ALTERNATE.forLocale(locale);
- SamplePatterns samplePatterns = PluralRulesFactory.getLocaleToSamplePatterns().get(locale);
- if (samplePatterns == null) {
- samplePatterns = PluralRulesFactory.getLocaleToSamplePatterns().get(new ULocale("und"));
- }
-
- // if (samplePatterns == null && NEW_LOCALES.contains(localeString)) {
- // skippedLocales.add(locale);
- // continue;
- // }
- // check for errors.
- samplePatterns.checkErrors(newRules.getKeywords());
- // now print.
- for (String keyword : newRules.getKeywords()) {
- if (sampleStyle != SampleStyle.samples) {
- Collection<NumberInfo> samples = getSamples(newRules, keyword, locale, sampleStyle);
- for (NumberInfo sample : samples) {
- String pattern = samplePatterns.keywordToPattern.get(keyword);
- String str = format(pattern, nf, sample);
- if (sampleStyle == SampleStyle.verify) {
- writer.write(keyword + "\t'" + sample + "\t" + str + "\n");
- } else {
- writer.write(locale + "\t" + keyword + "\t" + sample + "\t" + str + "\n");
- }
- }
- continue;
- }
- String pattern = null;
- String error = null;
- Collection<NumberInfo> samples = getSamples(newRules, keyword, locale, sampleStyle);
- NumberInfo first = samples.iterator().next();
- String sample = "??? " + first.toString();
- String rule = "";
- if (samplePatterns == null) {
- pattern = "???";
- error = "\tERROR: Locale data missing";
- } else {
- pattern = samplePatterns.keywordToPattern.get(keyword);
- rule = rulesForDisplay(newRules, keyword);
- error = samplePatterns.keywordToErrors.get(keyword);
- if (pattern == null) {
- pattern = "???";
- error = "\tERROR: Needed for new rules";
- } else {
- StringBuilder buffer = new StringBuilder();
- for (NumberInfo x : samples) {
- if (buffer.length() != 0) {
- buffer.append("; ");
- }
- String str = format(pattern, nf, x);
- buffer.append(str);
- }
- sample = buffer.toString();
- }
- }
- writer.write(locale + "\t" + keyword
- + "\t" + pattern
- + "\t" + sample
- + "\t" + rule
- + error
- + "\n"
- );
- }
- if (sampleStyle == SampleStyle.verify) {
- writer.close();
- }
- }
- if (sampleStyle != SampleStyle.verify) {
- if (skippedLocales.size() != 0) {
- writer.write("SKIP:\t\t\t" + skippedLocales + "\n");
- }
- writer.close();
- }
- }
-
- private static BufferedWriter getWriter(String filename) {
- try {
- BufferedWriter writer;
- String fileName = TARGETDIR + filename;
- System.out.println(new File(fileName).getCanonicalPath());
- writer = new BufferedWriter(
- new OutputStreamWriter(
- new FileOutputStream(fileName), Charset.forName("UTF-8")));
- return writer;
- } catch (FileNotFoundException e) {
- throw new IllegalArgumentException(e);
- } catch (IOException e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- private static Collection<NumberInfo> getSamples(PluralRules newRules, String keyword, ULocale locale, SampleStyle sampleStyle) {
- Set<NumberInfo> result = new TreeSet();
- Collection<NumberInfo> extras;
- if (sampleStyle == SampleStyle.original) {
- extras = LOCALE_TO_ORIGINALS.get(locale);
- if (extras != null) {
- for (NumberInfo s : extras) {
- if (keyword.equals(newRules.select(s))) {
- result.add(s);
- }
- }
- }
- }
- extras = PluralRulesFactory.getExtraSamples().get(locale);
- if (extras == null) {
- extras = PluralRulesFactory.getExtraSamples().get(new ULocale("und"));
- }
- if (extras != null) {
- for (NumberInfo s : extras) {
- if (keyword.equals(newRules.select(s))) {
- result.add(s);
- }
- }
- }
- if (result.size() == 0) {
- return newRules.getFractionSamples(keyword);
- }
- result.addAll(newRules.getFractionSamples(keyword));
- return result;
- }
-
- private static String rulesForDisplay(PluralRules newRules, String keyword) {
- String rule;
- rule = newRules.getRules(keyword);
- rule = rule != null ? rule.replace(" ", "\u00A0").replace("\u00A0or", " or")
- : keyword.equals("other") ? "<all else>"
- : "";
- return rule;
- }
-
- private static String format(String pattern, NumberFormat nf, NumberInfo x) {
- nf.setMaximumFractionDigits(x.visibleFractionDigitCount);
- nf.setMinimumFractionDigits(x.visibleFractionDigitCount);
- String str = nf.format(x.source);
- return pattern.replace("{0}", str);
- }
-
- /**
- *
- */
- private static void generateVerificationSamples() {
- // TODO Auto-generated method stub
-
- }
-
-
-}