我正在使用 OWL 和 SWRL API 构建一个 Maven 项目。我想使用以下代码检索存储在 .owl 文件中的所有规则:
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());
}
}
}
没有编译错误。但是当我运行这个课程时,我收到了这个通知
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)
实际上,.owl 文件中存储了 15 条规则。
请告诉我在哪里修复它。
我一直在寻找一个方便的教程或 SWRL API 的常见问题解答,包括这个. 但是,它似乎并没有太大帮助。
PS我的编码技术很差