
edu.stanford.protege.webprotege.mansyntax.render.AnnotationsSectionRenderer Maven / Gradle / Ivy
The newest version!
package edu.stanford.protege.webprotege.mansyntax.render;
import com.google.common.collect.Lists;
import edu.stanford.protege.webprotege.index.AnnotationAssertionAxiomsBySubjectIndex;
import org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntax;
import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.OWLObject;
import org.semanticweb.owlapi.model.OWLOntologyID;
import org.semanticweb.owlapi.util.ShortFormProvider;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.stream.Collectors.toSet;
/**
* @author Matthew Horridge, Stanford University, Bio-Medical Informatics Research Group, Date: 24/02/2014
*/
public class AnnotationsSectionRenderer extends AbstractOWLAxiomItemSectionRenderer {
public static final String VALUE_SEPARATOR = " : ";
public static final String PROPERTY_VALUES_SEPARATOR = " ";
@Nonnull
private final AnnotationAssertionAxiomsBySubjectIndex axiomsIndex;
@Inject
public AnnotationsSectionRenderer(@Nonnull AnnotationAssertionAxiomsBySubjectIndex axiomsIndex) {
this.axiomsIndex = checkNotNull(axiomsIndex);
}
@Override
public ManchesterOWLSyntax getSection() {
return ManchesterOWLSyntax.ANNOTATIONS;
}
@Override
protected Set getAxiomsInOntology(S subject, OWLOntologyID ontologyId) {
return axiomsIndex.getAxiomsForSubject(subject.getIRI(), ontologyId).collect(toSet());
}
@Override
public List getRenderablesForItem(S subject, OWLAnnotationAssertionAxiom item, OWLOntologyID ontologyId) {
return Lists.newArrayList(item.getProperty(), item.getValue());
}
@Override
public String getSeparatorAfter(int renderableIndex, List renderables) {
return renderableIndex == 0 ? PROPERTY_VALUES_SEPARATOR : VALUE_SEPARATOR;
}
@Override
protected List sort(Set items, final ShortFormProvider shortFormProvider) {
List sorted = Lists.newArrayList(items);
sorted.sort(new Comparator() {
@Override
public int compare(OWLAnnotationAssertionAxiom owlAnnotationAssertionAxiom,
OWLAnnotationAssertionAxiom owlAnnotationAssertionAxiom2) {
IRIOrdinalProvider iriOrdinalProvider = IRIOrdinalProvider.withDefaultAnnotationPropertyOrdering();
return new AnnotationPropertyComparatorImpl(shortFormProvider, iriOrdinalProvider).compare
(owlAnnotationAssertionAxiom.getProperty(), owlAnnotationAssertionAxiom2.getProperty());
}
});
return sorted;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy