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


Java Term类代码示例

本文整理汇总了Java中com.github.phenomics.ontolib.ontology.data.Term的典型用法代码示例。如果您正苦于以下问题:Java Term类的具体用法?Java Term怎么用?Java Term使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Term类属于com.github.phenomics.ontolib.ontology.data包,在下文中一共展示了Term类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: computeInformationContent

import com.github.phenomics.ontolib.ontology.data.Term; //导入依赖的package包/类
/**
 * Perform the actual computation.
 *
 * <p>
 * Note that {@code termLabels} must already contain the implicit ancestor annotations. You can
 * achieve this using {@link TermIds#augmentWithAncestors(ImmutableOntology, Set, boolean)}.
 * </p>
 *
 * @param <LabelT> Labels for objects from "the real world". This could, e.g., be
 *        <code>String</code>s with gene names. This type has to properly implement
 *        <code>equals(Object)</code> and <code>hashValue()</code> as it is to be used as keys in
 *        a {@link HashMap}.
 *
 * @param termLabels Labels for each {@link Term}, identified by {@link TermId}
 * @return {@link Map} from {@link TermId} to information content.
 */
public <LabelT> Map<TermId, Double>
    computeInformationContent(Map<TermId, ? extends Collection<LabelT>> termLabels) {
  LOGGER.info("Computing IC of {} terms using {} labels...", new Object[] {ontology.countAllTerms(),
      termLabels.values().stream().mapToInt(l -> l.size()).sum()});

  // Build mapping from TermId -> absolute frequency
  final TermId root = ontology.getRootTermId();
  final Map<TermId, Integer> termToFrequency = new HashMap<>();
  for (TermId termId : ontology.getNonObsoleteTermIds()) {
    termToFrequency.put(termId, 0);
  }
  for (Entry<TermId, ? extends Collection<LabelT>> e : termLabels.entrySet()) {
    termToFrequency.put(e.getKey(), e.getValue().size());
  }

  // Compute information content for each TermId
  final int maxFreq = termToFrequency.get(root);
  final Map<TermId, Double> termToInformationContent =
      caculateInformationContent(maxFreq, termToFrequency);

  // Fix terms with IC of zero, set it to IC of root
  int countIcZero = 0;
  final double dummyIc = -Math.log(1 / (double) maxFreq);

  for (Term t : ontology.getTerms()) {
    if (t.isObsolete()) {
      continue;
    }
    if (!termToFrequency.containsKey(t.getId())) {
      ++countIcZero;
      termToInformationContent.put(t.getId(), dummyIc);
    }
  }

  if (countIcZero > 0) {
    LOGGER.warn("Frequency of {} non-obsolete terms was zero! Their IC has been set to {} = "
        + "- log(1 / {}).", new Object[] {countIcZero, dummyIc, maxFreq});
  }
  LOGGER.info("Computing IC is complete.");

  return termToInformationContent;
}
 
开发者ID:Phenomics,项目名称:ontolib,代码行数:59,代码来源:InformationContentComputation.java


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