Skip to content

Instantly share code, notes, and snippets.

@benozol
Last active December 12, 2016 18:06
Show Gist options
  • Save benozol/20d84d5132152fe7d17966234d049257 to your computer and use it in GitHub Desktop.
Save benozol/20d84d5132152fe7d17966234d049257 to your computer and use it in GitHub Desktop.
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom;
import org.semanticweb.owlapi.model.OWLObjectUnionOf;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import uk.ac.manchester.cs.jfact.JFactFactory;
public class TestCase2 {
static final IRI VO_IRI = IRI.create("http://purl.obolibrary.org/obo/vo.owl");
static final String OBO_PREFIX = "http://purl.obolibrary.org/obo/";
public static void main(String[] args) throws Exception {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory = manager.getOWLDataFactory();
OWLOntology ontology = manager.loadOntology(VO_IRI);
JFactFactory reasonerFactory = new JFactFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ontology);
Collection<OWLObjectProperty> properties = Arrays
.asList(dataFactory.getOWLObjectProperty(OBO_PREFIX + "VO_0003355"));
Set<OWLClass> auxClasses = new TreeSet<>();
int ix = 0;
for (OWLObjectProperty prop : properties) {
String name = String.format("aux-%d", ix++);
OWLClass clazz = dataFactory.getOWLClass(Utils.VO_IRI + "#" + name);
auxClasses.add(clazz);
OWLObjectSomeValuesFrom someValues = dataFactory.getOWLObjectSomeValuesFrom(prop,
dataFactory.getOWLThing());
OWLAxiom axiom = dataFactory.getOWLEquivalentClassesAxiom(clazz, someValues);
manager.addAxiom(ontology, axiom);
}
reasoner.flush();
OWLObjectUnionOf union = dataFactory.getOWLObjectUnionOf(auxClasses);
reasoner.getSuperClasses(union).entities().forEach(clazz -> System.out.println("- " + clazz));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment