我正在用OWL和SWRL构建一个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的方便教程或常见问题,包括这。但是,这似乎没有多大帮助。
我的编码能力很差
发布于 2017-04-23 09:41:26
问题不在于输入文件,而在于没有已注册的SWRL规则引擎可用。在使用SWRLAPIFactory之前,这种设置很可能在Protege中进行。
这个需求在这里描述: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.
我认为您需要将该页面中描述的依赖项添加到项目中。
https://stackoverflow.com/questions/43497422
复制相似问题