InformationContentComputation { public Map<TermId, Double> computeInformationContent(Map<TermId, Collection<TermId>> termLabels) { LOGGER.info( "Computing IC of {} terms using {} labels...", ontology.countAllTerms(), termLabels.values().stream().mapToInt(Collection::size).sum() ); final TermId root = ontology.getRootTermId(); final Map<TermId, Integer> termToFrequency = new HashMap<>(); for (TermId termId : ontology.getNonObsoleteTermIds()) { termToFrequency.put(termId, 0); } for (Entry<TermId, Collection<TermId>> e : termLabels.entrySet()) { termToFrequency.put(e.getKey(), e.getValue().size()); } final int maxFreq = termToFrequency.get(root); final Map<TermId, Double> termToInformationContent = caculateInformationContent(maxFreq, termToFrequency); 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 / {}).", countIcZero, dummyIc, maxFreq); } LOGGER.info("Computing IC is complete."); return termToInformationContent; } InformationContentComputation(Ontology ontology); Map<TermId, Double> computeInformationContent(Map<TermId, Collection<TermId>> termLabels); static TermId mostInformativeCommonAncestor(TermId t1, TermId t2, Ontology ontology, Map<TermId, Double> term2ic);  }
@Test void test() { Map<TermId, Collection<TermId>> termLabels = TermAnnotations.constructTermAnnotationToLabelsMap(ontology, recipeAnnotations); Map<TermId, Double> informationContent = computation.computeInformationContent(termLabels); assertEquals(7, informationContent.size()); assertEquals(0.0, informationContent.get(idVegetable), 0.001); assertEquals(0.0, informationContent.get(idRootVegetable), 0.001); assertEquals(0.405, informationContent.get(idLeafVegetable), 0.001); assertEquals(0.405, informationContent.get(idCarrot), 0.001); assertEquals(0.405, informationContent.get(idBeet), 0.001); assertEquals(0.405, informationContent.get(idPumpkin), 0.001); assertEquals(1.099, informationContent.get(idBlueCarrot), 0.01); }