本文整理汇总了Java中it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap.addTo方法的典型用法代码示例。如果您正苦于以下问题:Java Object2IntOpenHashMap.addTo方法的具体用法?Java Object2IntOpenHashMap.addTo怎么用?Java Object2IntOpenHashMap.addTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
的用法示例。
在下文中一共展示了Object2IntOpenHashMap.addTo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: classify
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; //导入方法依赖的package包/类
@Override
public ClassLabel classify(O instance) {
Object2IntOpenHashMap<ClassLabel> count = new Object2IntOpenHashMap<>();
KNNList query = knnq.getKNNForObject(instance, k);
for(DoubleDBIDListIter neighbor = query.iter(); neighbor.valid(); neighbor.advance()) {
count.addTo(labelrep.get(neighbor), 1);
}
int bestoccur = Integer.MIN_VALUE;
ClassLabel bestl = null;
for(ObjectIterator<Entry<ClassLabel>> iter = count.object2IntEntrySet().fastIterator(); iter.hasNext();) {
Entry<ClassLabel> entry = iter.next();
if(entry.getIntValue() > bestoccur) {
bestoccur = entry.getIntValue();
bestl = entry.getKey();
}
}
return bestl;
}
示例2: close
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; //导入方法依赖的package包/类
@Override
public void close() {
synchronized(LuceneLinkTokenizer.this) {
Object2IntOpenHashMap<String> plinks = LuceneLinkTokenizer.this.links;
if(plinks.size() == 0) {
LuceneLinkTokenizer.this.links = links;
}
else {
for(ObjectIterator<Object2IntOpenHashMap.Entry<String>> it = links.object2IntEntrySet().fastIterator(); it.hasNext();) {
Object2IntOpenHashMap.Entry<String> ent = it.next();
plinks.addTo(ent.getKey(), ent.getIntValue());
}
}
links = null;
}
}
示例3: countkNN
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; //导入方法依赖的package包/类
/**
* Counting helper for kNN classification.
*
* @param counters Counter storage
* @param l Object labels
* @return Maximum count
*/
public int countkNN(Object2IntOpenHashMap<Object> counters, Object l) {
// Count each label, return maximum.
if(l instanceof LabelList) {
LabelList ll = (LabelList) l;
int m = 0;
for(int i = 0, e = ll.size(); i < e; i++) {
m = Math.max(m, counters.addTo(ll.get(i), 1));
}
return m;
}
return counters.addTo(l, 1);
}
示例4: update
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; //导入方法依赖的package包/类
/**
* Merge second counter set.
*
* @param other Other set of counters.
*/
public static <O> void update(Object2IntOpenHashMap<O> first, Object2IntOpenHashMap<O> second) {
for(Iterator<Object2IntMap.Entry<O>> iter = second.object2IntEntrySet().fastIterator(); iter.hasNext();) {
Object2IntMap.Entry<O> entry = iter.next();
second.addTo(entry.getKey(), entry.getIntValue());
}
}
示例5: countAllPhrases
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; //导入方法依赖的package包/类
private Map<String, Integer> countAllPhrases(String textInputFile) throws IOException {
Object2IntOpenHashMap<String> phraseCounts = new Object2IntOpenHashMap<>();
BufferedReader rdr = new BufferedReader(new FileReader(textInputFile));
while (rdr.ready()) {
String line = rdr.readLine();
List<String> phrases = splitLineInPhrases(line);
for (String phrase : phrases) {
phraseCounts.addTo(phrase, 1);
}
}
rdr.close();
return phraseCounts;
}
示例6: main
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; //导入方法依赖的package包/类
/**
* Creates the language model data structure given a file with the format
* Type <TAB> (frequency, words), (frequency, words) ... Type <TAB>
* (frequency, words), (frequency, words) ... ....
*
* @param args command line arguments
* @throws JSAPException
* @throws IOException
*/
public static void main( String args[] ) throws JSAPException, IOException {
SimpleJSAP jsap = new SimpleJSAP( TypeLanguageModel.class.getName(), "Language model for types builder", new Parameter[]{ new FlaggedOption( "input", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'i', "input", "Input file" ), new FlaggedOption( "output", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'o', "output", "File to serialize the data structure" ), } );
JSAPResult jsapResult = jsap.parse( args );
if( jsap.messagePrinted() ) return;
final BufferedReader lines = new BufferedReader( new FileReader( jsapResult.getString( "input" ) ) );
Object2ObjectLinkedOpenHashMap<String, Object2IntOpenHashMap<String>> languageModels = new Object2ObjectLinkedOpenHashMap<String, Object2IntOpenHashMap<String>>();
Object2IntOpenHashMap<String> freqs = new Object2IntOpenHashMap<String>();
Object2IntOpenHashMap<String> background = new Object2IntOpenHashMap<String>();
int totalFreq = 0;
String line = "";
while( ( line = lines.readLine() ) != null ) {
String[] parts = line.split( "\t" );
Object2IntOpenHashMap<String> typeHash = languageModels.get( parts[ 0 ] );
if( typeHash == null ) {
typeHash = new Object2IntOpenHashMap<String>();
languageModels.put( parts[ 0 ], typeHash );
freqs.put( parts[ 0 ], 0 );
}
String[] scoreAndModifier = parts[ 1 ].split( "," );
Integer freqI = 0;
for( String s : scoreAndModifier ) {
Matcher m = Pattern.compile( "(\\()(.+)" ).matcher( s ); // freq
if( m.find() ) {
Double freqD = ( Double.parseDouble( m.group( 2 ) ) ); //might break if input is ill-formed
freqI = freqD.intValue();
}
m = Pattern.compile( "(.+?)(\\))" ).matcher( s );
if( m.find() ) { //words
String[] tmpQ = Normalize.normalize( m.group( 1 ) ).trim().split( "\\s" );
//generate unigrams + bigrams + trigrams
for( String queryS : getTrigrams( tmpQ ) ) {
Integer freq = typeHash.get( queryS );
if( freq == null ) {
typeHash.put( queryS, 0 );
background.put( queryS, 0 );
}
freqs.addTo( parts[ 0 ], freqI );
typeHash.addTo( queryS, freqI );
background.addTo( queryS, freqI );
totalFreq += freqI;
}
}
}
}
lines.close();
TypeLanguageModel model = new TypeLanguageModel();
model.languageModels = languageModels;
model.freqs = freqs;
model.totalFreq = totalFreq;
model.backgroundModel = background;
BinIO.storeObject( model, jsapResult.getString( "output" ) );
}