【问题标题】:OWL API, adding the URI and Name between <!-- --> without adding URI to other sectionsOWL API,在 <!-- --> 之间添加 URI 和 Name,其他部分不添加 URI
【发布时间】:2015-04-07 21:23:17
【问题描述】:

在尝试显示 之间的 URI + 名称时,我遇到了 OWL API 的问题,但它也没有将 URI + 名称添加到其他部分。

例如,我使用披萨本体作为我的源,并且本体文件显示了以下个人代码集。

<!-- Individual: http://www.co-ode.org/ontologies/pizza/pizza.owl#America -->

<owl:Thing rdf:about="#America">
    <rdf:type rdf:resource="#Country"/>
</owl:Thing>

使用下面的代码,我得到了几乎相同的结果,但是 之间仍然缺少 URI,我可以将 iri+name 添加到 getOWLClass 方法,但最终会给出我是 和 namedIndividual 之间的 URI+Name,即 rdf:about = http://www.co-ode.org/ontologies/pizza/pizza.owl#America 而不仅仅是 #America。

 OWLClass tClass = dataFactory.getOWLClass(IRI.create("#Country"));
 OWLNamedIndividual tIndividual = dataFactory.getOWLNamedIndividual(IRI.create("#America"));
 OWLClassAssertionAxiom classAssertion = dataFactory.getOWLClassAssertionAxiom(tClass, tIndividual);
 manager.addAxiom(ontology, classAssertion);

输出:

<!-- #America -->

<owl:NamedIndividual rdf:about="#America">
    <rdf:type rdf:resource="#Country"/>
</owl:NamedIndividual>

它应该是什么:

<!-- http://www.co-ode.org/ontologies/pizza/pizza.owl#America -->

<owl:NamedIndividual rdf:about="#America">
    <rdf:type rdf:resource="#Country"/>
</owl:NamedIndividual>

我遗漏了什么,如何让它看起来像披萨本体中的正确方式?我正在使用 OWL API 4.0。

编辑:

根据 Ignazio 的建议,我进行了更改但没有成功,这是代码。我再次使用 OWL API 4,URI 仍然没有被添加到评论 .

 OWLClass tClass = dataFactory.getOWLClass(IRI.create("#Country"));
 OWLNamedIndividual tIndividual = dataFactory.getOWLNamedIndividual(IRI.create("#America"));
 OWLClassAssertionAxiom classAssertion = dataFactory.getOWLClassAssertionAxiom(tClass, tIndividual);
 XMLWriterPreferences.getInstance().setUseNamespaceEntities(true);
 OWLDocumentFormat format = m.getOntologyFormat(ontology);

 format.asPrefixOWLOntologyFormat()
    .setPrefix("ns:",
               "http://www.co-ode.org/ontologies/pizza/pizza.owl#");

 try
 {
     m.addAxiom(ontology, classAssertion);
     m.saveOntology(ontology, format, new SystemOutDocumentTarget());
 } catch (OWLOntologyStorageException e)
 {
     e.printStackTrace();
     System.exit(0);
 }

我还是很陌生,如果我是多余的,对不起。

输出仍然没有 URI + #America in :

 <!-- #America-->

 <owl:NamedIndividual rdf:about="#America">
     <rdf:type rdf:resource="#Country"/>
 </owl:NamedIndividual>

【问题讨论】:

    标签: java owl owl-api


    【解决方案1】:

    您正试图在 RDF/XML 中输出相关 IRI。 OWL API 不支持这一点(除非像您在代码中那样实际创建具有相关 IRI 的实体。但是,生成的本体违反 OWL 2 配置文件)。

    您可以通过实体获得类似的结果:

    XMLWriterPreferences.getInstance().setUseNamespaceEntities(true);
    ontology.getFormat()
                .asPrefixOWLOntologyFormat()
                .setPrefix("ns:",
                        "http://www.co-ode.org/ontologies/pizza/pizza.owl#");
    

    然后保存本体。

    【讨论】:

    • 您好,我使用的是 OWL API 4,所以没有找到 owlOntology.getFormat()。我不得不使用 OWLOntologyManager.getOntologyFormat(ontology).asPrefixOWLOntologyFormat().setPr‌​‌​‌​efix("ns:","co-ode.org/ontologies/pizza/pizza.owl#");我在执行上述代码时使用了这种方法,但 保持不变。在上面添加了更多代码......谢谢
    • IRI.create("#Country") 是一个相对的 IRI,设置命名空间对它没有任何作用。 之间的标题注释使用完整的 IRI,并且在任何情况下都不会缩短它。
    • 我没有在标题注释中获得完整的 IRI,我只获得了相对 IRI。
    • 是的——在我之前的评论中,我的意思是说 IRI.create("#Country") 将创建一个完整字符串形式为“#Country”的 IRI——这个 IRI 是相对的,并且是本体不应包含使用这些 IRI 的实体。出于您的目的,您应该使用IRI.create("http://www.co-ode.org/ontologies/pizza/pizza.owl#Country")
    猜你喜欢
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多