class TermAnnotations {

  public static Map<TermId, Collection<TermId>> constructTermAnnotationToLabelsMap(
      Ontology ontology, Collection<? extends TermAnnotation> annotations) {
    final Map<TermId, Collection<TermId>> result = new HashMap<>();

    for (TermAnnotation anno : annotations) {
      for (TermId termId : ontology.getAncestorTermIds(anno.getTermId(), true)) {
        if (!result.containsKey(termId)) {
          result.put(termId, Sets.newHashSet(anno.getLabel()));
        } else {
          result.get(termId).add(anno.getLabel());
        }
      }
    }

    return result;
  }

  private  TermAnnotations();

}