Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


owlet is a query expansion preprocessor for SPARQL. It parses embedded OWL class expressions (in Manchester Syntax) and uses an OWL reasoner to replace them with FILTER statements containing the URIs of subclasses of the given class expression (or superclasses, equivalent classes, or instances).

owlet is written in Scala but can be used in any Java application.


owlet is not yet available from an online Maven repository. To use it in your project you will need to:

  1. Check out the code, e.g. run git clone on the command line.
  2. Run mvn install to build the jar and add to your local Maven repository.
  3. Add the owlet dependency to your pom.xml:

How does it work

The OWL class expression to be expanded is a string literal at an appropriate location in a SPARQL query. The query expander recognizes the literal containing the class expression by its datatype, which must be Datatypes of literals in SPARQL are assigned using the ^^TypeURI suffix notation (where TypeURI is the URI of the datatype; URI prefixes are allowed).

The literal containing the class expression must be in one of the following 3 triple patterns (with rdf, rdfs, owl declared as in, and owlet as <>):

  1. Subclass triple: ?x rdfs:subClassOf "owl:Thing"^^owlet:omn
  2. instance-of triple: ?x rdf:type "owl:Thing"^^owlet:omn
  3. equivalent class triple: ?x owl:equivalentClass "owl:Thing"^^owlet:omn

Each of these triples will be rewritten by the expander in the following pattern:

FILTER(?x IN (<URI1>,<URI2>,<URI3>,...))

where <URI1>,<URI2>,<URI3>,... is the list of class or instance identifiers that satisfy the OWL class expression, as determined by the reasoner.


Below is an example of loading an ontology from a file into an OWL reasoner, and then using the reasoner to expand a SPARQL query to a triple store. In this example, the triple store is in-memory and holds the same ontology as the reasoner, but you could replace that part with querying a remote SPARQL endpoint that, for example, contains data linked to the ontology. The owlet tests include executable versions in both Java and Scala.


import org.junit.Test;
import org.semanticweb.elk.owlapi.ElkReasonerFactory;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.reasoner.InferenceType;
import org.semanticweb.owlapi.reasoner.OWLReasoner;

import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;

import org.phenoscape.owlet.QueryExpander;

public class SPARQLQueryRunner {

	public void runSPARQLQuery() throws OWLOntologyCreationException, IOException {
		final OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
		final OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File("my_ontology.owl"));
		final OWLReasoner reasoner = new ElkReasonerFactory().createReasoner(ontology);
		final Model rdfModel = ModelFactory.createDefaultModel();"my_ontology.owl");
		final String queryText = "PREFIX rdfs: <>\n"
				+ "PREFIX ow: <>\n"
				+ "PREFIX axial_skeleton: <>\n"
				+ "PREFIX definition: <>\n"
				+ "PREFIX part_of: <>\n"
				+ "SELECT DISTINCT ?structure ?label ?definition\n"
				+ "WHERE\n"
				+ "{\n"
				+ "?structure rdfs:label ?label .\n"
				+ "?structure definition: ?definition .\n"
				+ "?structure rdfs:subClassOf \"part_of: some axial_skeleton:\"^^ow:omn .\n"
				+ "}";
		final QueryExpander expander = new QueryExpander(reasoner);
		final Query query = QueryFactory.create(queryText);
		final Query expandedQuery = expander.expandQuery(query);
		final ResultSet results = QueryExecutionFactory.create(expandedQuery, rdfModel).execSelect();


More documentation can be found on the owlet wiki.


A little OWL in SPARQL.







No packages published