SQWRL (Semantic Query-Enhanced Web Rule Language; pronounced squirrel) is a SWRL-based language for querying OWL ontologies. It provides SQL-like operations to retrieve knowledge from OWL.    (B3U)

SQWRL Language Features    (B43)

The language introduction is two parts:    (B3V)

This document assumes that the reader is already familiar with SWRL. An introduction can be found here. A set of example SQWRL queries can be found here. A quick introduction to SQWRL can be found in:    (BN5)

Using SQWRL in Protege-OWL    (BDZ)

SQWRL is defined using a library of SWRL built-ins that effectively builds a query language on top of SWRL. These built-ins are defined in the SQWRL Ontology. It has the default namespace prefix sqwrl. A copy of this ontology can be found the standard Protege-OWL repositories, or can be imported through the 'Import Ontology' option in Protege-OWL's Metadata tab. The Jess rule engine is currently required to run SQWRL queries. Information on installing Jess can be found here.    (BJ8)

Accessing the Results of Queries    (A1C)

There are two mechanisms provided by the SWRLTab for accessing the results of queries: (1) a Java API that provides a JDBC-like interface called the SQWRLQueryAPI, which can be used to retrieve query results in Java applications; and (2) a graphical user interface called the SQWRLQueryTab that supports interactive querying and results display within the SWRLTab.    (B44)

Queries and Rules    (A1E)

SQWRL queries can operate in conjunction with SWRL and can thus be used to retrieve knowledge inferred by SWRL rules.    (A1F)

Assume, for example, the following rule that classifies persons older than 17 as adults:    (A1G)

A query to list all the adults in an ontology can be written:    (A1I)

Interoperation with other Built-In Libraries    (A2O)

SQWRL queries can freely use other built-in libraries. For example, to retrieve the name of all males in an ontology and prepend the title "Mr." to each name, the Core SWRL Built-in stringConcat can be used as follows:    (A2P)

Using the TBox Query Library with SQWRL query operators allows the writing of queries that ask questions about the classes and properties in an OWL ontology. For example, a query that returns all the direct subclasses of the Person class can be written:    (A2R)

To retrieve all properties (both direct and indirect) of the hasName property, one can write:    (A2T)

The list of built-in libraries provided by the SWRLTab can be found here. Users may also develop their own built-in libraries for use in SQWRL queries using the SWRLTab's built-in bridge mechanism.    (B45)

The ability to freely define and use built-ins in a query provides a means of continuously expanding the power of the query language.    (A2V)

Semantics of SQWRL    (A2W)

SQWRL queries operate on known individuals in the currently loaded OWL ontology. It is very important to note that SQWRL provides no way of accessing the information it accumulates from within a rule so query results cannot be written back to the ontology. There is no way, for example, to insert the result of a computed aggregate count back into the ontology. Such a mechanism could invalidate OWL's open world assumption and lead to nonmonotonicity.    (A2X)

While SQWRL's operators are implemented as SWRL built-ins, they do not operate like standard built-ins. Unlike most built-ins, they do not evaluate their arguments and return true if the arguments satisfy some predicate. Instead, they always return true and act as accumulators and build up table-based data structures outside of an ontology. However, they are side-effect free in terms of this ontology - they do not perform any ontology modifications. Crucially, they do not violate SWRL's semantics.    (BB7)

Unlike OWL and SWRL, SQWRL adopts the unique name assumption when querying.    (B3Y)