Search in sources :

Example 6 with MutableDouble

use of edu.stanford.nlp.util.MutableDouble in project CoreNLP by stanfordnlp.

the class ClassicCounter method incrementCount.

/** {@inheritDoc} */
@Override
public double incrementCount(E key, double count) {
    if (tempMDouble == null) {
        tempMDouble = new MutableDouble();
    }
    MutableDouble oldMDouble = map.put(key, tempMDouble);
    totalCount += count;
    if (oldMDouble != null) {
        count += oldMDouble.doubleValue();
    }
    tempMDouble.set(count);
    tempMDouble = oldMDouble;
    return count;
}
Also used : MutableDouble(edu.stanford.nlp.util.MutableDouble)

Example 7 with MutableDouble

use of edu.stanford.nlp.util.MutableDouble in project CoreNLP by stanfordnlp.

the class GeneralizedCounter method entrySet.

/* this is (non-tail) recursive right now, haven't figured out a way
  * to speed it up */
private Set<Map.Entry<Object, Double>> entrySet(Set<Map.Entry<Object, Double>> s, Object[] key, boolean useLists) {
    if (depth == 1) {
        //System.out.println("key is long enough to add to set");
        Set<K> keys = map.keySet();
        for (K finalKey : keys) {
            // array doesn't escape
            K[] newKey = ErasureUtils.<K>mkTArray(Object.class, key.length + 1);
            if (key.length > 0) {
                System.arraycopy(key, 0, newKey, 0, key.length);
            }
            newKey[key.length] = finalKey;
            MutableDouble value = (MutableDouble) map.get(finalKey);
            Double value1 = new Double(value.doubleValue());
            if (useLists) {
                s.add(new Entry<>(Arrays.asList(newKey), value1));
            } else {
                s.add(new Entry<>(newKey[0], value1));
            }
        }
    } else {
        Set<K> keys = map.keySet();
        //System.out.println("keyset level " + depth + " " + keys);
        for (K o : keys) {
            Object[] newKey = new Object[key.length + 1];
            if (key.length > 0) {
                System.arraycopy(key, 0, newKey, 0, key.length);
            }
            newKey[key.length] = o;
            //System.out.println("level " + key.length + " current key " + Arrays.asList(newKey));
            conditionalizeHelper(o).entrySet(s, newKey, true);
        }
    }
    //System.out.println("leaving key length " + key.length);
    return s;
}
Also used : MutableDouble(edu.stanford.nlp.util.MutableDouble) MutableDouble(edu.stanford.nlp.util.MutableDouble)

Aggregations

MutableDouble (edu.stanford.nlp.util.MutableDouble)7