gpt4 book ai didi

java - OWL API,在 <!-- --> 之间添加 URI 和名称,而不将 URI 添加到其他部分

转载 作者:行者123 更新时间:2023-11-30 08:17:09 24 4
gpt4 key购买 nike

当我尝试在 < !-- --> 之间显示 URI + 名称而不将 URI+名称添加到其他部分时,我遇到了 OWL API 的问题。

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

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

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

使用下面的代码我得到了几乎相同的结果,但是 <-- #America--> 之间仍然缺少 URI,我可以将 iri+name 添加到 getOWLClass 方法,但这最终会给出我是 < !-- --> 之间的 URI+Name 以及namedIndividual 上的,即 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>

最佳答案

您正在尝试在 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#");

并在此时保存本体。

关于java - OWL API,在 &lt;!-- --> 之间添加 URI 和名称,而不将 URI 添加到其他部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29501555/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com