2015-03-24 32 views
0

我在使用HermiT推理器庫時遇到問題。使用HermiT打印本體的層次結構

有沒有人瞭解我在這裏做錯了?

public static void main(String[] args) { 
    try { 
     // First, we create an OWLOntologyManager object. The manager will load and 
     // save ontologies. 
     OWLOntologyManager manager=OWLManager.createOWLOntologyManager(); 
     // Now, we create the file from which the ontology will be loaded. 
     File inputOntologyFile = new File("SchoolESTGExample.owl"); 
     // We use the OWL API to load the ontology. 
     OWLOntology ontology=manager.loadOntologyFromOntologyDocument(inputOntologyFile); 
     // Now we can start and create the reasoner. Here we create an instance of HermiT 
     // OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();   
     //OWLReasoner owlReasoner = reasonerFactory.createReasoner(ontology); 
     Reasoner reasoner = new Reasoner(ontology); 
     reasoner.precomputeInferences(); 
     // We can determine if the ontology is actually consistent 
     if (reasoner.isConsistent()) { 

      // Now we create an output stream that HermiT can use to write the axioms. The output stream is 
      // a wrapper around the file into which the axioms are written. 
      File prettyPrintHierarchyFile=new File("prettyPrint.owl"); 
      if (!prettyPrintHierarchyFile.exists()) 
       prettyPrintHierarchyFile.createNewFile(); 
      // turn to an absolute file, so that we can write to it 
      prettyPrintHierarchyFile=prettyPrintHierarchyFile.getAbsoluteFile(); 
      BufferedOutputStream prettyPrintHierarchyStreamOut=new BufferedOutputStream(new FileOutputStream(prettyPrintHierarchyFile)); 
      // The output stream is wrapped into a print write with autoflush. 
      PrintWriter output=new PrintWriter(prettyPrintHierarchyStreamOut,true); 
      // Now we let HermiT pretty print the hierarchies. Since all parameters are set to true, 
      // HermiT will print the class and the object property and the data property hierarchy. 
      long t=System.currentTimeMillis(); 
      t=System.currentTimeMillis()-t; 
      reasoner.printHierarchies(output, true, true, true); 

      // Now save a copy in OWL/XML format 
      //File f = new File("example.xml");       
      //IRI documentIRI2 = IRI.create(f); 
      //manager.saveOntology(school, new OWLXMLOntologyFormat(), documentIRI2); 
      //System.out.println("Ontology saved in XML format."); 
     } else { 
      System.out.println("Ontology malformed."); 
     } 

     // Remove the ontology from the manager 
     //manager.removeOntology(ontology); 

    } catch (OWLOntologyCreationException | IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

} 

控制檯輸出:

Exception in thread "main" java.lang.NoSuchMethodError: org.semanticweb.owlapi.model.OWLOntologyID.getDefaultDocumentIRI()Lorg/semanticweb/owlapi/model/IRI; 
    at org.semanticweb.HermiT.structural.OWLClausification.preprocessAndClausify(Unknown Source) 
    at org.semanticweb.HermiT.Reasoner.loadOntology(Unknown Source) 
    at org.semanticweb.HermiT.Reasoner.<init>(Unknown Source) 
    at org.semanticweb.HermiT.Reasoner.<init>(Unknown Source) 
    at App.main(App.java:34) 

感謝。

回答

0

經過一番研究,我發現了這個問題。 HermiT 3.4或3.5甚至不適用於OWL API 4.0。我只是更改爲OWL API 3.5,一切正常。隨意使用它。