簡體   English   中英

使用 OWL API 推理本體

[英]Reasoning an ontology using OWL API

我已經使用 OWL API 4.1.3 來加載我的本體,它並不大。 由於我需要使用推斷信息,我還使用 Hermit 1.3.8.413 庫進行了推理。 以下代碼顯示了我是如何做到的。

public class ReasonRDF {

public static void main(String[] args) throws OWLOntologyCreationException, OWLOntologyStorageException {

    readRDF("C:/Users/workspace/Ontology_matching/NVDB_Matching_v18_H_4_1_CONVERTYING/results/NewInstantiated/owl/OSM1.owl");

}
public static void readRDF(String address) throws OWLOntologyCreationException, OWLOntologyStorageException{
    OWLOntologyManager manager =OWLManager.createOWLOntologyManager();
    File file = new File (address);
    OWLOntology ont = manager.loadOntologyFromOntologyDocument(IRI.create(file));
    System.out.println("Ontology Loaded...");

    System.out.println("Logical IRI   : " + ont.getOntologyID());
    System.out.println("Format        : " + manager.getOntologyFormat(ont));
    System.out.println("Runtime memory: " + Runtime.getRuntime().totalMemory());      
      ReasonerFactory reasonerFactory = new ReasonerFactory();
      ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
      Configuration config = new Configuration();
      config.ignoreUnsupportedDatatypes=true;
      config.reasonerProgressMonitor= progressMonitor;
      OWLReasoner reasoner = reasonerFactory.createReasoner(ont, config);


      long t0 = System.nanoTime();

      System.out.println("Starting to add axiom generators");
      OWLDataFactory datafactory = manager.getOWLDataFactory();
      List<InferredAxiomGenerator<? extends OWLAxiom>> inferredAxioms = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
      //inferredAxioms.add(new InferredSubClassAxiomGenerator());
      inferredAxioms.add(new InferredClassAssertionAxiomGenerator());
      //inferredAxioms.add(new InferredDataPropertyCharacteristicAxiomGenerator());
      //inferredAxioms.add(new InferredObjectPropertyCharacteristicAxiomGenerator());
      //inferredAxioms.add(new InferredEquivalentClassAxiomGenerator());
      //inferredAxioms.add(new InferredPropertyAssertionGenerator());
      //inferredAxioms.add(new InferredInverseObjectPropertiesAxiomGenerator());         
      inferredAxioms.add(new InferredSubDataPropertyAxiomGenerator());
      inferredAxioms.add(new InferredSubObjectPropertyAxiomGenerator());
      System.out.println("finished adding axiom generators");

//        List<InferredIndividualAxiomGenerator<? extends OWLIndividualAxiom>> individualAxioms= new ArrayList<InferredIndividualAxiomGenerator<? extends OWLIndividualAxiom>>();
//        inferredAxioms.addAll(individualAxioms);

    // for writing inferred axioms to the new ontology
    OWLOntology infOnt = manager.createOntology(IRI.create(ont.getOntologyID().getOntologyIRI().get()+"_inferred"));

      // use generator and reasoner to infer some axioms
      System.out.println("Starting to infer");
      InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, inferredAxioms);
      //InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner);

      System.out.println("Inferrence is over");

      System.out.println("Storing the results");
      iog.fillOntology(datafactory,infOnt);
      System.out.println("Results are stored");
      long elapsed_time = System.nanoTime()-t0;
      System.out.println(elapsed_time);

      // save the ontology
      manager.saveOntology(infOnt, IRI.create("file:///C:/Users/ontologies/NVDB4_test.rdf"));
    }
}

它不會拋出任何錯誤,但需要永遠將推斷的本體存儲在新文件中。 事實上,即使在 2 天后它也沒有完成工作。 我的 IDE 是 eclipse EE,我提供了 6 到 12 GB 的內存來運行這個應用程序。 我的代碼或本體找不到任何問題。

有人可以建議優化甚至更好的實現方式或其他api嗎?

是我的本體,以防有人想測試它。

本體的大小僅與推理的復雜性松散相關——對於推理者來說,一些小的本體比其他非常大的本體要困難得多。 (當然也有可能出現錯誤)。

請問可以分享本體內容嗎?

編輯:嘗試了本體之后,看起來大小並不重要; 事實證明,本體很難推理。

我曾嘗試禁用 SWRL 規則並跳過類斷言生成,但仍然遇到了障礙。 對象屬性的數量和拓撲結構足以讓 HermiT 難以承受。

我已經嘗試了 1.3.8.500 版本,以防 OWLAPI 中的任何問題可能已在更新版本中修復; 我得到的唯一重要結果是代碼沒有運行內存限制。 分配給 VM 的 3 GB RAM 似乎綽綽有余。

與不相交相關的推理似乎要花費大量時間——這並不意外。 考慮是否可以從本體中刪除不相交的公理並仍然滿足您的要求。

還要考慮通過對 ABox 進行分區來分離個體是否有意義 - 如果存在您確定不相關的個​​體,則最好在多個本體中分離斷言。 大量不相關的個​​體可能會導致推理者嘗試永遠無法提供有用推理的推理路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM