List of usage examples for com.google.common.collect Maps newIdentityHashMap
public static <K, V> IdentityHashMap<K, V> newIdentityHashMap()
From source file:edu.byu.nlp.data.app.AnnotationStream2Csv.java
public static void main(String[] args) throws IOException { // parse CLI arguments new ArgumentParser(AnnotationStream2Csv.class).parseArgs(args); Preconditions.checkNotNull(jsonStream, "You must provide a valid --json-stream!"); Dataset data = readData(jsonStream); // optionally aggregate by instance String header = "annotator,start,end,annotation,label,source,num_correct_annotations,num_annotations,cum_num_annotations,num_annotators,cum_num_annotators\n"; // iterate over instances and (optionally) annotations final StringBuilder bld = new StringBuilder(); switch (row) { case ANNOTATION: // sort all annotations by end time Map<FlatInstance<SparseFeatureVector, Integer>, DatasetInstance> ann2InstMap = Maps .newIdentityHashMap();/*from ww w . j av a 2 s . co m*/ List<FlatInstance<SparseFeatureVector, Integer>> annotationList = Lists.newArrayList(); for (DatasetInstance inst : data) { for (FlatInstance<SparseFeatureVector, Integer> ann : inst.getAnnotations().getRawAnnotations()) { ann2InstMap.put(ann, inst); // record instance of each annotations annotationList.add(ann); } } Collections.sort(annotationList, new Comparator<FlatInstance<SparseFeatureVector, Integer>>() { @Override public int compare(FlatInstance<SparseFeatureVector, Integer> o1, FlatInstance<SparseFeatureVector, Integer> o2) { // no null checking since we want to fail if annotation time is not set. return Long.compare(o1.getEndTimestamp(), o2.getEndTimestamp()); } }); Set<Integer> annotators = Sets.newHashSet(); for (Enumeration<FlatInstance<SparseFeatureVector, Integer>> item : Iterables2 .enumerate(annotationList)) { FlatInstance<SparseFeatureVector, Integer> ann = item.getElement(); DatasetInstance inst = ann2InstMap.get(ann); annotators.add(ann.getAnnotator()); bld.append(ann.getAnnotator() + ","); bld.append(ann.getStartTimestamp() + ","); bld.append(ann.getEndTimestamp() + ","); bld.append(ann.getAnnotation() + ","); bld.append(inst.getLabel() + ","); bld.append( data.getInfo().getIndexers().getInstanceIdIndexer().get(inst.getInfo().getSource()) + ","); bld.append((!inst.hasLabel() ? "NA" : ann.getAnnotation() == inst.getLabel() ? 1 : 0) + ","); // num correct bld.append(1 + ","); // num annotations bld.append((item.getIndex() + 1) + ","); // cumulative num annotations bld.append(1 + ","); // num annotators bld.append(annotators.size() + ""); // cumulative num annotators bld.append("\n"); } break; case INSTANCE: int cumNumAnnotations = 0; for (DatasetInstance inst : data) { cumNumAnnotations += inst.getInfo().getNumAnnotations(); int numCorrectAnnotations = 0; // sum over all the annotators who put the correct answer (if available) if (inst.hasLabel()) { Integer correctLabel = inst.getLabel(); for (int j = 0; j < data.getInfo().getNumAnnotators(); j++) { numCorrectAnnotations += inst.getAnnotations().getLabelAnnotations() .getRow(j)[correctLabel]; } } bld.append("NA,"); bld.append("NA,"); bld.append("NA,"); bld.append("NA,"); bld.append(inst.getLabel() + ","); bld.append(inst.getInfo().getSource() + ","); bld.append(numCorrectAnnotations + ","); bld.append(inst.getInfo().getNumAnnotations() + ","); bld.append(cumNumAnnotations + ","); bld.append(inst.getInfo().getNumAnnotators() + ","); bld.append("NA"); // cumulative num annotators bld.append("\n"); } break; case ANNOTATOR: Multiset<Integer> perAnnotatorAnnotationCounts = HashMultiset.create(); Multiset<Integer> perAnnotatorCorrectAnnotationCounts = HashMultiset.create(); for (DatasetInstance inst : data) { for (FlatInstance<SparseFeatureVector, Integer> ann : inst.getAnnotations().getRawAnnotations()) { int annotatorId = ann.getAnnotator(); perAnnotatorAnnotationCounts.add(annotatorId); if (inst.getLabel() == ann.getAnnotation()) { perAnnotatorCorrectAnnotationCounts.add(annotatorId); } } } for (String annotatorId : data.getInfo().getAnnotatorIdIndexer()) { bld.append(annotatorId + ","); bld.append("NA,"); bld.append("NA,"); bld.append("NA,"); bld.append("NA,"); bld.append("NA,"); bld.append(perAnnotatorCorrectAnnotationCounts.count(annotatorId) + ","); bld.append(perAnnotatorAnnotationCounts.count(annotatorId) + ","); bld.append("NA,"); bld.append("1,"); // num annotators bld.append("NA"); // cumulative num annotators bld.append("\n"); } break; default: Preconditions.checkArgument(false, "unknown row type: " + row); break; } // output to console if (out == null) { System.out.println(header); System.out.println(bld.toString()); } else { File outfile = new File(out); Files.write(header, outfile, Charsets.UTF_8); Files.append(bld, outfile, Charsets.UTF_8); } }
From source file:edu.washington.cs.cupid.capability.CapabilityArguments.java
public CapabilityArguments() { arguments = Maps.newIdentityHashMap(); }
From source file:edu.washington.cs.cupid.capability.CapabilityArguments.java
public CapabilityArguments(ICapabilityArguments other) { arguments = Maps.newIdentityHashMap(); arguments.putAll(other.getArguments()); }
From source file:org.apache.kylin.metadata.filter.TsConditionEraser.java
public TsConditionEraser(TblColRef tsColumn, TupleFilter root) { this.tsColumn = tsColumn; this.root = root; this.isInTopLevelANDs = Maps.newIdentityHashMap(); }
From source file:com.google.gxp.compiler.util.ClassMap.java
public ClassMap() { this.map = Maps.newIdentityHashMap(); }
From source file:org.apache.kylin.metadata.filter.TimeConditionLiteralsReplacer.java
public TimeConditionLiteralsReplacer(TupleFilter root) { this.dateCompareTupleChildren = Maps.newIdentityHashMap(); }
From source file:org.onosproject.incubator.rpc.grpc.DeviceProviderRegistryClientProxy.java
DeviceProviderRegistryClientProxy(ManagedChannel channel) { this.channel = channel; pServices = Maps.newIdentityHashMap(); }
From source file:org.sonar.api.checks.checkers.MessageDispatcher.java
public MessageDispatcher(SensorContext context) { this.context = context; checkersByCheck = Maps.newIdentityHashMap(); checksByChecker = Maps.newIdentityHashMap(); }
From source file:org.sonatype.nexus.compat.EventBusApplicationEventMulticaster.java
@Inject public EventBusApplicationEventMulticaster(final EventBus eventBus) { this.eventBus = checkNotNull(eventBus); this.adapters = Maps.newIdentityHashMap(); }
From source file:co.cask.cdap.internal.io.ReflectionReader.java
protected ReflectionReader(Schema schema, TypeToken<TO> type) { this.creatorFactory = new InstantiatorFactory(true); this.creators = Maps.newIdentityHashMap(); this.fieldAccessorFactory = new ReflectionFieldAccessorFactory(); this.schema = schema; this.type = type; }