本文整理汇总了Java中com.bbn.bue.common.collections.CollectionUtils.makeSetElementsToContainersMultimap方法的典型用法代码示例。如果您正苦于以下问题:Java CollectionUtils.makeSetElementsToContainersMultimap方法的具体用法?Java CollectionUtils.makeSetElementsToContainersMultimap怎么用?Java CollectionUtils.makeSetElementsToContainersMultimap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.bbn.bue.common.collections.CollectionUtils
的用法示例。
在下文中一共展示了CollectionUtils.makeSetElementsToContainersMultimap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}