簡體   English   中英

使用HermiT打印本體的層次結構

[英]Print the hierarchy of an ontology using 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)

謝謝。

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

暫無
暫無

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

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