當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。