2011年8月9日星期二

LOAD and TRAVERSE ontology with owlapi

OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

// load an ontology from the web
IRI iri = IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl");
OWLOntology pizzaOntology = manager.loadOntologyFromOntologyDocument(iri);

// create a reasoner, many reasoner realize the OWLReasonerFactory interface,
// e.g. pellet, FaCT++, Hermit
OWLReasonerFactory reasonerFactory = (OWLReasonerFactory) Class.forName("com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory").newInstance();
Reasoner reasoner = reasonerFactory.createNonBufferingReasoner(pizzaOntology);

// traverse in OWLOntology
// get OWL_THING
IRI classIRI = OWLRDFVocabulary.OWL_THING.getIRI();
OWLClass clazz = manager.getOWLDataFactory().getOWLClass(classIRI);
// get subclasses.
Set subSet = reasoner.getSubClasses(clazz, true).getFlattened();
// check satisfiability of clazz
reasoner.isSatisfiable(clazz);

没有评论: