public String tagString(Index<String> tagIndex) { String tagStr; if (tag >= 0) { tagStr = tagIndex.get(tag); } else if (tag == ANY_TAG_INT) { tagStr = ANY; } else { tagStr = STOP; } return tagStr; }
private static <L> String toString(int[] array, Index<L> classIndex) { List<L> l = new ArrayList<>(array.length); for (int item : array) { l.add(classIndex.get(item)); } return l.toString(); }
public <E> String toString(Index<E> classIndex) { List<E> l = new ArrayList<>(); for (int aLabel : label) { l.add(classIndex.get(aLabel)); } return l.toString(); }
private String toString(int[] array, Index<?> classIndex) { List<Object> l = new ArrayList<>(); for (int anArray : array) { l.add(classIndex.get(anArray)); } return l.toString(); }
public TimeExpression getTemporalExpr(String s) { Matcher m = ID_PATTERN.matcher(s); if (m.matches()) { String prefix = m.group(1); int id = Integer.parseInt(m.group(2)); if ("t".equals(prefix) || prefix.isEmpty()) { return temporalExprIndex.get(id); } } return null; }
/** * Get index of featureType for feature indexed by i. (featureType index is * used to index labelIndices to get labels.) * * @param i Feature index * @return index of featureType */ private int getFeatureTypeIndex(int i) { return getFeatureTypeIndex(featureIndex.get(i)); }
public String toString(Index<String> tagIndex) { StringBuilder sb = new StringBuilder(); sb.append('"'); sb.append(StringUtils.join(words, " ")); sb.append("\" start: "); sb.append(startPosition); sb.append(" type: "); sb.append(tagIndex.get(type)); sb.append(" other_occurrences: "); sb.append(Arrays.toString(otherOccurrences)); return sb.toString(); }
/** * the feature number of the original feature or -1 if this is for a prior * */ int featureOf(int index) { IntTuple i = featureIndex.get(index); if (i.length() == 1) { return -1; } return i.get(1); }
public void changeLabelIndex(Index<L> newLabelIndex) { labels = trimToSize(labels); for (int i = 0; i < labels.length; i++) { labels[i] = newLabelIndex.indexOf(labelIndex.get(labels[i])); } labelIndex = newLabelIndex; }
public double probabilityOfTrue(Counter<String> features) { DecisionTreeNode cur = root; while(!cur.isLeaf()) { double value = features.getCount(featureIndex.get(cur.idx)); cur = (value < cur.split)? cur.children[0] : cur.children[1]; } return (cur.split); // at the leaf node, idx represents true or false. 1: true, 0: false, split represents probability of true. } }
public static <T> Counter<T> toCounter(double[] counts, Index<T> index) { if (index.size() < counts.length) throw new IllegalArgumentException("Index not large enough to name all the array elements!"); Counter<T> c = new ClassicCounter<>(); for (int i = 0; i < counts.length; i++) { if (counts[i] != 0.0) c.setCount(index.get(i), counts[i]); } return c; }
private short tagProject(short tag) { if (smoothTPIndex == null) { smoothTPIndex = new HashIndex<>(tagIndex); } if (tag < 0) { return tag; } else { String tagStr = smoothTPIndex.get(tag); String binStr = TP_PREFIX + smoothTP.project(tagStr); return (short) smoothTPIndex.addToIndex(binStr); } }
public ClassicCounter<L> numDatumsPerLabel(){ labels = trimToSize(labels); ClassicCounter<L> numDatums = new ClassicCounter<>(); for(int i : labels){ numDatums.incrementCount(labelIndex.get(i)); } return numDatums; }
private static <F, L> Counter<Pair<F, L>> makeWeightCounter(double[] weights, Index<Pair<F, L>> weightIndex) { Counter<Pair<F,L>> weightCounter = new ClassicCounter<>(); for (int i = 0; i < weightIndex.size(); i++) { if (weights[i] == 0) { continue; // no need to save 0 weights } weightCounter.setCount(weightIndex.get(i), weights[i]); } return weightCounter; }
private void updateCounters(Rule rule, Counter<String> symWeights, Counter<String> symCounts) { String label = stateIndex.get(rule.parent()); String basicCat = basicCategory(label); symWeights.incrementCount(basicCat, Math.exp(rule.score())); symCounts.incrementCount(basicCat); }
public Counter<E> condLogProbsGivenPrevious(int position, int[] prevlabels) { Counter<E> c = new ClassicCounter<>(); for (int i = 0, sz = classIndex.size(); i < sz; i++) { E label = classIndex.get(i); c.incrementCount(label, condLogProbGivenPrevious(position, i, prevlabels)); } return c; }
public Counter<E> logProbs(int position) { Counter<E> c = new ClassicCounter<>(); for (int i = 0, sz = classIndex.size(); i < sz; i++) { E label = classIndex.get(i); c.incrementCount(label, logProb(position, i)); } return c; }
public static <T> String toBiggestValuesFirstString(Counter<Integer> c, int k, Index<T> index) { PriorityQueue<Integer> pq = toPriorityQueue(c); PriorityQueue<T> largestK = new BinaryHeapPriorityQueue<>(); // while (largestK.size() < k && ((Iterator)pq).hasNext()) { //same as above while (largestK.size() < k && !pq.isEmpty()) { double firstScore = pq.getPriority(pq.getFirst()); int first = pq.removeFirst(); largestK.changePriority(index.get(first), firstScore); } return largestK.toString(); }