本文整理汇总了Java中gnu.trove.map.hash.TObjectIntHashMap.keySet方法的典型用法代码示例。如果您正苦于以下问题:Java TObjectIntHashMap.keySet方法的具体用法?Java TObjectIntHashMap.keySet怎么用?Java TObjectIntHashMap.keySet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.trove.map.hash.TObjectIntHashMap
的用法示例。
在下文中一共展示了TObjectIntHashMap.keySet方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
}
示例2: writeData
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
public static void writeData(String file, TObjectIntHashMap<String> data){
BufferedWriter writer;
try {
writer = new BufferedWriter(new FileWriter(file));
for (String s : data.keySet()) {
writer.append(data.get(s) + "\t" + s);
writer.newLine();
}
writer.flush();
writer.close();
}
catch (Exception e){
e.printStackTrace();
}
}
示例3: write
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
public static void write(TObjectIntHashMap<String> uri_id,
boolean append, String outFile){
BufferedWriter writer;
try {
writer = new BufferedWriter(new FileWriter(outFile, append));
for (String s : uri_id.keySet()) {
writer.append(uri_id.get(s) + "\t" + s);
writer.newLine();
}
writer.flush();
writer.close();
}
catch (Exception e){
e.printStackTrace();
}
}
示例4: writeChunkCounts
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
private static <T> void writeChunkCounts(JsonWriter writer, String name, final TObjectIntHashMap<T> map, int max) throws IOException
{
List<T> sortedCoords = new ArrayList<T>(map.keySet());
Collections.sort(sortedCoords, new Comparator<T>()
{
@Override
public int compare(T s1, T s2)
{
return map.get(s2) - map.get(s1);
}
});
int i = 0;
writer.name(name).beginArray();
for (T key : sortedCoords)
{
if ((max > 0) && (i++ > max))
{
break;
}
if (map.get(key) < 5)
{
continue;
}
writer.beginObject();
writer.name("key").value(key.toString());
writer.name("count").value(map.get(key));
writer.endObject();
}
writer.endArray();
}
示例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: calculate
import gnu.trove.map.hash.TObjectIntHashMap; //导入方法依赖的package包/类
/**
* The input should be a {@link Map} for each rater where the keys represent
* all the subjects that were rated by the raters and the values represent
* the annotations given by the raters. Agreement between the raters is
* determined by {@link #equals(Object)} for the INSTANCE type. Annotations
* for subjects which are not in both sets are ignored.
*
* @see "http://en.wikipedia.org/wiki/Cohen's_kappa"
*
* @param rater1
* The annotations from rater 1
* @param rater2
* The annotations from rater 2
* @return Cohen's Kappa [0,1]
*/
public static <K, A> double calculate(
final Map<K, A> rater1,
final Map<K, A> rater2)
{
int totalCount = 0;
int agreementCount = 0;
final TObjectIntHashMap<A> answerCountsR1 = new TObjectIntHashMap<A>();
final TObjectIntHashMap<A> answerCountsR2 = new TObjectIntHashMap<A>();
for (final K subjectKey : rater1.keySet())
{
// We can only form an agreement if both raters rated this
// specific subject, so let's check
if (rater2.keySet().contains(subjectKey))
{
final A r1a = rater1.get(subjectKey);
final A r2a = rater2.get(subjectKey);
// It's possible that the key exists but is mapped to
// a null value (for example, if majority voting was used
// to generate the set and there was no majority).
if (r1a == null || r2a == null)
continue;
// Get the answers from the raters
final A annotation1 = r1a;
final A annotation2 = r2a;
// Count the agreements
if (annotation1.equals(annotation2))
agreementCount++;
// Count each of the answers for each of the raters
answerCountsR1.putIfAbsent(annotation1, 0);
answerCountsR2.putIfAbsent(annotation2, 0);
answerCountsR1.increment(annotation1);
answerCountsR2.increment(annotation2);
// Keep a running total
totalCount++;
}
}
System.out.println(answerCountsR1);
final double PrA = agreementCount / (double) totalCount;
System.out.println(PrA);
double PrE = 0;
for (final A ann : answerCountsR1.keySet())
{
final Integer i = answerCountsR2.get(ann);
final double PrAnnR1 = answerCountsR1.get(ann) / (double) totalCount;
final double PrAnnR2 = (i == null ? 0 : i) / (double) totalCount;
PrE += PrAnnR1 * PrAnnR2;
}
System.out.println(PrE);
final double kappa = (PrA - PrE) / (1d - PrE);
return kappa;
}