The SWRLAPI is a Java API for working with the OWL-based SWRL rule and SQWRL query languages. It includes graphical tools for editing and executing rules and queries.
See the SWRLAPI Wiki for documentation.
A standalone SWRLTab application and a Protégé-based SWRLTab Plugin, both built using this API, are also available.
The following examples can be used to quickly get started with the API. A sample SWRLAPI-based project can also be found here.
The library's dependency information can be found here:
If you'd like to be able to execute SWRL rules or SQWRL queries you will need a SWRLAPI-based rule engine implementation. Currently, a Drools-based SWRL rule engine implementation is provided. This implementation is also hosted on Maven Central. Its dependency information can be found here:
The SWRLAPI uses the OWLAPI to manage OWL ontologies. The following example illustrates how the library can be used to create a SWRL query engine using an ontology created by the OWLAPI and then execute rules in that ontology.
// Create OWLOntology instance using the OWLAPI
OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = ontologyManager.loadOntologyFromOntologyDocument(new File("/ont/Ont1.owl"));
// Create a SWRL rule engine using the SWRLAPI
SWRLRuleEngine swrlRuleEngine = SWRLAPIFactory.createSWRLRuleEngine(ontology);
// Run the SWRL rules in the ontology
swrlRuleEngine.infer();
This example shows how the API can be used to create a SQWRL query engine, create and execute a SQWRL query using this engine, and then process the results.
// Create OWLOntology instance using the OWLAPI
OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = ontologyManager.loadOntologyFromOntologyDocument(new File("/ont/Ont1.owl"));
// Create SQWRL query engine using the SWRLAPI
SQWRLQueryEngine queryEngine = SWRLAPIFactory.createSQWRLQueryEngine(ontology);
// Create and execute a SQWRL query using the SWRLAPI
SQWRLResult result = queryEngine.runSQWRLQuery("q1","swrlb:add(?x, 2, 2) -> sqwrl:select(?x)");
// Process the SQWRL result
if (result.next())
System.out.println("Name: " + result.getLiteral("x").getInteger());
Extensive documentation on the SWRLAPI can be found on the SWRLAPI Wiki.
To build this library you must have the following items installed:
Get a copy of the latest code:
git clone https://github.com/protegeproject/swrlapi.git
Change into the swrlapi directory:
cd swrlapi
Then build it with Maven:
mvn clean install
On build completion your local Maven repository will contain the generated swrlapi-${version}.jar file.
This JAR is used by the Protégé SWRLTab Plugin and by the standalone SWRLTab tool.
A Build Project is provided to build core SWRLAPI-related components. A project containing a library of integration tests is also provided.
This software is licensed under the BSD 2-clause License.
If you have questions about this library, please go to the main Protégé website and subscribe to the Protégé Developer Support mailing list. After subscribing, send messages to protege-dev at lists.stanford.edu.