public void dump(PrintWriter out, WordPairStats wpStats, boolean reverse) { if (wpStats == null || !wpStats.hasStats()) { dump(out); return; } FullStatFig entropyFig = new FullStatFig(); FullStatFig numTranslationsFig = new FullStatFig(); FullStatFig sumFig = new FullStatFig(); // Sort English words by decreasing frequency ArrayList<Pair<Double, String>> entries1 = new ArrayList<Pair<Double, String>>(); for (String s : keySet()) { double count = wpStats.enCount(reverse, s); entries1.add(new Pair<Double, String>(count, s)); } Collections.sort( entries1, Collections.reverseOrder(new Pair.FirstComparator<Double, String>())); for (Pair<Double, String> vs : entries1) { String s = vs.getSecond(); StringDoubleMap m = getMap(s, false); FullStatFig fig = new FullStatFig(m.values()); entropyFig.add(fig.entropy()); numTranslationsFig.add(fig.size()); sumFig.add(fig.total()); out.printf( "%s\tentropy %s\tnTrans %d\tsum %f\tn %.0f\n", s, Fmt.D(fig.entropy()), fig.size(), fig.total(), vs.getFirst()); ArrayList<StringDoubleMap.Entry> entries2 = new ArrayList<StringDoubleMap.Entry>(m.entrySet()); Collections.sort(entries2, Collections.reverseOrder(m.entryValueComparator())); for (StringDoubleMap.Entry tv : entries2) { if (tv.getValue() < 1e-10) continue; // Skip zero entries String t = tv.getKey(); double count = wpStats.frCount(reverse, t); double dice = wpStats.dice(reverse, s, t); out.printf(" %s: %f\tn %.0f, dice=%f\n", t, tv.getValue(), count, dice); } } out.println("# entropy = " + entropyFig); out.println("# sum = " + sumFig); out.println("# numTranslations = " + numTranslationsFig); }
public void dump(PrintWriter out) { FullStatFig entropyFig = new FullStatFig(); FullStatFig numTranslationsFig = new FullStatFig(); FullStatFig sumFig = new FullStatFig(); for (Map.Entry<String, StringDoubleMap> e : entrySet()) { String s = e.getKey(); StringDoubleMap m = e.getValue(); FullStatFig fig = new FullStatFig(m.values()); entropyFig.add(fig.entropy()); numTranslationsFig.add(fig.size()); sumFig.add(fig.total()); out.printf( "%s\tentropy %s\tnTrans %d\tsum %f\n", s, Fmt.D(fig.entropy()), fig.size(), fig.total()); ArrayList<StringDoubleMap.Entry> entries2 = new ArrayList<StringDoubleMap.Entry>(m.entrySet()); Collections.sort(entries2, Collections.reverseOrder(m.entryValueComparator())); for (StringDoubleMap.Entry tv : entries2) { if (tv.getValue() < 1e-10) continue; // Skip zero entries String t = tv.getKey(); out.printf(" %s: %f\n", t, tv.getValue()); } } out.println("# entropy = " + entropyFig); out.println("# sum = " + sumFig); out.println("# numTranslations = " + numTranslationsFig); }