本文整理汇总了Java中com.bbn.bue.common.collections.CollectionUtils类的典型用法代码示例。如果您正苦于以下问题:Java CollectionUtils类的具体用法?Java CollectionUtils怎么用?Java CollectionUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CollectionUtils类属于com.bbn.bue.common.collections包,在下文中一共展示了CollectionUtils类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkValidity
import com.bbn.bue.common.collections.CollectionUtils; //导入依赖的package包/类
@Value.Check
protected void checkValidity() {
// no incomplete response may appear in any response set
final ImmutableSet<Response> allResponsesInSets = ImmutableSet.copyOf(
concat(responseSets()));
for (final Response incompleteResponse : incompleteResponses()) {
checkArgument(!allResponsesInSets.contains(incompleteResponse),
"A response may not be both completed and incomplete");
}
if (responseSetIds().isPresent()) {
for (final String id : responseSetIds().get().keySet()) {
checkArgument(!id.contains("-"), "Event frame IDs may not contain -s");
checkArgument(!id.contains("\t"), "Event frame IDs may not contain tabs");
}
// we can have an empty output file, verify that all the responseSets have an id
checkArgument(responseSets().size() == responseSetIds().get().size(),
"Response set IDs are missing");
checkArgument(responseSetIds().get().keySet().size() == responseSets().size(),
"All response set IDs must be unique");
CollectionUtils.assertSameElementsOrIllegalArgument(responseSets(),
responseSetIds().get().values(), "Response sets did not match IDs",
"Response sets in list", "Response sets in ID map");
}
}
示例2: check
import com.bbn.bue.common.collections.CollectionUtils; //导入依赖的package包/类
@Value.Check
protected void check() {
for (final TypeRoleFillerRealisSet eventFrame : eventFrames()) {
final Set<TypeRoleFillerRealis> intersection =
Sets.intersection(eventFrame.asSet(), incomplete());
checkArgument(intersection.isEmpty(), "A TRFR cannot be both incomplete and linked: %s",
intersection);
}
if (idsToEventFrames().isPresent()) {
for (final String id : idsToEventFrames().get().keySet()) {
checkArgument(!id.contains("-"), "Event frame IDs may not contain -s");
checkArgument(!id.contains("\t"), "Event frame IDs may not contain tabs");
}
CollectionUtils.assertSameElementsOrIllegalArgument(eventFrames(),
idsToEventFrames().get().values(), "Event frames did not match IDs",
"Event frames in list", "Event frames in ID map");
}
}
示例3: score
import com.bbn.bue.common.collections.CollectionUtils; //导入依赖的package包/类
/**
* Returns absent if the score is undefined (e.g. one side is all singletons).
*/
public Optional<FMeasureInfo> score(final Iterable<? extends Iterable<?>> predicted,
final Iterable<? extends Iterable<?>> gold) {
final List<Set<Object>> predictedAsSets = CorefScorerUtils.toSets(predicted);
final List<Set<Object>> goldAsSets = CorefScorerUtils.toSets(gold);
final Map<Object, Set<Object>> predictedItemToGroup =
CollectionUtils.makeElementsToContainersMap(predictedAsSets);
final Map<Object, Set<Object>> goldItemToGroup =
CollectionUtils.makeElementsToContainersMap(goldAsSets);
CorefScorerUtils.checkPartitionsOverSameElements(predictedItemToGroup.keySet(),
goldItemToGroup.keySet());
final Optional<Float> recall =
mucScoreComponent(goldAsSets, predictedAsSets, predictedItemToGroup);
final Optional<Float> precision =
mucScoreComponent(predictedAsSets, goldAsSets, goldItemToGroup);
if (recall.isPresent() && precision.isPresent()) {
// why are these floats?
return Optional.<FMeasureInfo>of(new PrecisionRecallPair(precision.get(), recall.get()));
} else {
return Optional.absent();
}
}
示例4: scoreSets
import com.bbn.bue.common.collections.CollectionUtils; //导入依赖的package包/类
private FMeasureInfo scoreSets(final Iterable<Set<Object>> predicted,
final Iterable<Set<Object>> gold) {
final Map<Object, Set<Object>> predictedItemToGroup =
CollectionUtils.makeElementsToContainersMap(predicted);
final Map<Object, Set<Object>> goldItemToGroup =
CollectionUtils.makeElementsToContainersMap(gold);
CorefScorerUtils.checkPartitionsOverSameElements(predictedItemToGroup.keySet(),
goldItemToGroup.keySet());
// if this is empty, we know the other is too,
// by the above
if (predictedItemToGroup.isEmpty()) {
return new PrecisionRecallPair(0.0f, 0.0f);
}
double precisionTotal = 0.0;
double recallTotal = 0.0;
for (final Object item : goldItemToGroup.keySet()) {
final Set<Object> goldGroup = goldItemToGroup.get(item);
final Set<Object> predictedGroup = predictedItemToGroup.get(item);
final Set<Object> inBoth = Sets.intersection(goldGroup, predictedGroup);
precisionTotal += inBoth.size() / ((double) predictedGroup.size());
recallTotal += inBoth.size() / ((double) goldGroup.size());
}
return new PrecisionRecallPair(
(float) (precisionTotal / goldItemToGroup.keySet().size()),
(float) (recallTotal / goldItemToGroup.keySet().size()));
}
示例5: writePartitions
import com.bbn.bue.common.collections.CollectionUtils; //导入依赖的package包/类
private static int writePartitions(final ImmutableSet<Symbol> remaining, final int nPartitions,
final File outputDirectory, final File partitionListFile, final String partitionPrefix,
final ImmutableMap<Symbol, File> documentMap) throws IOException {
int outputDocuments = 0;
// Partition remaining data
final ImmutableList<ImmutableList<Symbol>> partitions =
CollectionUtils.partitionAlmostEvenly(remaining.asList(), nPartitions);
// Write out each partition
log.info("Writing partitions to directory {}", outputDirectory);
int maxPartition = partitions.size();
final ImmutableList.Builder<File> partitionFiles = ImmutableList.builder();
for (int partitionNum = 0; partitionNum < partitions.size(); partitionNum++) {
final ImmutableList<Symbol> partition = partitions.get(partitionNum);
// maxPartition -1 since partitions are indexed starting at 0
final String partitionFileName = partitionPrefix + '.'
+ StringUtils.padWithMax(partitionNum, maxPartition - 1);
final File partitionFile;
if (documentMap != null) {
partitionFile = new File(outputDirectory, partitionFileName + ".map");
FileUtils.writeSymbolToFileMap(filterMapToKeysPreservingOrder(documentMap, partition),
Files.asCharSink(partitionFile, Charsets.UTF_8));
} else {
partitionFile = new File(outputDirectory, partitionFileName + ".list");
FileUtils.writeFileList(Lists.transform(partition, SymbolToFileFunction.INSTANCE),
Files.asCharSink(partitionFile, Charsets.UTF_8));
}
partitionFiles.add(partitionFile);
outputDocuments += partition.size();
log.info("Wrote partition {} to {}", partitionNum, partitionFile);
}
// Write out lists of files/maps created
FileUtils.writeFileList(partitionFiles.build(),
Files.asCharSink(partitionListFile, Charsets.UTF_8));
log.info("Wrote partition list to {}", partitionListFile);
return outputDocuments;
}
示例6: scoreSets
import com.bbn.bue.common.collections.CollectionUtils; //导入依赖的package包/类
private BLANCResult scoreSets(final Iterable<Set<Object>> predicted,
final Iterable<Set<Object>> gold) {
final Map<Object, Set<Object>> predictedItemToGroup =
CollectionUtils.makeElementsToContainersMap(predicted);
final Map<Object, Set<Object>> goldItemToGroup =
CollectionUtils.makeElementsToContainersMap(gold);
CorefScorerUtils.checkPartitionsOverSameElements(predictedItemToGroup.keySet(),
goldItemToGroup.keySet());
double corefLinksInBoth = 0.0;
double corefLinksInKey = 0.0;
double corefLinksInResponse = 0.0;
double nonCorefInBoth = 0.0;
double nonCorefLinksInKey = 0.0;
double nonCorefLinksInResponse = 0.0;
final Set<Object> allItems = predictedItemToGroup.keySet();
for (final Object item : allItems) {
final Set<Object> predictedNeighbors = Sets.newHashSet(predictedItemToGroup.get(item));
if (!useSelfEdges) {
predictedNeighbors.remove(item);
}
final Set<Object> goldNeighbors = Sets.newHashSet(goldItemToGroup.get(item));
if (!useSelfEdges) {
goldNeighbors.remove(item);
}
// The contribution for this item is the size of the intersection
// of the gold and predicted neighbor sets.
corefLinksInBoth += Sets.intersection(predictedNeighbors, goldNeighbors).size();
corefLinksInResponse += predictedNeighbors.size();
corefLinksInKey += goldNeighbors.size();
// -1 = don't count this item itself as a link if not using self edges
nonCorefLinksInKey += allItems.size() - goldNeighbors.size() + (useSelfEdges?0:- 1);
// -1 = don't count this item itself as a link if not using self edges
nonCorefLinksInResponse += allItems.size() - predictedNeighbors.size() + (useSelfEdges?0:-1);
final ImmutableSet<Object> neighborsInEither =
Sets.union(predictedNeighbors, goldNeighbors).immutableCopy();
// -1 = don't count this item itself as a link if not using self-edgescd
nonCorefInBoth += Sets.difference(allItems, neighborsInEither).size() + (useSelfEdges?0:-1);
}
return BLANCResult.fromSetCounts(true,
corefLinksInBoth, corefLinksInKey, corefLinksInResponse, nonCorefInBoth,
nonCorefLinksInKey, nonCorefLinksInResponse);
}
示例7: scoreSets
import com.bbn.bue.common.collections.CollectionUtils; //导入依赖的package包/类
private BLANCResult scoreSets(final Iterable<Set<Object>> predicted,
final Iterable<Set<Object>> gold) {
final Multimap<Object, Set<Object>> predictedItemToGroup =
CollectionUtils.makeSetElementsToContainersMultimap(predicted);
final Multimap<Object, Set<Object>> goldItemToGroup =
CollectionUtils.makeSetElementsToContainersMultimap(gold);
final Set<Object> keyItems = goldItemToGroup.keySet();
final Set<Object> responseItems = predictedItemToGroup.keySet();
final ImmutableSet<Object> itemsInBoth =
Sets.intersection(keyItems, responseItems).immutableCopy();
// |C_k \cap C_r|
int corefLinksInBoth = 0;
// |C_k|
int corefLinksInKey = 0;
// |C_r|
int corefLinksInResponse = 0;
// |N_K \cap N_r|
int nonCorefInBoth = 0;
// |N_k|
int nonCorefLinksInKey = 0;
// |N_r|
int nonCorefLinksInResponse = 0;
final Set<Object> allItems = Sets.union(responseItems,
keyItems).immutableCopy();
for (final Object item : allItems) {
final boolean inKey = keyItems.contains(item);
final boolean inResponse = responseItems.contains(item);
final Collection<Set<Object>> predictedClusters = predictedItemToGroup.get(item);
final Collection<Set<Object>> goldClusters = goldItemToGroup.get(item);
final Predicate<Object> SELF_ADJUSTMENT_FILTER;
if (useSelfEdges) {
SELF_ADJUSTMENT_FILTER = Predicates.alwaysTrue();
} else {
SELF_ADJUSTMENT_FILTER = not(equalTo(item));
}
final int selfAdjustment = useSelfEdges ? 0 : -1;
final ImmutableSet<Object> predictedNeighbors =
FluentIterable.from(concat(predictedClusters)).filter(SELF_ADJUSTMENT_FILTER).toSet();
final ImmutableSet<Object> goldNeighbors =
FluentIterable.from(concat(goldClusters)).filter(SELF_ADJUSTMENT_FILTER).toSet();
// The contribution for this item is the size of the intersection
// of the gold and predicted neighbor sets.
corefLinksInBoth += Sets.intersection(predictedNeighbors, goldNeighbors).size();
corefLinksInResponse += predictedNeighbors.size();
corefLinksInKey += goldNeighbors.size();
if (inKey) {
nonCorefLinksInKey += keyItems.size() - goldNeighbors.size() + selfAdjustment;
}
if (inResponse) {
nonCorefLinksInResponse += responseItems.size() - predictedNeighbors.size() + selfAdjustment;
}
if (inKey && inResponse) {
final ImmutableSet<Object> neighborsInEither =
Sets.union(predictedNeighbors, goldNeighbors).immutableCopy();
// -1 = don't count this item itself as a link
nonCorefInBoth += Sets.difference(itemsInBoth, neighborsInEither).size() + selfAdjustment;
}
}
return BLANCResult.fromSetCounts(keyItems.equals(responseItems),
corefLinksInBoth, corefLinksInKey, corefLinksInResponse, nonCorefInBoth,
nonCorefLinksInKey, nonCorefLinksInResponse);
}
示例8: entries
import com.bbn.bue.common.collections.CollectionUtils; //导入依赖的package包/类
/**
* Returns all provenance entries in this matrix, regardless of cell.
*/
public Set<CellFiller> entries() {
return FluentIterable.from(table.cellSet())
.transformAndConcat(CollectionUtils.<List<CellFiller>>TableCellValue())
.toSet();
}