我正在用OWL和SWRL API構建Maven項目。 我想檢索使用下面的代碼保存在一個文件.owl所有規則:SWRL API錯誤:未註冊的SWRL規則引擎
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的便利教程或常見問題,包括this。但是,它似乎沒有太大的幫助。
P.S.我的編碼技巧很差
嗨@ignazio,我已經添加了依賴關係,錯誤現在改變了,我會在另一個帖子中提問。謝謝 –