2017-04-19 149 views
0

我正在用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.我的編碼技巧很差

回答

0

問題不在輸入文件中,而是因爲沒有註冊的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.

我相信你需要添加在該頁面到您的項目描述的依賴關係。

+0

嗨@ignazio,我已經添加了依賴關係,錯誤現在改變了,我會在另一個帖子中提問。謝謝 –