Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a method to list all superclasses #15

Merged
merged 1 commit into from Dec 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -14,6 +14,7 @@
import java.util.Collection;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.semanticweb.owlapi.model.OWLOntology;

import net.bioclipse.core.PublishedClass;
Expand Down Expand Up @@ -88,6 +89,14 @@ public Collection<String> getAnnotationProperties(OWLOntology ontology)
public Collection<String> getClasses(OWLOntology ontology)
throws IOException, BioclipseException, CoreException;

@Recorded
@PublishedMethod(
params = "OWLOntology ontology, String classIRI",
methodSummary = "Returns the (non-asserted) OWL super classes as a collection of String's."
)
public Collection<String> getSuperClasses(OWLOntology ontology, String classIRI)
throws IOException, BioclipseException, CoreException;

@Recorded
@PublishedMethod(
params = "OWLOntology ontology",
Expand Down
Expand Up @@ -12,6 +12,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand All @@ -27,6 +28,7 @@
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDeclarationAxiom;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.OWLLiteral;
Expand All @@ -37,11 +39,13 @@
import org.semanticweb.owlapi.profiles.OWLProfileReport;
import org.semanticweb.owlapi.profiles.OWLProfileViolation;
import org.semanticweb.owlapi.search.EntitySearcher;
import org.semanticweb.owlapi.search.Searcher;
import org.semanticweb.owlapi.util.SimpleIRIMapper;

import net.bioclipse.business.BioclipsePlatformManager;
import net.bioclipse.core.business.BioclipseException;
import net.bioclipse.managers.business.IBioclipseManager;
import uk.ac.manchester.cs.owl.owlapi.OWLClassImpl;

public class OWLAPIManager implements IBioclipseManager {

Expand Down Expand Up @@ -161,6 +165,37 @@ public Collection<String> getClasses(OWLOntology ontology, IProgressMonitor moni
return list;
}

public Collection<String> getSuperClasses(OWLOntology ontology, String clazz, IProgressMonitor monitor)
throws IOException, BioclipseException, CoreException {
if (monitor == null) monitor = new NullProgressMonitor();

Set<String> allSuperClasses = new HashSet<String>();
Set<OWLEntity> entities = ontology.getEntitiesInSignature(IRI.create(clazz));
if (entities.isEmpty()) {
// recurse, maybe it's there
for (OWLOntology importedOntology : ontology.getImports()) {
Collection<String> subList = getSuperClasses(importedOntology, clazz, monitor);
allSuperClasses.addAll(subList);
}
} else {
if (entities.size() > 1)
throw new BioclipseException("More than one entity found with this IRI.");
OWLEntity entity = entities.iterator().next(); // there is exactly one
if (!(entity instanceof OWLClass))
throw new BioclipseException("The IRI is not of an OWLClass in this ontology, but an " + entity.getEntityType());
OWLClass owlClazz = new OWLClassImpl(IRI.create(clazz));
Collection<OWLClassExpression> superClasses = Searcher.sup(ontology.getSubClassAxiomsForSubClass(owlClazz));
for (OWLClassExpression superClass : superClasses) {
OWLClass superOwlClass = superClass.asOWLClass();
String superIri = superOwlClass.getIRI().toString();
allSuperClasses.add(superIri);
// recurse
allSuperClasses.addAll(getSuperClasses(ontology, superIri, monitor));
}
}
return allSuperClasses;
}

public Collection<OWLAnnotationProperty> getAllAnnotationProperties(OWLOntology ontology, IProgressMonitor monitor)
throws IOException, BioclipseException, CoreException {
if (monitor == null) monitor = new NullProgressMonitor();
Expand Down