我正在尝试使用 Apache Jena 为 SKOS 编写导出器实用程序。我的问题是更宽或更窄的对象正在嵌套。我期待以下 xml,但获取带有嵌套元素的 xml。我没有从教程中得到任何帮助。这只是格式问题还是与我编码的方式有关?
实际输出
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:SKOS="http://www.w3.org/2004/02/skos/core#">
<SKOS:Concept rdf:about="http://lexicon.ai/P011">
<SKOS:broader>
<SKOS:Concept>
<SKOS:narrower>
<SKOS:Concept>
<SKOS:scopeNote>testb</SKOS:scopeNote>
<SKOS:prefLabel>Disease</SKOS:prefLabel>
</SKOS:Concept>
</SKOS:narrower>
<SKOS:scopeNote>testb</SKOS:scopeNote>
<SKOS:prefLabel>Disease</SKOS:prefLabel>
</SKOS:Concept>
</SKOS:broader>
<SKOS:altLabel>alt2</SKOS:altLabel>
<SKOS:altLabel>alt1</SKOS:altLabel>
<SKOS:scopeNote>test</SKOS:scopeNote>
<SKOS:prefLabel>Disease</SKOS:prefLabel>
</SKOS:Concept>
</rdf:RDF>
预期产出
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:SKOS="http://www.w3.org/2004/02/skos/core#">
<SKOS:Concept rdf:about="http://lexicon.ai/P011">
<SKOS:broader rdf:about="http://lexicon.ai/P012"/>
<SKOS:altLabel>alt2</SKOS:altLabel>
<SKOS:altLabel>alt1</SKOS:altLabel>
<SKOS:scopeNote>test</SKOS:scopeNote>
<SKOS:prefLabel>Disease</SKOS:prefLabel>
</SKOS:Concept>
<SKOS:Concept rdf:about="http://lexicon.ai/P012">
<SKOS:narrower rdf:about="http://lexicon.ai/P0121"/>
<SKOS:scopeNote>testb</SKOS:scopeNote>
<SKOS:prefLabel>Diseaseb</SKOS:prefLabel>
</SKOS:Concept>
<SKOS:Concept rdf:about="http://lexicon.ai/P0121">
<SKOS:scopeNote>testn</SKOS:scopeNote>
<SKOS:prefLabel>Diseasen</SKOS:prefLabel>
</SKOS:Concept>
</rdf:RDF>
代码如下
Model model = ModelFactory.createDefaultModel();
model.setNsPrefix("SKOS", SKOS.uri);
Model model2 = ModelFactory.createDefaultModel();
model2.setNsPrefix("SKOS", SKOS.uri);
final Resource Entity = model.createResource(personURI);
final Resource broader1 = model.createResource();
final Resource nt1 = model.createResource();
nt1.addProperty(RDF.type, SKOS.Concept);
nt1.addProperty(SKOS.prefLabel, "Diseasen");
nt1.addProperty(SKOS.scopeNote, "testn");
broader1.addProperty(RDF.type, SKOS.Concept);
broader1.addProperty(SKOS.prefLabel, "Diseaseb");
broader1.addProperty(SKOS.scopeNote, "testb");
broader1.addProperty(SKOS.narrower, nt1);
Entity.addProperty(RDF.type, SKOS.Concept);
Entity.addProperty(SKOS.prefLabel, "Disease");
Entity.addProperty(SKOS.scopeNote, "test");