Skip to content

Java API for working with the SWRL rule and SQWRL query languages

Notifications You must be signed in to change notification settings

AwelEshetu/swrlapi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

SWRLAPI

The SWRLAPI is a Java API for working with the OWL-based SWRL rule and SQWRL query langauges. 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.

Getting Started

The following examples can be used to quickly get started with the API.

First, either download the latest JAR from the project's GitHub Release area or use your favourite dependency management tool to download it from Maven Central. Here is the Maven dependency for this library:

  <dependency>
    <groupId>edu.stanford.swrl</groupId>
    <artifactId>swrlapi</artifactId>
    <version>1.0.0-beta-4</version>
  </dependency>

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 Maven dependency is:

  <dependency>
    <groupId>edu.stanford.swrl</groupId>
    <artifactId>swrlapi-drools-engine</artifactId>
    <version>1.0.0-beta-6</version>
  </dependency>

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, execute a SQWRL query using this engine, and then process the results.

 // Create OWLOntology instances 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").getInt());

Extensive documentation on the SWRLAPI can be found on the SWRLAPI Wiki.

Building

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.

Questions

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.

About

Java API for working with the SWRL rule and SQWRL query languages

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 97.2%
  • Web Ontology Language 2.8%