In the 3.5 release of Protege, the SWRLTab APIs changed substantially. Instead of being packaged with Protege-OWL, the SWRLTab components were separated into a number of different subsystems. One of the primary motivations for this change was providing a set of APIs that could be used to interact with SWRLTab subsystems in both Protege 3 and Protege 4. They also reflect the inclusion of new OWL 2 RL functionality and the Drools rule engine . (CHM)
As before, these APIs are part of the standard Protege-OWL distribution. The JARs containing these APIs are included in the Protege-OWL plugins directory (e.g., C;/Development/Protege_3.5/plugins/edu.stanford.smi.protegex.owl). In general, a Java program that wishes to use these APIs should simply include all the JARs in this plugin directory. (If you wish to download the source code for these APIs, you can follow the instructions here.) (CK4)
At the API level, these changes are mostly reflected in package name updates. In general, 3.4.8 class or interfaces were in the edu.stanford.smi.protegex.owl.swrl.bridge package and below; in 3.5 and later, the corresponding package will be in the org.protege.owl.portability, org.protege.owl.swrltab.p3, or org.protege.owl.swrlapi packages. A Java IDE should be able to automatically update imports to reflect the new package names. In a few cases, class or interface names will have changed. The primary relevant APIs are the: (CIK)
Updating to the 3.5 SWRL Rule Engine API (CHR)
In 3.4.8 and earlier, a SWRL rule engine was created using the SWRL Rule Engine API as follows: (CHS)
OWLModel owlModel = ... // Create using normal Protege-OWL mechanisms. SWRLRuleEngine ruleEngine = SWRLRuleEngineFactory.create("SWRLJessBridge", owlModel); (CI0)
In 3.5, the SWRLRuleEngineFactory has been replaced with P3SWRLRuleEngineFactory; this class in the org.protege.swrltab.p3 package. Also, the rule engine name is how shortened, so "SWRLJessBridge" becomes "Jess". (CHT)
So the new 3.5 code would be: (CHU)
OWLModel owlModel = ... // Create using normal Protege-OWL mechanisms. SWRLRuleEngine ruleEngine = P3SWRLRuleEngineFactory.create("Jess", owlModel); (CI0)
The API provided by the SWRLRuleEngine is largely unchanged. (CHV)
In 3.5, the Drools rule engine is now supported. The code to create an instance if the SWRL rule engine using Drools is: (CHW)
OWLModel owlModel = ... // Create using normal Protege-OWL mechanisms. SWRLRuleEngine ruleEngine = P3SWRLRuleEngineFactory.create("Drools", owlModel); (CI0)
As before, a rule engine does not have to be specified, in which case the system will pick an installed engine. By default, the Drools engine is returned. (CHX)
This default behaviour can be changed by setting a property named protege.owl.swrl.default_rule_engine in the protege.properties file, which is in the base of the Protege installation directory. For example, an entry to set the default rule engine to Jess would be: (CI3)
protege.owl.swrl.default_rule_engine=Jess (CI4)
Protege must be restarted for this assignment to take effect. (CI5)
Updating to the 3.5 SQWRL Query API (CIA)
In 3.4.8 and earlier, a SQWRL query engine was created using the SQWRL Query API as follows: (CHS)
OWLModel owlModel = ... // Create using normal Protege-OWL mechanisms SQWRLQueryEngine queryEngine = SQWRLQueryEngineFactory.create(owlModel); (CI0)
In 3.5, the SQWRLQueryEngineFactory has been replaced with P3SQWRLQueryEngineFactory, which is in the package org.protege.swrltab.p3 package. (CIH)
So the new 3.5 code would be: (CHU)
OWLModel owlModel = ... // Create using normal Protege-OWL mechanisms SQWRLQueryEngine queryEngine = P3SQWRLQueryEngineFactory.create(owlModel); (CI0)
As described above, the system will pick a default rule engine if none is specified, behaviour that can be overridden using the protege.properties file. (CIG)
Two of the classes and interfaces for dealing with query result values have also been changed. The base type representing results was renamed from SQWRLResult to Result, and the type for dealing with literal values was renamed from DataValue to LiteralValue. Also, the exception returned from a query was renamed from SQWRLException to ResultException. These new classes are in the org.protege.owl.portability.query package. (CII)
So, a snippet of code to deal with literal return value that conforms with the 3.5 release would look as follows: (CID)
try { Result result = queryEngine.runSQWRLQuery("Query-1"); while (result.hasNext()) { LiteralValue nameValue = result.getLiteralValue("?name"); LiteralValue salaryValue = result.getLiteralValue("?salary"); System.out.println("Name: " + nameValue.getString()); System.out.println("Salary: " + salaryValue.getInt()); result.next(); } } catch (ResultException e) { ... } (CIF)