首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将OWL公理转换为曼彻斯特语法

将OWL公理转换为曼彻斯特语法
EN

Stack Overflow用户
提问于 2013-04-25 22:55:40
回答 3查看 1.1K关注 0票数 2

有没有办法将OWL公理转换为曼彻斯特语法?我知道OWL-API将允许您将曼彻斯特语法中的句子解析为OWL函数式语法,但我需要做的恰恰相反。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-04-26 23:42:01

非常感谢你为我指明了正确的方向,这就是我解决问题的方法。

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

代码语言:javascript
复制
    File file=new File("ontology/pizza.owl");
    OWLOntologyManager manager;
    OWLOntology localOntology=null;
    OWLDataFactory factory ;

    try {


        //loading the ontology
        manager=OWLManager.createOWLOntologyManager();

        try {
            localOntology = manager.loadOntologyFromOntologyDocument(file);
        } catch (OWLOntologyCreationException e) {
            e.printStackTrace();
        }

        factory = localOntology.getOWLOntologyManager().getOWLDataFactory();

        OWLOntologyFormat format = manager.getOntologyFormat(localOntology);
        System.out.println("    format: " + format);

        ManchesterOWLSyntaxOntologyFormat manSyntaxFormat = new ManchesterOWLSyntaxOntologyFormat();
        if(format.isPrefixOWLOntologyFormat()) {
            manSyntaxFormat.copyPrefixesFrom(format.asPrefixOWLOntologyFormat());
        }

        manager.setOntologyFormat(localOntology, manSyntaxFormat);
        manager.saveOntology(localOntology, manSyntaxFormat);
        System.out.println("Manchester syntax: --- saved in Manchester.owl");

        ManchesterOWLSyntaxOWLObjectRendererImpl rendering = new ManchesterOWLSyntaxOWLObjectRendererImpl();

        OWLClass c1 = factory.getOWLClass(IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#IceCream"));

        Set<OWLClassExpression> c1eqclasses = c1.getEquivalentClasses(localOntology);
        for(OWLClassExpression c1e : c1eqclasses)
            System.out.println("Equivalent: "+rendering.render(c1e));

        c1eqclasses = c1.getDisjointClasses(localOntology);
        for(OWLClassExpression c1e : c1eqclasses)
            System.out.println("Disjoint: "+rendering.render(c1e));

        c1eqclasses = c1.getSubClasses(localOntology);
        for(OWLClassExpression c1e : c1eqclasses)
            System.out.println("Subclass: "+rendering.render(c1e));

        c1eqclasses = c1.getSuperClasses(localOntology);
        for(OWLClassExpression c1e : c1eqclasses)
            System.out.println("Superclass: "+rendering.render(c1e));



    }
    catch (OWLOntologyStorageException e) {
        System.out.println("Could not save ontology: " + e.getMessage());
    }



}

票数 3
EN

Stack Overflow用户

发布于 2013-04-26 03:16:21

OWL-API还允许您读取以函数式语法编写的本体,并将其转换为曼彻斯特语法。

将本体编写为以曼彻斯特语法序列化的文件的代码示例:

代码语言:javascript
复制
File file = new File("/home/foo/bar.owl");
OWLOntologyFormat format = manager.getOntologyFormat(ontology);
ManchesterOWLSyntaxOntologyFormat manSyntaxFormat =
                                         new ManchesterOWLSyntaxOntologyFormat();
manager.saveOntology(ontology, manSyntaxFormat, IRI.create(file));

managerontology是来自OWL-API的标准对象。

票数 2
EN

Stack Overflow用户

发布于 2015-10-28 06:35:43

在新版本的OWL API (我使用4.0.1)中,使用以下方法

代码语言:javascript
复制
Set<OWLEquivalentAxiom> axioms = localOntology.getEquivalentClassesAxiom(c1);

相反,

代码语言:javascript
复制
Set<OWLClassExpression> c1eqclasses = c1.getEquivalentClasses(localOntology);

其他调用也是如此。

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

https://stackoverflow.com/questions/16218139

复制
相关文章

相似问题

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