gnu.trove.TObjectIntIterator Java Examples
The following examples show how to use
gnu.trove.TObjectIntIterator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CandidateFrameElementFilters.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
public void itemizeCandidates() { candidates = new THashSet<String>(); IntCounter<String> counts = new IntCounter<String>(); for (DataPointWithElements p : mData) { for (Range fillerSpanRange : p.getOvertFrameElementFillerSpans()) { String ss = getSufficientStatistics(p.getParses().getBestParse(), fillerSpanRange); counts.increment(ss); } } for (TObjectIntIterator<String> iter = counts.getIterator(); iter.hasNext();) { iter.advance(); if (iter.value()>=mMinCount) candidates.add(iter.key()); } }
Example #2
Source File: IntCounterMap.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
/** * If {@code this} is an {@link IntCounterMap} of the form <code> { a => { b => c } } </code>, * returns a new {@link IntCounterMap} of the form <code> { b => { a => c } } </code>. */ public IntCounterMap<L,K> invert() { IntCounterMap<L,K> invertedMap = new IntCounterMap<L,K>(); for (Map.Entry<K,IntCounter<L>> item : this.entrySet()) { K key1 = item.getKey(); IntCounter<L> counter = item.getValue(); for (TObjectIntIterator<L> iter = counter.getIterator(); iter.hasNext();) { iter.advance(); L key2 = iter.key(); int value = iter.value(); invertedMap.set(key2, key1, value); } } return invertedMap; }
Example #3
Source File: IntCounter.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
/** * @param valueThreshold * @return New IntCounter containing only entries whose value equals or exceeds the given threshold */ public IntCounter<T> filter(int valueThreshold) { IntCounter<T> result = new IntCounter<T>(); for (TObjectIntIterator<T> iter = getIterator(); iter.hasNext();) { iter.advance(); T key = iter.key(); int value = getT(key); if (value >= valueThreshold) { result.set(key, value); } } int nullValue = getT(null); if (containsKey(null) && nullValue >= valueThreshold) result.set(null, nullValue); return result; }
Example #4
Source File: IntCounter.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
/** * @param valueThreshold * @return Set of keys whose corresponding value equals or exceeds the given threshold */ public Set<T> filteredKeys(int valueThreshold) { Set<T> result = new THashSet<T>(); for (TObjectIntIterator<T> iter = getIterator(); iter.hasNext();) { iter.advance(); T key = iter.key(); int value = getT(key); if (value >= valueThreshold) { result.add(key); } } if (containsKey(null) && getT(null) >= valueThreshold) result.add(null); return result; }
Example #5
Source File: IntCounter.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
/** * Returns a new counter containing only keys with nonzero values in * both this and 'that'. Each key's value is the sum of its corresponding * values in this and 'that'. */ public IntCounter<T> andWith(IntCounter<T> that) { IntCounter<T> result = new IntCounter<T>(); for (TObjectIntIterator<T> iter = this.getIterator(); iter.hasNext();) { iter.advance(); if (iter.value()!=0 && that.getCount(iter.key())!=0) result.set(iter.key(), iter.value() + that.getCount(iter.key())); } return result; }
Example #6
Source File: Enumerator.java From consulo with Apache License 2.0 | 5 votes |
public String toString() { StringBuffer buffer = new StringBuffer(); for( TObjectIntIterator<T> iter = myNumbers.iterator(); iter.hasNext(); ) { iter.advance(); buffer.append(Integer.toString(iter.value()) + ": " + iter.key().toString() + "\n"); } return buffer.toString(); }
Example #7
Source File: IntCounter.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
public Counter<T> toCounter() { TObjectDoubleHashMap<T> map = new TObjectDoubleHashMap<T>(); for (TObjectIntIterator<T> iter = getIterator(); iter.hasNext();) { iter.advance(); map.put(iter.key(), (double)iter.value()); } if (containsKey(null)) map.put(null, (double)getT(null)); return new Counter<T>(map); }
Example #8
Source File: IntCounter.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
/** * @return A map from unique values in this IntCounter to the number of distinct keys with which they are associated */ public IntCounter<Integer> getHistogram() { IntCounter<Integer> histogram = new IntCounter<Integer>(); for (TObjectIntIterator<T> iter = getIterator(); iter.hasNext();) { iter.advance(); int value = iter.value(); histogram.increment(value); } if (containsKey(null)) histogram.increment(getT(null)); return histogram; }
Example #9
Source File: IntCounter.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
/** * @param factor Scaling factor to be multiplied by each value in this counter * @return A new Counter instance equivalent to this one, but with scaled values */ public Counter<T> scaleBy(double factor) { Counter<T> result = new Counter<T>(); for (TObjectIntIterator<T> iter = getIterator(); iter.hasNext();) { iter.advance(); result.set(iter.key(), iter.value() * factor); } if (containsKey(null)) result.set(null, getT(null)*factor); return result; }
Example #10
Source File: IntCounter.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
/** * @param factor Scaling factor to be multiplied by each value in this counter * @return A new Counter instance equivalent to this one, but with scaled values */ public IntCounter<T> scaleBy(int factor) { IntCounter<T> result = new IntCounter<T>(); for (TObjectIntIterator<T> iter = getIterator(); iter.hasNext();) { iter.advance(); result.set(iter.key(), iter.value() * factor); } if (containsKey(null)) result.set(null, getT(null)*factor); return result; }
Example #11
Source File: TroveFeaturesDB.java From jatecs with GNU General Public License v3.0 | 5 votes |
public void removeFeatures(IIntIterator removedFeatures) { int shift = 0; int lastGoodFeature = 0; int totalFeatures = _featuresMap.size(); TIntIntHashMap featuresRemap = new TIntIntHashMap(); while (removedFeatures.hasNext()) { int removedFeature = removedFeatures.next(); while (lastGoodFeature < removedFeature) { featuresRemap.put(lastGoodFeature, lastGoodFeature - shift); ++lastGoodFeature; } lastGoodFeature = removedFeature + 1; int removedFeaturePosition = removedFeature - shift; _featuresMap.remove(_featuresRMap.get(removedFeaturePosition)); _featuresRMap.remove(removedFeaturePosition); ++shift; } while (lastGoodFeature < totalFeatures) { featuresRemap.put(lastGoodFeature, lastGoodFeature - shift); ++lastGoodFeature; } TObjectIntIterator<String> mapIter = _featuresMap.iterator(); while (mapIter.hasNext()) { mapIter.advance(); int value = mapIter.value(); int newvalue = featuresRemap.get(value); mapIter.setValue(newvalue); } }
Example #12
Source File: IntCounter.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
/** * Returns a new counter containing only keys with nonzero values in * at least one of the provided counters. Each key's value is the * number of counters in which it occurs. */ public static <T> IntCounter<T> or(Collection<IntCounter<? extends T>> counters) { IntCounter<T> result = new IntCounter<T>(); for (IntCounter<? extends T> counter : counters) { for (TObjectIntIterator<? extends T> iter = counter.getIterator(); iter.hasNext();) { iter.advance(); if (iter.value()!=0) result.increment(iter.key()); } } return result; }
Example #13
Source File: IntCounter.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
public void incrementAllBy(IntCounter<? extends T> counts) { for (TObjectIntIterator<? extends T> iter = counts.getIterator(); iter.hasNext();) { iter.advance(); this.incrementBy(iter.key(), iter.value()); } if (counts.containsKey(null)) this.incrementBy(null, counts.getCount(null)); }
Example #14
Source File: IntCounter.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
public void incrementAllBy(int delta) { for (TObjectIntIterator<T> iter = getIterator(); iter.hasNext();) { iter.advance(); this.incrementBy(iter.key(), delta); } }
Example #15
Source File: IntCounterMap.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
/** * If {@code this} is a {@link IntCounterMap} of the form <code> { a => { b => c } } </code>, * returns a new {@link IntCounterMap} of the form <code> { b => {c => # } } </code> * where for every {@code b}, {@code #} is the number of {@code a}'s for which {@code this[a][b]==c } */ public IntCounterMap<L,Integer> getAggregateHistogram() { IntCounterMap<L,Integer> aggregateHistogram = new IntCounterMap<L,Integer>(); for (IntCounter<L> counter : this.values()) { for (TObjectIntIterator<L> iter = counter.getIterator(); iter.hasNext();) { iter.advance(); L key = iter.key(); int value = iter.value(); aggregateHistogram.increment(key, value); } } return aggregateHistogram; }
Example #16
Source File: TroveFeaturesDB.java From jatecs with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") public IFeatureDB cloneDB() { TroveFeaturesDB featuresDB = new TroveFeaturesDB(); featuresDB._name = new String(_name); TObjectIntIterator<String> iterator = _featuresMap.iterator(); while (iterator.hasNext()) { iterator.advance(); featuresDB._featuresMap.put(iterator.key(), iterator.value()); } featuresDB._featuresRMap = (Vector<String>) _featuresRMap.clone(); return featuresDB; }
Example #17
Source File: IntCounter.java From semafor-semantic-parser with GNU General Public License v3.0 | 4 votes |
/** * @return Iterator for the counter. Ignores the {@code null} key (if present). */ public TObjectIntIterator<T> getIterator() { return m_map.iterator(); }