Skip to : [Content] [Navigation]
 

There is no native SPARQL support in OWLAPI. However, a Jena model can be created with the contents of an OWLAPI reasoner so SPARQL query answering can be done on the Jena model. OWLAPI reasoner and Jena model can be queried together but all updates should be done on the OWLAPI ontology. The following snippet shows the general idea behind this approach:

   // import com.clarkparsia.pellet.owlapiv3.PelletReasoner;
   // import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory;

   // Create OWLAPI ontology as usual
   OWLOntology ontology = ...
   // Create Pellet-OWLAPI reasoner (non-buffering mode makes synchronization easier)
   PelletReasoner reasoner = 
         PelletReasonerFactory.getInstance().createNonBufferingReasoner( ontology );
   // Get the KB from the reasoner
   KnowledgeBase kb = reasoner.getKB();
   // Create a Pellet graph using the KB from OWLAPI
   PelletInfGraph graph = new org.mindswap.pellet.jena.PelletReasoner().bind( kb );
   // Wrap the graph in a model
   InfModel model = ModelFactory.createInfModel( graph );
   // Use the model to answer SPARQL queries

The model created this way cannot be used to answer SPARQL queries that query for RDF syntax triples, e.g. SELECT * WHERE { ?x owl:onProperty ?p }.