0

I am trying to writer a exporter utility to SKOS using Apache Jena. My issue is that the broader or narrower objects are getting nested. I am expecting the following xml but getting the xmls with nested elements. I am not getting any help from tutorials. Is it just a formatting issue or something to do with the way I am coding for it ?

Actual Output

<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>

Expected Output

<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>

Codes is as follows

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");
Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Lokanath
  • 1
  • 1

1 Answers1

0

"http://lexicon.ai/P011" does not appear in the code sample Entity does not appear to be used.

There are two model.createResource() which will create 2 blank nodes.

The "actual" output shows one resource was created with createResource("http://lexicon.ai/P011") and one with a blank node. That looks like the cause of the nesting.

To get nearer to the required output, you will need to use to named resources and may be better off with the more basic writer, RDFFormat.RDFXML_PLAIN writing using RDFDataMgr.write.

AndyS
  • 16,345
  • 17
  • 21
  • Yes I corrected my code , but the issue still remains. – Lokanath Apr 09 '18 at 08:14
  • 1
    When I use RDFFormat.RDFXML_PLAIN as format I am not seeing the nesting but each element is described by "rdf:Description" , but when I change the format to RDFFormat.RDFXML_ABBREV or RDFFormat.RDFXML_PLAIN, each element is described by "SKOS:Concept" and I see nesting. Is this the correct behavior ? – Lokanath Apr 09 '18 at 08:26