【发布时间】: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>
【问题讨论】: