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