Skip to content

Commit

Permalink
CLDR-8956 Add tool for checking dtd items in ldml spec
Browse files Browse the repository at this point in the history
  • Loading branch information
macchiati committed Mar 7, 2023
1 parent c058b3a commit 76bb398
Show file tree
Hide file tree
Showing 3 changed files with 395 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multiset;
import com.google.common.collect.TreeMultimap;
import com.google.common.collect.TreeMultiset;

public class ListCoverageLevels {
public static void main(String[] args) {
Expand All @@ -49,7 +51,7 @@ public static void main(String[] args) {
PathStarrer starrer = new PathStarrer().setSubstitutionPattern("*");
Factory mainAndAnnotationsFactory = config.getMainAndAnnotationsFactory();

Set<String> toTest = sc.getLocaleCoverageLocales(Organization.cldr, EnumSet.allOf(Level.class));
Set<String> toTest = sc.getLocaleCoverageLocales(Organization.cldr, EnumSet.of(Level.MODERN));
// ImmutableSortedSet.of("it", "root", "ja");
// mainAndAnnotationsFactory.getAvailable();
final Set<CLDRLocale> ALL;
Expand All @@ -59,6 +61,29 @@ public static void main(String[] args) {
ALL = ImmutableSet.copyOf(_ALL);
}

Map<Level, Multiset<String>> levelToCounter = new TreeMap<>();
for (Level level : Level.values()) {
levelToCounter.put(level, TreeMultiset.create());
}
for (String locale : toTest) {
CLDRFile file = mainAndAnnotationsFactory.make(locale, false);
CoverageLevel2 coverageLeveler = CoverageLevel2.getInstance(locale);
System.out.println(locale);
for (String path : file) {
Level level = coverageLeveler.getLevel(path);
String skeleton = starrer.set(path);
levelToCounter.get(level).add(skeleton);
}
}
for (Entry<Level, Multiset<String>> entry : levelToCounter.entrySet()) {
Level level = entry.getKey();
Multiset<String> counter = entry.getValue();
for (Multiset.Entry<String> skeleton : counter.entrySet()) {
System.out.println(level + "\t" + skeleton.getCount() + "\t" + skeleton.getElement());
}
}
if (true) return;

M4<Level, String, Attributes, Boolean> data = ChainedMap.of(
new TreeMap<Level,Object>(),
new TreeMap<String,Object>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,30 @@

import java.io.File;
import java.text.ParseException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Deque;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -1739,7 +1761,10 @@ private void handleParentLocales(XPathParts parts) {
String locales = parts.getAttributeValue(-1, "locales");
String[] pl = locales.split(" ");
for (int i = 0; i < pl.length; i++) {
parentLocales.put(pl[i], parent);
String old = parentLocales.put(pl[i], parent);
if (old != null) {
throw new IllegalArgumentException("Locale " + pl[i] + " cannot have two parents: " + old + " and " + parent);
}
}
}

Expand Down
Loading

0 comments on commit 76bb398

Please sign in to comment.