本文整理汇总了Java中gnu.trove.map.hash.TObjectIntHashMap.adjustOrPutValue方法的典型用法代码示例。如果您正苦于以下问题:Java TObjectIntHashMap.adjustOrPutValue方法的具体用法?Java TObjectIntHashMap.adjustOrPutValue怎么用?Java TObjectIntHashMap.adjustOrPutValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.trove.map.hash.TObjectIntHashMap
的用法示例。
在下文中一共展示了TObjectIntHashMap.adjustOrPutValue方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: diagnostics
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
@SubscribeEvent(priority = EventPriority.LOW)
public void diagnostics(final DiagnosticEvent.Gather event) {
final TObjectIntHashMap<String> counts = new TObjectIntHashMap<String>();
final Iterator<Entry<String, ISound>> iterator = this.playingSounds.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, ISound> entry = iterator.next();
ISound isound = entry.getValue();
counts.adjustOrPutValue(isound.getSound().getSoundLocation().toString(), 1, 1);
}
final ArrayList<String> results = new ArrayList<String>();
final TObjectIntIterator<String> itr = counts.iterator();
while (itr.hasNext()) {
itr.advance();
results.add(String.format(TextFormatting.GOLD + "%s: %d", itr.key(), itr.value()));
}
Collections.sort(results);
event.output.addAll(results);
}
示例2: postprocessQuery
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
/**
* This method represents the last step that's executed when processing a query. A list of partial-results (DistanceElements) returned by
* the lookup stage is processed based on some internal method and finally converted to a list of ScoreElements. The filtered list of
* ScoreElements is returned by the feature module during retrieval.
*
* @param partialResults List of partial results returned by the lookup stage.
* @param qc A ReadableQueryConfig object that contains query-related configuration parameters.
* @return List of final results. Is supposed to be de-duplicated and the number of items should not exceed the number of items per module.
*/
@Override
protected List<ScoreElement> postprocessQuery(List<SegmentDistanceElement> partialResults, ReadableQueryConfig qc) {
/* Prepare helper data-structures. */
final List<ScoreElement> results = new ArrayList<>();
final TObjectIntHashMap<String> scoreMap = new TObjectIntHashMap<>();
/* Set QueryConfig and extract correspondence function. */
qc = this.setQueryConfig(qc);
final CorrespondenceFunction correspondence = qc.getCorrespondenceFunction().orElse(this.linearCorrespondence);
for (DistanceElement hit : partialResults) {
if (hit.getDistance() < this.distanceThreshold) {
scoreMap.adjustOrPutValue(hit.getId(), 1, scoreMap.get(hit.getId())/2);
}
}
/* Prepare final result-set. */
scoreMap.forEachEntry((key, value) -> results.add(new SegmentScoreElement(key, 1.0 - 1.0/value)));
ScoreElement.filterMaximumScores(results.stream());
return results;
}
示例3: addDocument
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
@Override
public void addDocument(Document doc) throws IOException {
// add the document
lengths.get(document).add(doc.identifier, doc.terms.size());
// now deal with fields:
TObjectIntHashMap<Bytes> currentFieldLengths = new TObjectIntHashMap<>(doc.tags.size());
for (Tag tag : doc.tags) {
int len = tag.end - tag.begin;
currentFieldLengths.adjustOrPutValue(new Bytes(ByteUtil.fromString(tag.name)), len, len);
}
for (Bytes field : currentFieldLengths.keySet()) {
if (!lengths.containsKey(field)) {
lengths.put(field, new FieldLengthList(field));
}
lengths.get(field).add(doc.identifier, currentFieldLengths.get(field));
}
}
示例4: getBagOfWords
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
public TObjectIntHashMap<String> getBagOfWords() {
TObjectIntHashMap<String> termCounts = new TObjectIntHashMap<>();
for(String term : terms) {
termCounts.adjustOrPutValue(term, 1, 1);
}
return termCounts;
}
示例5: process
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
@Override
public void process(Document doc) throws IOException {
processor.process(new FieldLengthData(ByteUtil.fromString("document"), doc.identifier, doc.terms.size()));
TObjectIntHashMap<String> fieldLengths = new TObjectIntHashMap<>();
for (Tag tag : doc.tags) {
int len = tag.end - tag.begin;
fieldLengths.adjustOrPutValue(tag.name, len, len);
}
for (String field : fieldLengths.keySet()) {
processor.process(new FieldLengthData(ByteUtil.fromString(field), doc.identifier, fieldLengths.get(field)));
}
}
示例6: testOrderedWindowFeaturer
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
@Test
public void testOrderedWindowFeaturer() throws IOException, NoSuchAlgorithmException, IncompatibleProcessorException {
ArrayListTupleflowSink<TextFeature> catcher = new ArrayListTupleflowSink<>();
// first try bi-grams ~(#od:1(a b))
WindowFeaturer featurer = new WindowFeaturer(new FakeParameters(Parameters.create()));
featurer.setProcessor( catcher );
for(int i =0 ; i < 1000 ; i++){
featurer.process( new Window( 0,i,1,2,3, ByteUtil.fromString("word-" + i)) );
}
TObjectIntHashMap<byte[]> collisions = new TObjectIntHashMap<>();
for( TextFeature t : catcher.data ){
collisions.adjustOrPutValue(t.feature, 1, 1);
}
int c = 0;
for( int val : collisions.values() ){
if(val > 1){
c++;
}
}
assert (c == 0);
}
示例7: search
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
/**
* Search for a given image (represented by its features) in the database
*
* @param features
* the features
* @return the list of matching images and their scores (bigger == more
* chance of match)
*/
public List<ObjectIntPair<T>> search(int[][] features) {
final TObjectIntHashMap<T> counter = new TObjectIntHashMap<>();
for (final int[] sketch : features) {
for (int i = 0; i < sketch.length; i++) {
final int sk = sketch[i];
final Set<T> s = database.get(i).get(sk);
if (s != null) {
for (final T key : s) {
counter.adjustOrPutValue(key, 1, 1);
}
}
}
}
final List<ObjectIntPair<T>> result = new ArrayList<>();
counter.forEachEntry(new TObjectIntProcedure<T>() {
@Override
public boolean execute(T a, int b) {
if (b > minScore)
result.add(ObjectIntPair.pair(a, b));
return false;
}
});
Collections.sort(result, new Comparator<ObjectIntPair<T>>() {
@Override
public int compare(ObjectIntPair<T> o1, ObjectIntPair<T> o2) {
return Integer.compare(o2.second, o1.second);
}
});
return result;
}
示例8: train
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
@Override
public void train(List<? extends Annotated<OBJECT, ANNOTATION>> data) {
final TIntIntHashMap nAnnotationCounts = new TIntIntHashMap();
final TObjectIntHashMap<ANNOTATION> annotationCounts = new TObjectIntHashMap<ANNOTATION>();
int maxVal = 0;
for (final Annotated<OBJECT, ANNOTATION> sample : data) {
final Collection<ANNOTATION> annos = sample.getAnnotations();
for (final ANNOTATION s : annos) {
annotationCounts.adjustOrPutValue(s, 1, 1);
}
nAnnotationCounts.adjustOrPutValue(annos.size(), 1, 1);
if (annos.size() > maxVal)
maxVal = annos.size();
}
// build distribution and rng for each annotation
annotations = new ArrayList<ANNOTATION>();
final TDoubleArrayList probs = new TDoubleArrayList();
annotationCounts.forEachEntry(new TObjectIntProcedure<ANNOTATION>() {
@Override
public boolean execute(ANNOTATION a, int b) {
annotations.add(a);
probs.add(b);
return true;
}
});
annotationProbability = new EmpiricalWalker(probs.toArray(), Empirical.NO_INTERPOLATION, new MersenneTwister());
numAnnotations.train(data);
}
示例9: annotate
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
@Override
public List<ScoredAnnotation<ANNOTATION>> annotate(final OBJECT object) {
if (this.nn == null)
this.nn = new ObjectNearestNeighboursExact<FEATURE>(this.features, this.comparator);
final TObjectIntHashMap<ANNOTATION> selected = new TObjectIntHashMap<ANNOTATION>();
final List<FEATURE> queryfv = new ArrayList<FEATURE>(1);
queryfv.add(this.extractor.extractFeature(object));
final int[][] indices = new int[1][this.k];
final float[][] distances = new float[1][this.k];
this.nn.searchKNN(queryfv, this.k, indices, distances);
int count = 0;
for (int i = 0; i < this.k; i++) {
// Distance check
if (distances[0][i] > this.threshold) {
continue;
}
final Collection<ANNOTATION> anns = this.annotations.get(indices[0][i]);
for (final ANNOTATION ann : anns) {
selected.adjustOrPutValue(ann, 1, 1);
count++;
}
}
final TObjectIntIterator<ANNOTATION> iterator = selected.iterator();
final List<ScoredAnnotation<ANNOTATION>> result = new ArrayList<ScoredAnnotation<ANNOTATION>>(selected.size());
while (iterator.hasNext()) {
iterator.advance();
result.add(new ScoredAnnotation<ANNOTATION>(iterator.key(), (float) iterator.value() / (float) count));
}
return result;
}
示例10: findMatches
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
@Override
public boolean findMatches(List<T> queryfeatures) {
matches = new ArrayList<Pair<T>>();
final TObjectIntHashMap<T> targets = new TObjectIntHashMap<T>();
for (final T query : queryfeatures) {
final T modeltarget = findMatch(query, modelKeypoints);
if (modeltarget == null)
continue;
final T querytarget = findMatch(modeltarget, queryfeatures);
if (querytarget == query) {
matches.add(new Pair<T>(query, modeltarget));
targets.adjustOrPutValue(modeltarget, 1, 1);
}
}
final ArrayList<Pair<T>> matchesToRemove = new ArrayList<Pair<T>>();
targets.forEachEntry(new TObjectIntProcedure<T>() {
@Override
public boolean execute(T a, int b) {
if (b > 1) {
for (final Pair<T> p : matches) {
if (p.secondObject() == a)
matchesToRemove.add(p);
}
}
return true;
}
});
matches.removeAll(matchesToRemove);
return matches.size() > 0;
}
示例11: map
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
@Override
protected void map(LongWritable key, Text value,
Mapper<LongWritable, Text, LongWritable, BytesWritable>.Context context) throws java.io.IOException,
InterruptedException
{
List<String> tokens = null;
USMFStatus status = null;
DateTime time = null;
try {
final String svalue = value.toString();
status = new USMFStatus(options.getStatusType().type());
status.fillFromString(svalue);
if (status.isInvalid())
return;
if (!filters.filter(svalue))
return;
tokens = jsonPath.read(svalue);
if (tokens == null) {
context.getCounter(TextEntryType.INVALID_JSON).increment(1);
// System.err.println("Couldn't read the tokens from the tweet");
return;
}
if (tokens.size() == 0) {
context.getCounter(TextEntryType.INVALID_ZEROLENGTH).increment(1);
return; // Quietly quit, value exists but was empty
}
time = status.createdAt();
if (time == null) {
context.getCounter(TextEntryType.INVALID_TIME).increment(1);
// System.err.println("Time was null, this usually means the original tweet had no time. Skip this tweet.");
return;
}
} catch (final Exception e) {
// System.out.println("Couldn't get tokens from:\n" + value +
// "\nwith jsonpath:\n" + jsonPath);
return;
}
// Quantise the time to a specific index
final long timeIndex = (time.getMillis() / timeDeltaMillis) * timeDeltaMillis;
TweetCountWordMap timeWordMap = this.tweetWordMap.get(timeIndex);
// System.out.println("Tweet time: " + time.getMillis());
// System.out.println("Tweet timeindex: " + timeIndex);
if (timeWordMap == null) {
this.tweetWordMap.put(timeIndex, timeWordMap = new TweetCountWordMap());
}
final TObjectIntHashMap<String> tpMap = timeWordMap.getTweetWordMap();
timeWordMap.incrementTweetCount(1);
final List<String> seen = new ArrayList<String>();
for (final String token : tokens) {
// Apply stop words?
// Apply junk words?
// Already seen it?
if (seen.contains(token))
continue;
seen.add(token);
tpMap.adjustOrPutValue(token, 1, 1);
// if(token.equals("...")){
// System.out.println("TOKEN: " + token);
// System.out.println("TIME: " + timeIndex);
// System.out.println("NEW VALUE: " + newv);
// }
}
context.getCounter(TextEntryType.VALID).increment(1);
}