当前位置: 首页>>代码示例>>Java>>正文


Java CollectionUtils.makeSetElementsToContainersMultimap方法代码示例

本文整理汇总了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);
}
 
开发者ID:BBN-E,项目名称:bue-common-open,代码行数:75,代码来源:MultiBLANCScorer.java


注:本文中的com.bbn.bue.common.collections.CollectionUtils.makeSetElementsToContainersMultimap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。