首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用HermiT打印本体的层次结构

使用HermiT打印本体的层次结构
EN

Stack Overflow用户
提问于 2015-03-25 07:11:50
回答 1查看 390关注 0票数 0

我在使用HermiT推理器库时遇到了问题。

有没有人能理解我做错了什么?

代码语言:javascript
复制
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();
    }

}

控制台输出:

代码语言:javascript
复制
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)

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2015-03-25 09:51:43

经过另一次研究,我发现了问题所在。HermiT 3.4或3.5甚至不能与OWL API 4.0一起工作。我只是换成了OWL API 3.5,一切都很好。请随意使用它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29244631

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档