/** */ public void setCount(K1 o1, K2 o2, int count) { IntCounter<K2> c = getCounter(o1); int oldCount = getCount(o1, o2); total -= oldCount; c.setCount(o2, count); total += count; }
/** * Given an ordering of the first (row) and second (column) keys, will produce a double matrix. * */ public int[][] toMatrix(List<K1> firstKeys, List<K2> secondKeys) { int[][] counts = new int[firstKeys.size()][secondKeys.size()]; for (int i = 0; i < firstKeys.size(); i++) { for (int j = 0; j < secondKeys.size(); j++) { counts[i][j] = getCount(firstKeys.get(i), secondKeys.get(j)); } } return counts; }
public int remove(K1 o1, K2 o2) { IntCounter<K2> c = getCounter(o1); int oldCount = getCount(o1, o2); total -= oldCount; c.remove(o2); if (c.isEmpty()) { map.remove(o1); } return oldCount; }
@SuppressWarnings({"unchecked"}) public String toCSVString(NumberFormat nf) { List<K1> firstKeys = new ArrayList<>(firstKeySet()); List<K2> secondKeys = new ArrayList<>(secondKeySet()); Collections.sort((List<? extends Comparable>)firstKeys); Collections.sort((List<? extends Comparable>)secondKeys); StringBuilder b = new StringBuilder(); String[] headerRow = new String[secondKeys.size() + 1]; headerRow[0] = ""; for (int j = 0; j < secondKeys.size(); j++) { headerRow[j + 1] = secondKeys.get(j).toString(); } b.append(StringUtils.toCSVString(headerRow)).append("\n"); for (K1 rowLabel : firstKeys) { String[] row = new String[secondKeys.size() + 1]; row[0] = rowLabel.toString(); for (int j = 0; j < secondKeys.size(); j++) { K2 colLabel = secondKeys.get(j); row[j + 1] = nf.format(getCount(rowLabel, colLabel)); } b.append(StringUtils.toCSVString(row)).append("\n"); } return b.toString(); }
System.out.printf("%s --> %s%n", word, lemma); for (String reducedTag : reducedTags) { int count = lemmaReducedTagCounter.getCount(lemma, reducedTag); String posTags = setToString(reducedTagTagCounter.getCounter(lemma+reducedTag).keySet()); System.out.printf("\t%s\t%d\t%s%n", reducedTag, count, posTags); Set<String> reducedTags = tagReducedTagCounter.getCounter(tag).keySet(); for (String reducedTag : reducedTags) { int count = tagReducedTagCounter.getCount(tag, reducedTag);
public static <CK1 extends Comparable<CK1>, CK2 extends Comparable<CK2>> String toCSVString( TwoDimensionalIntCounter<CK1, CK2> counter, NumberFormat nf, Comparator<CK1> key1Comparator, Comparator<CK2> key2Comparator) { List<CK1> firstKeys = new ArrayList<>(counter.firstKeySet()); List<CK2> secondKeys = new ArrayList<>(counter.secondKeySet()); Collections.sort(firstKeys, key1Comparator); Collections.sort(secondKeys, key2Comparator); StringBuilder b = new StringBuilder(); int secondKeysSize = secondKeys.size(); String[] headerRow = new String[secondKeysSize + 1]; headerRow[0] = ""; for (int j = 0; j < secondKeysSize; j++) { headerRow[j + 1] = secondKeys.get(j).toString(); } b.append(StringUtils.toCSVString(headerRow)).append('\n'); for (CK1 rowLabel : firstKeys) { String[] row = new String[secondKeysSize + 1]; row[0] = rowLabel.toString(); for (int j = 0; j < secondKeysSize; j++) { CK2 colLabel = secondKeys.get(j); row[j + 1] = nf.format(counter.getCount(rowLabel, colLabel)); } b.append(StringUtils.toCSVString(row)).append('\n'); } return b.toString(); }
/** */ public void setCount(K1 o1, K2 o2, int count) { IntCounter<K2> c = getCounter(o1); int oldCount = getCount(o1, o2); total -= oldCount; c.setCount(o2, count); total += count; }
double cMT = morphTag.getCount(morphId, tagId);
/** */ public void setCount(K1 o1, K2 o2, int count) { IntCounter<K2> c = getCounter(o1); int oldCount = getCount(o1, o2); total -= oldCount; c.setCount(o2, count); total += count; }
private double probWordTag(String word, int loc, int wordId, int tagId) { double cW = wordTag.totalCount(wordId); double cWT = wordTag.getCount(wordId, tagId); // p_L double p_W = cW / wordTag.totalCount(); // p_T double cTseen = tagCounter.getCount(tagId); double p_T = cTseen / tagCounter.totalCount(); // p_T_L double p_W_T = 0.0; if (cW > 0.0) { // Seen lemma double p_T_W = 0.0; if (cW > 100.0 && cWT > 0.0) { p_T_W = cWT / cW; } else { double cTunseen = wordTagUnseen.getCount(tagId); // TODO p_T_U is 0? double p_T_U = cTunseen / wordTagUnseen.totalCount(); p_T_W = (cWT + smooth[1]*p_T_U) / (cW + smooth[1]); } p_W_T = p_T_W * p_W / p_T; } else { // Unseen word. Score based on the word signature (of the surface form) IntTaggedWord iTW = new IntTaggedWord(wordId, tagId); double c_T = tagCounter.getCount(tagId); p_W_T = Math.exp(getUnknownWordModel().score(iTW, loc, c_T, tagCounter.totalCount(), smooth[0], word)); } return p_W_T; }
/** */ public void setCount(K1 o1, K2 o2, int count) { IntCounter<K2> c = getCounter(o1); int oldCount = getCount(o1, o2); total -= oldCount; c.setCount(o2, count); total += count; }
double cLT = lemmaTag.getCount(lemmaId, tagId);
public int remove(K1 o1, K2 o2) { IntCounter<K2> c = getCounter(o1); int oldCount = getCount(o1, o2); total -= oldCount; c.remove(o2); if (c.isEmpty()) { map.remove(o1); } return oldCount; }
/** * Given an ordering of the first (row) and second (column) keys, will produce a double matrix. * */ public int[][] toMatrix(List<K1> firstKeys, List<K2> secondKeys) { int[][] counts = new int[firstKeys.size()][secondKeys.size()]; for (int i = 0; i < firstKeys.size(); i++) { for (int j = 0; j < secondKeys.size(); j++) { counts[i][j] = getCount(firstKeys.get(i), secondKeys.get(j)); } } return counts; }
public int remove(K1 o1, K2 o2) { IntCounter<K2> c = getCounter(o1); int oldCount = getCount(o1, o2); total -= oldCount; c.remove(o2); if (c.isEmpty()) { map.remove(o1); } return oldCount; }
/** * Given an ordering of the first (row) and second (column) keys, will produce a double matrix. * */ public int[][] toMatrix(List<K1> firstKeys, List<K2> secondKeys) { int[][] counts = new int[firstKeys.size()][secondKeys.size()]; for (int i = 0; i < firstKeys.size(); i++) { for (int j = 0; j < secondKeys.size(); j++) { counts[i][j] = getCount(firstKeys.get(i), secondKeys.get(j)); } } return counts; }
public int remove(K1 o1, K2 o2) { IntCounter<K2> c = getCounter(o1); int oldCount = getCount(o1, o2); total -= oldCount; c.remove(o2); if (c.isEmpty()) { map.remove(o1); } return oldCount; }
/** * Given an ordering of the first (row) and second (column) keys, will produce a double matrix. * */ public int[][] toMatrix(List<K1> firstKeys, List<K2> secondKeys) { int[][] counts = new int[firstKeys.size()][secondKeys.size()]; for (int i = 0; i < firstKeys.size(); i++) { for (int j = 0; j < secondKeys.size(); j++) { counts[i][j] = getCount(firstKeys.get(i), secondKeys.get(j)); } } return counts; }
@SuppressWarnings({"unchecked"}) public String toCSVString(NumberFormat nf) { List<K1> firstKeys = new ArrayList<>(firstKeySet()); List<K2> secondKeys = new ArrayList<>(secondKeySet()); Collections.sort((List<? extends Comparable>)firstKeys); Collections.sort((List<? extends Comparable>)secondKeys); StringBuilder b = new StringBuilder(); String[] headerRow = new String[secondKeys.size() + 1]; headerRow[0] = ""; for (int j = 0; j < secondKeys.size(); j++) { headerRow[j + 1] = secondKeys.get(j).toString(); } b.append(StringUtils.toCSVString(headerRow)).append("\n"); for (K1 rowLabel : firstKeys) { String[] row = new String[secondKeys.size() + 1]; row[0] = rowLabel.toString(); for (int j = 0; j < secondKeys.size(); j++) { K2 colLabel = secondKeys.get(j); row[j + 1] = nf.format(getCount(rowLabel, colLabel)); } b.append(StringUtils.toCSVString(row)).append("\n"); } return b.toString(); }
@SuppressWarnings({"unchecked"}) public String toCSVString(NumberFormat nf) { List<K1> firstKeys = new ArrayList<K1>(firstKeySet()); List<K2> secondKeys = new ArrayList<K2>(secondKeySet()); Collections.sort((List<? extends Comparable>)firstKeys); Collections.sort((List<? extends Comparable>)secondKeys); StringBuilder b = new StringBuilder(); String[] headerRow = new String[secondKeys.size() + 1]; headerRow[0] = ""; for (int j = 0; j < secondKeys.size(); j++) { headerRow[j + 1] = secondKeys.get(j).toString(); } b.append(StringUtils.toCSVString(headerRow)).append("\n"); for (K1 rowLabel : firstKeys) { String[] row = new String[secondKeys.size() + 1]; row[0] = rowLabel.toString(); for (int j = 0; j < secondKeys.size(); j++) { K2 colLabel = secondKeys.get(j); row[j + 1] = nf.format(getCount(rowLabel, colLabel)); } b.append(StringUtils.toCSVString(row)).append("\n"); } return b.toString(); }