All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.stanford.protege.webprotege.mansyntax.render.NamedIndividualFactsSectionRenderer 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.DataPropertyAssertionAxiomsBySubjectIndex;
import edu.stanford.protege.webprotege.index.ObjectPropertyAssertionAxiomsBySubjectIndex;
import org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntax;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObject;
import org.semanticweb.owlapi.model.OWLOntologyID;
import org.semanticweb.owlapi.model.OWLPropertyAssertionAxiom;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;

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 NamedIndividualFactsSectionRenderer extends AbstractOWLAxiomItemSectionRenderer, OWLObject> {

    @Nonnull
    private final ObjectPropertyAssertionAxiomsBySubjectIndex objectPropertyAxiomsIndex;

    @Nonnull
    private final DataPropertyAssertionAxiomsBySubjectIndex dataPropertyAxiomsIndex;

    @Inject
    public NamedIndividualFactsSectionRenderer(@Nonnull ObjectPropertyAssertionAxiomsBySubjectIndex objectPropertyAxiomsIndex,
                                               @Nonnull DataPropertyAssertionAxiomsBySubjectIndex dataPropertyAxiomsIndex) {
        this.objectPropertyAxiomsIndex = checkNotNull(objectPropertyAxiomsIndex);
        this.dataPropertyAxiomsIndex = checkNotNull(dataPropertyAxiomsIndex);
    }

    @Override
    public ManchesterOWLSyntax getSection() {
        return ManchesterOWLSyntax.FACTS;
    }

    @Override
    public Set> getAxiomsInOntology(OWLNamedIndividual subject,
                                                                    OWLOntologyID ontologyId) {
        return Stream.concat(
                objectPropertyAxiomsIndex.getObjectPropertyAssertions(subject, ontologyId),
                dataPropertyAxiomsIndex.getDataPropertyAssertions(subject, ontologyId)
        ).collect(toSet());
    }

    @Override
    public List getRenderablesForItem(OWLNamedIndividual subject,
                                                 OWLPropertyAssertionAxiom item,
                                                 OWLOntologyID ontologyId) {
        return Lists.newArrayList(item.getProperty(), item.getObject());
    }

    @Override
    public String getSeparatorAfter(int renderableIndex, List renderables) {
        return renderableIndex == 0 ? "      " : super.getSeparatorAfter(renderableIndex, renderables);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy