Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get nested RDF/XML from Jena?

Tags:

java

rdf

jena

I need to create RDF that looks like this:

<rdf:Description rdf:about='uri1'>
  <namespace:level1>
    <rdf:Description>
      <namespace:blankNode rdf:resource='uri2'/>
      <namespace:text></namespace:text> 
    </rdf:Description>
  </namespace:level1>
</rdf:Description>

<rdf:Description rdf:about="uri2">
  some properties here
</rdf:Description>

As you can see, there are nested structures, as well as blank nodes. (I don't know if that's the exact terminology for the "blankNode" property in my structure.) If I use

model.write(System.out, "RDF/XML-ABBREV");

then even the blank node is nested, which I don't want. Is there any way to get this kind of structure using Jena? Or is there any other library for Java that can handle this better?

like image 321
user1355348 Avatar asked May 07 '12 02:05

user1355348


1 Answers

I think you're going at this the wrong way.

Nesting is a concept that only makes sense when talking about trees. But RDF is not about trees, it's about triples. Forget for a while about the structure of the XML, and think about the triples that are encoded in the XML. I find model.write(System.out, "N-TRIPLES"); most useful for that.

You first need to understand what triples you want your RDF/XML file to express. As long as it expresses the right triples, it doesn't matter whether the one node is written nested inside the other or what order things appear in. These are purely “cosmetic” questions, like indentation.

like image 126
cygri Avatar answered Nov 11 '22 17:11

cygri