/** * Calculates the node's <i>number</i>, defined as the number of nodes traversed in a left-to-right, depth-first search of the * tree starting at {@code root} and ending at {@code this}. Returns -1 if {@code root} does not contain {@code this}. * @param root the root node of the relevant tree * @return the number of the current node, or -1 if {@code root} does not contain {@code this}. */ public int nodeNumber(Tree root) { MutableInteger i = new MutableInteger(1); if(nodeNumberHelper(root,i)) return i.intValue(); return -1; }
/** * Removes the given key from this Counter. Its count will now be 0 and it * will no longer be considered previously seen. */ public double remove(E key) { totalCount -= getCount(key); // subtract removed count from total (may be 0) MutableInteger val = map.remove(key); if (val == null) { return Double.NaN; } else { return val.doubleValue(); } }
/** * Sets the current count for the given key. This will wipe out any existing * count for that key. * <p> * To add to a count instead of replacing it, use * {@link #incrementCount(Object,int)}. */ public void setCount(E key, int count) { if (tempMInteger == null) { tempMInteger = new MutableInteger(); } tempMInteger.set(count); tempMInteger = map.put(key, tempMInteger); totalCount += count; if (tempMInteger != null) { totalCount -= tempMInteger.intValue(); } }
private Tree getNodeNumberHelper(MutableInteger i, int target) { int i1 = i.intValue(); if(i1 == target) return this; if(i1 > target) throw new IndexOutOfBoundsException("Error -- tree does not contain " + i + " nodes."); i.incValue(1); for (Tree kid : children()) { Tree temp = kid.getNodeNumberHelper(i, target); if(temp != null) return temp; } return null; }
/** * gets the <code>n</code>th terminal in <code>tree</code>. The first terminal is number zero. */ public static Tree getTerminal(Tree tree, int n) { return getTerminal(tree, new MutableInteger(0), n); }
final MutableInteger totalProcessed = new MutableInteger(0); final MutableInteger totalSkipped = new MutableInteger(0); final MutableInteger totalErrorAnnotating = new MutableInteger(0); totalSkipped.incValue(1); continue; totalSkipped.incValue(1); continue; totalSkipped.incValue(1); continue; logger.err("Skipping " + file.getName() + ": output file " + finalOutputFilename + " as it already exists. Don't use the noClobber option to override this."); synchronized (totalSkipped) { totalSkipped.incValue(1); totalProcessed.incValue(1); if (totalProcessed.intValue() % 1000 == 0) { logger.info("Processed " + totalProcessed + " documents"); if ((totalProcessed.intValue() + totalErrorAnnotating.intValue()) == files.size()) { totalErrorAnnotating.incValue(1); if ((totalProcessed.intValue() + totalErrorAnnotating.intValue()) == files.size()) {
/** * Returns the current count for the given key, which is 0 if it hasn't * been * seen before. This is a convenient version of {@code get} that casts * and extracts the primitive value. */ public int getIntCount(Object key) { MutableInteger count = map.get(key); if (count == null) { return defaultValue; // haven't seen this object before -> 0 count } return count.intValue(); }
final boolean randomize = Boolean.parseBoolean(properties.getProperty("randomize", "false")); final MutableInteger totalProcessed = new MutableInteger(0); final MutableInteger totalSkipped = new MutableInteger(0); final MutableInteger totalErrorAnnotating = new MutableInteger(0); int nFiles = 0; totalSkipped.incValue(1); continue; totalSkipped.incValue(1); continue; totalSkipped.incValue(1); continue;
private boolean nodeNumberHelper(Tree t, MutableInteger i) { if (this == t) { return true; } i.incValue(1); for (Tree kid : t.children()) { if (nodeNumberHelper(kid, i)) return true; } return false; }
public Object object(int n) { tempInt.set(n); return intToObject.get(tempInt); }
/** Return the total pipeline annotation time in milliseconds. * * @return The total pipeline annotation time in milliseconds */ protected long getTotalTime() { long total = 0; for (MutableInteger m: accumulatedTime) { total += m.longValue(); } return total; }
/** * Adds the given count to the current count for the given key. If the key * hasn't been seen before, it is assumed to have count 0, and thus this * method will set its count to the given amount. Negative increments are * equivalent to calling {@code decrementCount}. * <p> * To more conveniently increment the count by 1, use * {@link #incrementCount(Object)}. * <p> * To set a count to a specific value instead of incrementing it, use * {@link #setCount(Object,int)}. */ public int incrementCount(E key, int count) { if (tempMInteger == null) { tempMInteger = new MutableInteger(); } MutableInteger oldMInteger = map.put(key, tempMInteger); totalCount += count; if (oldMInteger != null) { count += oldMInteger.intValue(); } tempMInteger.set(count); tempMInteger = oldMInteger; return count; }
/** * Assigns span indices (BeginIndexAnnotation and EndIndexAnnotation) to all nodes in a tree. * The beginning index is equivalent to the IndexAnnotation of the first leaf in the constituent. * The end index is equivalent to the first integer after the IndexAnnotation of the last leaf in the constituent. * * @param startIndex Begin indexing at this value */ public Pair<Integer, Integer> indexSpans(MutableInteger startIndex) { int start = Integer.MAX_VALUE; int end = Integer.MIN_VALUE; if(isLeaf()){ start = startIndex.intValue(); end = startIndex.intValue() + 1; startIndex.incValue(1); } else { for (Tree kid : children()) { Pair<Integer, Integer> span = kid.indexSpans(startIndex); if(span.first < start) start = span.first; if(span.second > end) end = span.second; } } Label label = label(); if (label instanceof CoreMap) { CoreMap afl = (CoreMap) label(); afl.set(CoreAnnotations.BeginIndexAnnotation.class, start); afl.set(CoreAnnotations.EndIndexAnnotation.class, end); } return new Pair<>(start, end); }
/** * Fetches the {@code i}th node in the tree, with node numbers defined * as in {@link #nodeNumber(Tree)}. * * @param i the node number to fetch * @return the {@code i}th node in the tree * @throws IndexOutOfBoundsException if {@code i} is not between 1 and * the number of nodes (inclusive) contained in {@code this}. */ public Tree getNodeNumber(int i) { return getNodeNumberHelper(new MutableInteger(1),i); }
final MutableInteger totalProcessed = new MutableInteger(0); final MutableInteger totalSkipped = new MutableInteger(0); final MutableInteger totalErrorAnnotating = new MutableInteger(0); totalSkipped.incValue(1); continue; totalSkipped.incValue(1); continue; totalSkipped.incValue(1); continue; logger.err("Skipping " + file.getName() + ": output file " + finalOutputFilename + " as it already exists. Don't use the noClobber option to override this."); synchronized (totalSkipped) { totalSkipped.incValue(1); totalProcessed.incValue(1); if (totalProcessed.intValue() % 1000 == 0) { logger.info("Processed " + totalProcessed + " documents"); if ((totalProcessed.intValue() + totalErrorAnnotating.intValue()) == files.size()) { totalErrorAnnotating.incValue(1); if ((totalProcessed.intValue() + totalErrorAnnotating.intValue()) == files.size()) {
/** * Returns the current count for the given key, which is 0 if it hasn't * been * seen before. This is a convenient version of <code>get</code> that casts * and extracts the primitive value. */ public int getIntCount(Object key) { MutableInteger count = map.get(key); if (count == null) { return defaultValue; // haven't seen this object before -> 0 count } return count.intValue(); }
private boolean nodeNumberHelper(Tree t, MutableInteger i) { if (this == t) { return true; } i.incValue(1); for (Tree kid : t.children()) { if (nodeNumberHelper(kid, i)) return true; } return false; }
/** Return a String that gives detailed human-readable information about * how much time was spent by each annotator and by the entire annotation * pipeline. This String includes newline characters but does not end * with one, and so it is suitable to be printed out with a * <code>println()</code>. * * @return Human readable information on time spent in processing. */ public String timingInformation() { StringBuilder sb = new StringBuilder(); if (TIME) { sb.append("Annotation pipeline timing information:\n"); Iterator<MutableInteger> it = accumulatedTime.iterator(); long total = 0; for (Annotator annotator : annotators) { MutableInteger m = it.next(); sb.append(StringUtils.getShortClassName(annotator)).append(": "); sb.append(Timing.toSecondsString(m.longValue())).append(" sec.\n"); total += m.longValue(); } sb.append("TOTAL: ").append(Timing.toSecondsString(total)).append(" sec."); } return sb.toString(); }
static boolean leftEdge(Tree t, Tree t1, MutableInteger i) { if (t == t1) { return true; } else if (t1.isLeaf()) { int j = t1.yield().size(); // so that empties don't add size i.set(i.intValue() + j); return false; } else { for (Tree kid : t1.children()) { if (leftEdge(t, kid, i)) { return true; } } return false; } }