I am building a Maven project with OWL and SWRL APIs. I want to retrieve all rules stored in an .owl file using the code below:
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.swrlapi.core.SWRLAPIRule;
import org.swrlapi.core.SWRLRuleEngine;
import org.swrlapi.factory.SWRLAPIFactory;
import java.io.*;
import java.util.Set;
public class ManagingRules {
public static void main(String[] args) throws OWLOntologyCreationException {
OWLOntologyManager m = OWLManager.createOWLOntologyManager();
OWLOntology ontology = m.loadOntologyFromOntologyDocument(new File("pwidasFinale.owl"));
//taking SWRLs list
SWRLRuleEngine ruleEngine = SWRLAPIFactory.createSWRLRuleEngine(ontology);
// Get SWRL rules
Set<SWRLAPIRule> sets = ruleEngine.getSWRLRules();
for(SWRLAPIRule item : sets){
System.out.println(item.toString());
}
}
}
There is no compile error. But when I run this class, I got this notification
Exception in thread "main" org.swrlapi.exceptions.NoRegisteredSWRLRuleEnginesException: no registered SWRL rule engines
at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:47)
at org.swrlapi.factory.SWRLAPIFactory.createSWRLRuleEngine(SWRLAPIFactory.java:39)
at ManagingRules.main(ManagingRules.java:20)
In fact, in the .owl file, there are 15 rules stored.
Kindly please show me where to fix it.
I've been searching a convenient tutorial or FAQ of SWRL API, including this. But, it seems it doesn't help so much.
P.S. my coding skill is poor
The problem is not in the input file, but in the fact that there are no registered SWRL rule engines available. This setup is very likely carried out in Protege before the SWRLAPIFactory is used.
This requirement is described here: https://github.com/protegeproject/swrlapi/
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.
I believe you need to add the dependencies described in that page to your project.